Custom Group Financials [Technimentals]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © barnabygraham

// Credit to LucF for the script 'Financials on Chart' from which the bulk of this code was taken.

//@version=5
indicator("Custom Group Financials [Technimentals]")

// Financial legends.
var string F_NA = "⸺"
var string F000 = "█ INCOME STATEMENTS █"
var string F001 = " After tax other income/expense"
var string F002 = " Average basic shares outstanding"
var string F003 = " Other COGS"
var string F004 = " Cost of goods"
var string F005 = " Deprecation and amortization"
var string F006 = " Diluted net income available to common stockholders"
var string F007 = " Diluted shares outstanding"
var string F008 = " Dilution adjustment"
var string F009 = " Discontinued operations"
var string F010 = " Basic EPS"
var string F011 = " Diluted EPS"
var string F012 = " EBIT"
var string F013 = " EBITDA"
var string F014 = " Equity in earnings"
var string F015 = " Gross profit"
var string F016 = " Taxes"
var string F017 = " Interest capitalized"
var string F018 = " Interest expense on debt"
var string F019 = " Non-controlling/minority interest"
var string F020 = " Net income before discontinued operations"
var string F021 = " Net income"
var string F022 = " Non-operating income, excl. interest expenses"
var string F023 = " Interest expense, net of interest capitalized"
var string F024 = " Non-operating interest income"
var string F025 = " Operating income"
var string F026 = " Operating expenses (excl. COGS)"
var string F027 = " Miscellaneous non-operating expense"
var string F028 = " Other operating expenses, total"
var string F029 = " Preferred dividends"
var string F030 = " Pretax equity in earnings"
var string F031 = " Pretax income"
var string F032 = " Research & development"
var string F033 = " Selling/general/admin expenses, other"
var string F034 = " Selling/general/admin expenses, total"
var string F035 = " Non-operating income, total"
var string F036 = " Total operating expenses"
var string F037 = " Total revenue"
var string F038 = " Unusual income/expense"

var string F100 = "█ BALANCE SHEET █"
var string F101 = " Accounts payable"
var string F102 = " Accounts receivable - trade, net"
var string F103 = " Accrued payroll"
var string F104 = " Accumulated depreciation, total"
var string F105 = " Additional paid-in capital/Capital surplus"
var string F106 = " Tangible book value per share"
var string F107 = " Book value per share"
var string F108 = " Capitalized lease obligations"
var string F109 = " Capital and operating lease obligations"
var string F110 = " Cash & equivalents"
var string F111 = " Cash and short term investments"
var string F112 = " Common equity, total"
var string F113 = " Common stock par/Carrying value"
var string F114 = " Current portion of LT debt and capital leases"
var string F115 = " Deferred income, current"
var string F116 = " Deferred income, non-current"
var string F117 = " Deferred tax assets"
var string F118 = " Deferred tax liabilities"
var string F119 = " Dividends payable"
var string F120 = " Goodwill, net"
var string F121 = " Income tax payable"
var string F122 = " Net intangible assets"
var string F123 = " Inventories - finished goods"
var string F124 = " Inventories - progress payments & other"
var string F125 = " Inventories - raw materials"
var string F126 = " Inventories - work in progress"
var string F127 = " Investments in unconsolidated subsidiaries"
var string F128 = " Long term debt excl. lease liabilities"
var string F129 = " Long term debt"
var string F130 = " Long term investments"
var string F131 = " Note receivable - long term"
var string F132 = " Other long term assets, total"
var string F133 = " Minority interest"
var string F134 = " Notes payable"
var string F135 = " Operating lease liabilities"
var string F136 = " Other common equity"
var string F137 = " Other current assets, total"
var string F138 = " Other current liabilities"
var string F139 = " Other intangibles, net"
var string F140 = " Other investments"
var string F141 = " Other liabilities, total"
var string F142 = " Other receivables"
var string F143 = " Other short term debt"
var string F144 = " Paid in capital"
var string F145 = " Gross property/plant/equipment"
var string F146 = " Net property/plant/equipment"
var string F147 = " Preferred stock, carrying value"
var string F148 = " Prepaid expenses"
var string F149 = " Provision for risks & charge"
var string F150 = " Retained earnings"
var string F151 = " Short term debt excl. current portion of LT debt"
var string F152 = " Short term debt"
var string F153 = " Short term investments"
var string F154 = " Shareholders' equity"
var string F155 = " Total assets"
var string F156 = " Total current assets"
var string F157 = " Total current liabilities"
var string F158 = " Total debt"
var string F159 = " Total equity"
var string F160 = " Total inventory"
var string F161 = " Total liabilities"
var string F162 = " Total liabilities & shareholders' equities"
var string F163 = " Total non-current assets"
var string F164 = " Total non-current liabilities"
var string F165 = " Total receivables, net"
var string F166 = " Treasury stock - common"

var string F200 = "█ CASHFLOW █"
var string F201 = " Amortization"
var string F202 = " Capital expenditures - fixed assets"
var string F203 = " Capital expenditures"
var string F204 = " Capital expenditures - other assets"
var string F205 = " Cash from financing activities"
var string F206 = " Cash from investing activities"
var string F207 = " Cash from operating activities"
var string F208 = " Deferred taxes (cash flow)"
var string F209 = " Depreciation & amortization (cash flow)"
var string F210 = " Change in accounts payable"
var string F211 = " Change in accounts receivable"
var string F212 = " Change in accrued expenses"
var string F213 = " Change in inventories"
var string F214 = " Change in other assets/liabilities"
var string F215 = " Change in taxes payable"
var string F216 = " Changes in working capital"
var string F217 = " Common dividends paid"
var string F218 = " Depreciation/depletion"
var string F219 = " Free cash flow"
var string F220 = " Funds from operations"
var string F221 = " Issuance/retirement of debt, net"
var string F222 = " Issuance/retirement of long term debt"
var string F223 = " Issuance/retirement of other debt"
var string F224 = " Issuance/retirement of short term debt"
var string F225 = " Issuance/retirement of stock, net"
var string F226 = " Net income (cash flow)"
var string F227 = " Non-cash items"
var string F228 = " Other financing cash flow items, total"
var string F229 = " Financing activities - other sources"
var string F230 = " Financing activities - other uses"
var string F231 = " Other investing cash flow items, total"
var string F232 = " Investing activities - other sources"
var string F233 = " Investing activities - other uses"
var string F234 = " Preferred dividends paid"
var string F235 = " Purchase/acquisition of business"
var string F236 = " Purchase of investments"
var string F237 = " Repurchase of common & preferred stock"
var string F238 = " Purchase/sale of business, net"
var string F239 = " Purchase/sale of investments, net"
var string F240 = " Reduction of long term debt"
var string F241 = " Sale of common & preferred stock"
var string F242 = " Sale of fixed assets & businesses"
var string F243 = " Sale/maturity of investments"
var string F244 = " Issuance of long term debt"
var string F245 = " Total cash dividends paid"

var string F300 = "█ STATISTICS █"
var string F301 = " Accruals"
var string F302 = " Altman Z-score"
var string F303 = " Asset turnover"
var string F304 = " Beneish M-score"
var string F305 = " Buyback yield %"
var string F306 = " Cash conversion cycle"
var string F307 = " Cash to debt ratio"
var string F308 = " COGS to revenue ratio"
var string F309 = " Current ratio"
var string F310 = " Days sales outstanding"
var string F311 = " Days inventory"
var string F312 = " Days payable"
var string F313 = " Debt to assets ratio"
var string F314 = " Debt to EBITDA ratio"
var string F315 = " Debt to equity ratio"
var string F316 = " Debt to revenue ratio"
var string F317 = " Dividend payout ratio %"
var string F318 = " Dividend yield %"
var string F319 = " Dividends per share - common stock primary issue"
var string F320 = " EPS estimates"
var string F321 = " EPS basic one year growth"
var string F322 = " EPS diluted one year growth"
var string F323 = " EBITDA margin %"
var string F324 = " Effective interest rate on debt %"
var string F325 = " Enterprise value to EBITDA ratio"
var string F326 = " Enterprise value"
var string F327 = " Equity to assets ratio"
var string F328 = " Enterprise value to EBIT ratio"
var string F329 = " Enterprise value to revenue ratio"
var string F330 = " Float shares outstanding"
var string F331 = " Free cash flow margin %"
var string F332 = " Fulmer H factor"
var string F333 = " Goodwill to assets ratio"
var string F334 = " Graham's number"
var string F335 = " Gross margin %"
var string F336 = " Gross profit to assets ratio"
var string F337 = " Interest coverage"
var string F338 = " Inventory to revenue ratio"
var string F339 = " Inventory turnover"
var string F340 = " KZ index"
var string F341 = " Long term debt to total assets ratio"
var string F342 = " Net current asset value per share"
var string F343 = " Net income per employee"
var string F344 = " Net margin %"
var string F345 = " Number of employees"
var string F346 = " Operating earnings yield %"
var string F347 = " Operating margin %"
var string F348 = " PEG ratio"
var string F349 = " Piotroski F-score"
var string F350 = " Price earnings ratio forward"
var string F351 = " Price sales ratio forward"
var string F352 = " Price to free cash flow ratio"
var string F353 = " Price to tangible book ratio"
var string F354 = " Quality ratio"
var string F355 = " Quick ratio"
var string F356 = " Research & development to revenue ratio"
var string F357 = " Return on assets %"
var string F358 = " Return on equity adjusted to book value %"
var string F359 = " Return on equity %"
var string F360 = " Return on invested capital %"
var string F361 = " Return on tangible assets %"
var string F362 = " Return on tangible equity %"
var string F363 = " Revenue one year growth"
var string F364 = " Revenue per employee"
var string F365 = " Revenue estimates"
var string F366 = " Shares buyback ratio %"
var string F367 = " Sloan ratio %"
var string F368 = " Springate score"
var string F369 = " Sustainable growth rate"
var string F370 = " Tangible common equity ratio"
var string F371 = " Tobin's Q (approximate)"
var string F372 = " Total common shares outstanding"
var string F373 = " Zmijewski score"

var string F400 = "█ CALCULATED █"
var string F401 = " Market Capitalization"
var string F402 = " Earnings Yield"
var string F403 = " Price Book Ratio"
var string F404 = " Price Earnings Ratio"
var string F405 = " Price-To-Sales Ratio"

i_01 = input.string(F037, "Financial Data", options = [F_NA, F400, F401, F402, F403, F404, F405, F000, F001, F002, F003, F004, F005, F006, F007, F008, F009, F010, F011, F012, F013, F014, F015, F016, F017, F018, F019, F020, F021, F022, F023, F024, F025, F026, F027, F028, F029, F030, F031, F032, F033, F034, F035, F036, F037, F038, F100, F101, F102, F103, F104, F105, F106, F107, F108, F109, F110, F111, F112, F113, F114, F115, F116, F117, F118, F119, F120, F121, F122, F123, F124, F125, F126, F127, F128, F129, F130, F131, F132, F133, F134, F135, F136, F137, F138, F139, F140, F141, F142, F143, F144, F145, F146, F147, F148, F149, F150, F151, F152, F153, F154, F155, F156, F157, F158, F159, F160, F161, F162, F163, F164, F165, F166, F200, F201, F202, F203, F204, F205, F206, F207, F208, F209, F210, F211, F212, F213, F214, F215, F216, F217, F218, F219, F220, F221, F222, F223, F224, F225, F226, F227, F228, F229, F230, F231, F232, F233, F234, F235, F236, F237, F238, F239, F240, F241, F242, F243, F244, F245, F300, F301, F302, F303, F304, F305, F306, F307, F308, F309, F310, F311, F312, F313, F314, F315, F316, F317, F318, F319, F320, F321, F322, F323, F324, F325, F326, F327, F328, F329, F330, F331, F332, F333, F334, F335, F336, F337, F338, F339, F340, F341, F342, F343, F344, F345, F346, F347, F348, F349, F350, F351, F352, F353, F354, F355, F356, F357, F358, F359, F360, F361, F362, F363, F364, F365, F366, F367, F368, F369, F370, F371, F372, F373])
totalAverage = input.string('Total','Total or Average', options = ['Total','Average'])
fPeriod = input.string('FY','Period',['FY','FQ','TTM'])
colour = input.color(color.rgb(255-69,255-69,255-69,1.69),'Colour')

f_getId(_userFinancialChoice) =>
    string _return = 
      _userFinancialChoice == F001 ? "AFTER_TAX_OTHER_INCOME" :
      _userFinancialChoice == F002 ? "BASIC_SHARES_OUTSTANDING" :
      _userFinancialChoice == F003 ? "COST_OF_GOODS_EXCL_DEP_AMORT" :
      _userFinancialChoice == F004 ? "COST_OF_GOODS" :
      _userFinancialChoice == F005 ? "DEP_AMORT_EXP_INCOME_S" :
      _userFinancialChoice == F006 ? "DILUTED_NET_INCOME" :
      _userFinancialChoice == F007 ? "DILUTED_SHARES_OUTSTANDING" :
      _userFinancialChoice == F008 ? "DILUTION_ADJUSTMENT" :
      _userFinancialChoice == F009 ? "DISCONTINUED_OPERATIONS" :
      _userFinancialChoice == F010 ? "EARNINGS_PER_SHARE_BASIC" :
      _userFinancialChoice == F011 ? "EARNINGS_PER_SHARE_DILUTED" :
      _userFinancialChoice == F012 ? "EBIT" :
      _userFinancialChoice == F013 ? "EBITDA" :
      _userFinancialChoice == F014 ? "EQUITY_IN_EARNINGS" :
      _userFinancialChoice == F015 ? "GROSS_PROFIT" :
      _userFinancialChoice == F016 ? "INCOME_TAX" :
      _userFinancialChoice == F017 ? "INTEREST_CAPITALIZED" :
      _userFinancialChoice == F018 ? "INTEREST_EXPENSE_ON_DEBT" :
      _userFinancialChoice == F019 ? "MINORITY_INTEREST_EXP" :
      _userFinancialChoice == F020 ? "NET_INCOME_BEF_DISC_OPER" :
      _userFinancialChoice == F021 ? "NET_INCOME" :
      _userFinancialChoice == F022 ? "NON_OPER_INCOME" :
      _userFinancialChoice == F023 ? "NON_OPER_INTEREST_EXP" :
      _userFinancialChoice == F024 ? "NON_OPER_INTEREST_INCOME" :
      _userFinancialChoice == F025 ? "OPER_INCOME" :
      _userFinancialChoice == F026 ? "OPERATING_EXPENSES" :
      _userFinancialChoice == F027 ? "OTHER_INCOME" :
      _userFinancialChoice == F028 ? "OTHER_OPER_EXPENSE_TOTAL" :
      _userFinancialChoice == F029 ? "PREFERRED_DIVIDENDS" :
      _userFinancialChoice == F030 ? "PRETAX_EQUITY_IN_EARNINGS" :
      _userFinancialChoice == F031 ? "PRETAX_INCOME" :
      _userFinancialChoice == F032 ? "RESEARCH_AND_DEV" :
      _userFinancialChoice == F033 ? "SELL_GEN_ADMIN_EXP_OTHER" :
      _userFinancialChoice == F034 ? "SELL_GEN_ADMIN_EXP_TOTAL" :
      _userFinancialChoice == F035 ? "TOTAL_NON_OPER_INCOME" :
      _userFinancialChoice == F036 ? "TOTAL_OPER_EXPENSE" :
      _userFinancialChoice == F037 ? "TOTAL_REVENUE" :
      _userFinancialChoice == F038 ? "UNUSUAL_EXPENSE_INC" :

      _userFinancialChoice == F101 ? "ACCOUNTS_PAYABLE" :
      _userFinancialChoice == F102 ? "ACCOUNTS_RECEIVABLES_NET" :
      _userFinancialChoice == F103 ? "ACCRUED_PAYROLL" :
      _userFinancialChoice == F104 ? "ACCUM_DEPREC_TOTAL" :
      _userFinancialChoice == F105 ? "ADDITIONAL_PAID_IN_CAPITAL" :
      _userFinancialChoice == F106 ? "BOOK_TANGIBLE_PER_SHARE" :
      _userFinancialChoice == F107 ? "BOOK_VALUE_PER_SHARE" :
      _userFinancialChoice == F108 ? "CAPITAL_LEASE_OBLIGATIONS" :
      _userFinancialChoice == F109 ? "CAPITAL_OPERATING_LEASE_OBLIGATIONS" :
      _userFinancialChoice == F110 ? "CASH_N_EQUIVALENTS" :
      _userFinancialChoice == F111 ? "CASH_N_SHORT_TERM_INVEST" :
      _userFinancialChoice == F112 ? "COMMON_EQUITY_TOTAL" :
      _userFinancialChoice == F113 ? "COMMON_STOCK_PAR" :
      _userFinancialChoice == F114 ? "CURRENT_PORT_DEBT_CAPITAL_LEASES" :
      _userFinancialChoice == F115 ? "DEFERRED_INCOME_CURRENT" :
      _userFinancialChoice == F116 ? "DEFERRED_INCOME_NON_CURRENT" :
      _userFinancialChoice == F117 ? "DEFERRED_TAX_ASSESTS" :
      _userFinancialChoice == F118 ? "DEFERRED_TAX_LIABILITIES" :
      _userFinancialChoice == F119 ? "DIVIDENDS_PAYABLE" :
      _userFinancialChoice == F120 ? "GOODWILL" :
      _userFinancialChoice == F121 ? "INCOME_TAX_PAYABLE" :
      _userFinancialChoice == F122 ? "INTANGIBLES_NET" :
      _userFinancialChoice == F123 ? "INVENTORY_FINISHED_GOODS" :
      _userFinancialChoice == F124 ? "INVENTORY_PROGRESS_PAYMENTS" :
      _userFinancialChoice == F125 ? "INVENTORY_RAW_MATERIALS" :
      _userFinancialChoice == F126 ? "INVENTORY_WORK_IN_PROGRESS" :
      _userFinancialChoice == F127 ? "INVESTMENTS_IN_UNCONCSOLIDATE" :
      _userFinancialChoice == F128 ? "LONG_TERM_DEBT_EXCL_CAPITAL_LEASE" :
      _userFinancialChoice == F129 ? "LONG_TERM_DEBT" :
      _userFinancialChoice == F130 ? "LONG_TERM_INVESTMENTS" :
      _userFinancialChoice == F131 ? "LONG_TERM_NOTE_RECEIVABLE" :
      _userFinancialChoice == F132 ? "LONG_TERM_OTHER_ASSETS_TOTAL" :
      _userFinancialChoice == F133 ? "MINORITY_INTEREST" :
      _userFinancialChoice == F134 ? "NOTES_PAYABLE_SHORT_TERM_DEBT" :
      _userFinancialChoice == F135 ? "OPERATING_LEASE_LIABILITIES" :
      _userFinancialChoice == F136 ? "OTHER_COMMON_EQUITY" :
      _userFinancialChoice == F137 ? "OTHER_CURRENT_ASSETS_TOTAL" :
      _userFinancialChoice == F138 ? "OTHER_CURRENT_LIABILITIES" :
      _userFinancialChoice == F139 ? "OTHER_INTANGIBLES_NET" :
      _userFinancialChoice == F140 ? "OTHER_INVESTMENTS" :
      _userFinancialChoice == F141 ? "OTHER_LIABILITIES_TOTAL" :
      _userFinancialChoice == F142 ? "OTHER_RECEIVABLES" :
      _userFinancialChoice == F143 ? "OTHER_SHORT_TERM_DEBT" :
      _userFinancialChoice == F144 ? "PAID_IN_CAPITAL" :
      _userFinancialChoice == F145 ? "PPE_TOTAL_GROSS" :
      _userFinancialChoice == F146 ? "PPE_TOTAL_NET" :
      _userFinancialChoice == F147 ? "PREFERRED_STOCK_CARRYING_VALUE" :
      _userFinancialChoice == F148 ? "PREPAID_EXPENSES" :
      _userFinancialChoice == F149 ? "PROVISION_F_RISKS" :
      _userFinancialChoice == F150 ? "RETAINED_EARNINGS" :
      _userFinancialChoice == F151 ? "SHORT_TERM_DEBT_EXCL_CURRENT_PORT" :
      _userFinancialChoice == F152 ? "SHORT_TERM_DEBT" :
      _userFinancialChoice == F153 ? "SHORT_TERM_INVEST" :
      _userFinancialChoice == F154 ? "SHRHLDRS_EQUITY" :
      _userFinancialChoice == F155 ? "TOTAL_ASSETS" :
      _userFinancialChoice == F156 ? "TOTAL_CURRENT_ASSETS" :
      _userFinancialChoice == F157 ? "TOTAL_CURRENT_LIABILITIES" :
      _userFinancialChoice == F158 ? "TOTAL_DEBT" :
      _userFinancialChoice == F159 ? "TOTAL_EQUITY" :
      _userFinancialChoice == F160 ? "TOTAL_INVENTORY" :
      _userFinancialChoice == F161 ? "TOTAL_LIABILITIES" :
      _userFinancialChoice == F162 ? "TOTAL_LIABILITIES_SHRHLDRS_EQUITY" :
      _userFinancialChoice == F163 ? "TOTAL_NON_CURRENT_ASSETS" :
      _userFinancialChoice == F164 ? "TOTAL_NON_CURRENT_LIABILITIES" :
      _userFinancialChoice == F165 ? "TOTAL_RECEIVABLES_NET" :
      _userFinancialChoice == F166 ? "TREASURY_STOCK_COMMON" :

      _userFinancialChoice == F201 ? "AMORTIZATION" :
      _userFinancialChoice == F202 ? "CAPITAL_EXPENDITURES_FIXED_ASSETS" :
      _userFinancialChoice == F203 ? "CAPITAL_EXPENDITURES" :
      _userFinancialChoice == F204 ? "CAPITAL_EXPENDITURES_OTHER_ASSETS" :
      _userFinancialChoice == F205 ? "CASH_F_FINANCING_ACTIVITIES" :
      _userFinancialChoice == F206 ? "CASH_F_INVESTING_ACTIVITIES" :
      _userFinancialChoice == F207 ? "CASH_F_OPERATING_ACTIVITIES" :
      _userFinancialChoice == F208 ? "CASH_FLOW_DEFERRED_TAXES" :
      _userFinancialChoice == F209 ? "CASH_FLOW_DEPRECATION_N_AMORTIZATION" :
      _userFinancialChoice == F210 ? "CHANGE_IN_ACCOUNTS_PAYABLE" :
      _userFinancialChoice == F211 ? "CHANGE_IN_ACCOUNTS_RECEIVABLE" :
      _userFinancialChoice == F212 ? "CHANGE_IN_ACCRUED_EXPENSES" :
      _userFinancialChoice == F213 ? "CHANGE_IN_INVENTORIES" :
      _userFinancialChoice == F214 ? "CHANGE_IN_OTHER_ASSETS" :
      _userFinancialChoice == F215 ? "CHANGE_IN_TAXES_PAYABLE" :
      _userFinancialChoice == F216 ? "CHANGES_IN_WORKING_CAPITAL" :
      _userFinancialChoice == F217 ? "COMMON_DIVIDENDS_CASH_FLOW" :
      _userFinancialChoice == F218 ? "DEPRECIATION_DEPLETION" :
      _userFinancialChoice == F219 ? "FREE_CASH_FLOW" :
      _userFinancialChoice == F220 ? "FUNDS_F_OPERATIONS" :
      _userFinancialChoice == F221 ? "ISSUANCE_OF_DEBT_NET" :
      _userFinancialChoice == F222 ? "ISSUANCE_OF_LONG_TERM_DEBT" :
      _userFinancialChoice == F223 ? "ISSUANCE_OF_OTHER_DEBT" :
      _userFinancialChoice == F224 ? "ISSUANCE_OF_SHORT_TERM_DEBT" :
      _userFinancialChoice == F225 ? "ISSUANCE_OF_STOCK_NET" :
      _userFinancialChoice == F226 ? "NET_INCOME_STARTING_LINE" :
      _userFinancialChoice == F227 ? "NON_CASH_ITEMS" :
      _userFinancialChoice == F228 ? "OTHER_FINANCING_CASH_FLOW_ITEMS_TOTAL" :
      _userFinancialChoice == F229 ? "OTHER_FINANCING_CASH_FLOW_SOURCES" :
      _userFinancialChoice == F230 ? "OTHER_FINANCING_CASH_FLOW_USES" :
      _userFinancialChoice == F231 ? "OTHER_INVESTING_CASH_FLOW_ITEMS_TOTAL" :
      _userFinancialChoice == F232 ? "OTHER_INVESTING_CASH_FLOW_SOURCES" :
      _userFinancialChoice == F233 ? "OTHER_INVESTING_CASH_FLOW_USES" :
      _userFinancialChoice == F234 ? "PREFERRED_DIVIDENDS_CASH_FLOW" :
      _userFinancialChoice == F235 ? "PURCHASE_OF_BUSINESS" :
      _userFinancialChoice == F236 ? "PURCHASE_OF_INVESTMENTS" :
      _userFinancialChoice == F237 ? "PURCHASE_OF_STOCK" :
      _userFinancialChoice == F238 ? "PURCHASE_SALE_BUSINESS" :
      _userFinancialChoice == F239 ? "PURCHASE_SALE_INVESTMENTS" :
      _userFinancialChoice == F240 ? "REDUCTION_OF_LONG_TERM_DEBT" :
      _userFinancialChoice == F241 ? "SALE_OF_STOCK" :
      _userFinancialChoice == F242 ? "SALES_OF_BUSINESS" :
      _userFinancialChoice == F243 ? "SALES_OF_INVESTMENTS" :
      _userFinancialChoice == F244 ? "SUPPLYING_OF_LONG_TERM_DEBT" :
      _userFinancialChoice == F245 ? "TOTAL_CASH_DIVIDENDS_PAID" :

      _userFinancialChoice == F301 ? "ACCRUALS_RATIO" :
      _userFinancialChoice == F302 ? "ALTMAN_Z_SCORE" :
      _userFinancialChoice == F303 ? "ASSET_TURNOVER" :
      _userFinancialChoice == F304 ? "BENEISH_M_SCORE" :
      _userFinancialChoice == F305 ? "BUYBACK_YIELD" :
      _userFinancialChoice == F306 ? "CASH_CONVERSION_CYCLE" :
      _userFinancialChoice == F307 ? "CASH_TO_DEBT" :
      _userFinancialChoice == F308 ? "COGS_TO_REVENUE" :
      _userFinancialChoice == F309 ? "CURRENT_RATIO" :
      _userFinancialChoice == F310 ? "DAY_SALES_OUT" :
      _userFinancialChoice == F311 ? "DAYS_INVENT" :
      _userFinancialChoice == F312 ? "DAYS_PAY" :
      _userFinancialChoice == F313 ? "DEBT_TO_ASSET" :
      _userFinancialChoice == F314 ? "DEBT_TO_EBITDA" :
      _userFinancialChoice == F315 ? "DEBT_TO_EQUITY" :
      _userFinancialChoice == F316 ? "DEBT_TO_REVENUE" :
      _userFinancialChoice == F317 ? "DIVIDEND_PAYOUT_RATIO" :
      _userFinancialChoice == F318 ? "DIVIDENDS_YIELD" :
      _userFinancialChoice == F319 ? "DPS_COMMON_STOCK_PRIM_ISSUE" :
      _userFinancialChoice == F320 ? "EARNINGS_ESTIMATE" :
      _userFinancialChoice == F321 ? "EARNINGS_PER_SHARE_BASIC_ONE_YEAR_GROWTH" :
      _userFinancialChoice == F322 ? "EARNINGS_PER_SHARE_DILUTED_ONE_YEAR_GROWTH" :
      _userFinancialChoice == F323 ? "EBITDA_MARGIN" :
      _userFinancialChoice == F324 ? "EFFECTIVE_INTEREST_RATE_ON_DEBT" :
      _userFinancialChoice == F325 ? "ENTERPRISE_VALUE_EBITDA" :
      _userFinancialChoice == F326 ? "ENTERPRISE_VALUE" :
      _userFinancialChoice == F327 ? "EQUITY_TO_ASSET" :
      _userFinancialChoice == F328 ? "EV_EBIT" :
      _userFinancialChoice == F329 ? "EV_REVENUE" :
      _userFinancialChoice == F330 ? "FLOAT_SHARES_OUTSTANDING" :
      _userFinancialChoice == F331 ? "FREE_CASH_FLOW_MARGIN" :
      _userFinancialChoice == F332 ? "FULMER_H_FACTOR" :
      _userFinancialChoice == F333 ? "GOODWILL_TO_ASSET" :
      _userFinancialChoice == F334 ? "GRAHAM_NUMBERS" :
      _userFinancialChoice == F335 ? "GROSS_MARGIN" :
      _userFinancialChoice == F336 ? "GROSS_PROFIT_TO_ASSET" :
      _userFinancialChoice == F337 ? "INTERST_COVER" :
      _userFinancialChoice == F338 ? "INVENT_TO_REVENUE" :
      _userFinancialChoice == F339 ? "INVENT_TURNOVER" :
      _userFinancialChoice == F340 ? "KZ_INDEX" :
      _userFinancialChoice == F341 ? "LONG_TERM_DEBT_TO_ASSETS" :
      _userFinancialChoice == F342 ? "NCAVPS_RATIO" :
      _userFinancialChoice == F343 ? "NET_INCOME_PER_EMPLOYEE" :
      _userFinancialChoice == F344 ? "NET_MARGIN" :
      _userFinancialChoice == F345 ? "NUMBER_OF_EMPLOYEES" :
      _userFinancialChoice == F346 ? "OPERATING_EARNINGS_YIELD" :
      _userFinancialChoice == F347 ? "OPERATING_MARGIN" :
      _userFinancialChoice == F348 ? "PEG_RATIO" :
      _userFinancialChoice == F349 ? "PIOTROSKI_F_SCORE" :
      _userFinancialChoice == F350 ? "PRICE_EARNINGS_FORWARD" :
      _userFinancialChoice == F351 ? "PRICE_SALES_FORWARD" :
      _userFinancialChoice == F352 ? "PRICE_TO_FREE_CASH_FLOW" :
      _userFinancialChoice == F353 ? "PRICE_TO_TANGIBLE_BOOK" :
      _userFinancialChoice == F354 ? "QUALITY_RATIO" :
      _userFinancialChoice == F355 ? "QUICK_RATIO" :
      _userFinancialChoice == F356 ? "RESEARCH_AND_DEVELOP_TO_REVENUE" :
      _userFinancialChoice == F357 ? "RETURN_ON_ASSETS" :
      _userFinancialChoice == F358 ? "RETURN_ON_EQUITY_ADJUST_TO_BOOK" :
      _userFinancialChoice == F359 ? "RETURN_ON_EQUITY" :
      _userFinancialChoice == F360 ? "RETURN_ON_INVESTED_CAPITAL" :
      _userFinancialChoice == F361 ? "RETURN_ON_TANG_ASSETS" :
      _userFinancialChoice == F362 ? "RETURN_ON_TANG_EQUITY" :
      _userFinancialChoice == F363 ? "REVENUE_ONE_YEAR_GROWTH" :
      _userFinancialChoice == F364 ? "REVENUE_PER_EMPLOYEE" :
      _userFinancialChoice == F365 ? "SALES_ESTIMATES" :
      _userFinancialChoice == F366 ? "SHARE_BUYBACK_RATIO" :
      _userFinancialChoice == F367 ? "SLOAN_RATIO" :
      _userFinancialChoice == F368 ? "SPRINGATE_SCORE" :
      _userFinancialChoice == F369 ? "SUSTAINABLE_GROWTH_RATE" :
      _userFinancialChoice == F370 ? "TANGIBLE_COMMON_EQUITY_RATIO" :
      _userFinancialChoice == F371 ? "TOBIN_Q_RATIO" :
      _userFinancialChoice == F372 ? "TOTAL_SHARES_OUTSTANDING" :
      _userFinancialChoice == F373 ? "ZMIJEWSKI_SCORE" : na

t1 = request.financial(input.symbol('NASDAQ:AAPL',''), f_getId(i_01), fPeriod)
t2 = request.financial(input.symbol('NASDAQ:MSFT',''), f_getId(i_01), fPeriod)
t3 = request.financial(input.symbol('NASDAQ:AMZN',''), f_getId(i_01), fPeriod)
t4 = request.financial(input.symbol('NASDAQ:TSLA',''), f_getId(i_01), fPeriod)
t5 = request.financial(input.symbol('NASDAQ:GOOG',''), f_getId(i_01), fPeriod)
t6 = request.financial(input.symbol('NASDAQ:GOOGL',''), f_getId(i_01), fPeriod)
t7 = request.financial(input.symbol('NASDAQ:NVDA',''), f_getId(i_01), fPeriod)
t8 = request.financial(input.symbol('NASDAQ:META',''), f_getId(i_01), fPeriod)
t9 = request.financial(input.symbol('NASDAQ:PEP',''), f_getId(i_01), fPeriod)
t10 = request.financial(input.symbol('NASDAQ:COST',''), f_getId(i_01), fPeriod)
t11 = request.financial(input.symbol('NASDAQ:AVGO',''), f_getId(i_01), fPeriod)
t12 = request.financial(input.symbol('NASDAQ:ADBE',''), f_getId(i_01), fPeriod)
t13 = request.financial(input.symbol('NASDAQ:CSCO',''), f_getId(i_01), fPeriod)//
t14 = request.financial(input.symbol('NASDAQ:TMUS',''), f_getId(i_01), fPeriod)
t15 = request.financial(input.symbol('NASDAQ:CMCSA',''), f_getId(i_01), fPeriod)
t16 = request.financial(input.symbol('NASDAQ:QCOM',''), f_getId(i_01), fPeriod)
t17 = request.financial(input.symbol('NASDAQ:INTC',''), f_getId(i_01), fPeriod)
t18 = request.financial(input.symbol('NASDAQ:TXN',''), f_getId(i_01), fPeriod)
t19 = request.financial(input.symbol('NASDAQ:AMD',''), f_getId(i_01), fPeriod)
t20 = request.financial(input.symbol('NASDAQ:AMGN',''), f_getId(i_01), fPeriod)
t21 = request.financial(input.symbol('NASDAQ:HON',''), f_getId(i_01), fPeriod)
t22 = request.financial(input.symbol('NASDAQ:INTU',''), f_getId(i_01), fPeriod)
t23 = request.financial(input.symbol('NASDAQ:NFLX',''), f_getId(i_01), fPeriod)
t24 = request.financial(input.symbol('NASDAQ:ADP',''), f_getId(i_01), fPeriod)
t25 = request.financial(input.symbol('NASDAQ:PYPL',''), f_getId(i_01), fPeriod)
t26 = request.financial(input.symbol('NASDAQ:SBUX',''), f_getId(i_01), fPeriod)
t27 = request.financial(input.symbol('NASDAQ:AMAT',''), f_getId(i_01), fPeriod)
t28 = request.financial(input.symbol('NASDAQ:MDLZ',''), f_getId(i_01), fPeriod)
t29 = request.financial(input.symbol('NASDAQ:ADI',''), f_getId(i_01), fPeriod)
t30 = request.financial(input.symbol('NASDAQ:ISRG',''), f_getId(i_01), fPeriod)
t31 = request.financial(input.symbol('NASDAQ:BKNG',''), f_getId(i_01), fPeriod)
t32 = request.financial(input.symbol('NASDAQ:GILD',''), f_getId(i_01), fPeriod)
t33 = request.financial(input.symbol('NASDAQ:CHTR',''), f_getId(i_01), fPeriod)
t34 = request.financial(input.symbol('NASDAQ:VRTX',''), f_getId(i_01), fPeriod)
t35 = request.financial(input.symbol('NASDAQ:MU',''), f_getId(i_01), fPeriod)
t36 = request.financial(input.symbol('NASDAQ:CSX',''), f_getId(i_01), fPeriod)
t37 = request.financial(input.symbol('NASDAQ:FISV',''), f_getId(i_01), fPeriod)
t38 = request.financial(input.symbol('NASDAQ:LRCX',''), f_getId(i_01), fPeriod)
t39 = request.financial(input.symbol('NASDAQ:REGN',''), f_getId(i_01), fPeriod)
t40 = request.financial(input.symbol('NASDAQ:MRNA',''), f_getId(i_01), fPeriod)

Total = (t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12+t13+t14+t15+t16+t17+t18+t19+t20+t21+t22+t23+t24+t25+t26+t27+t28+t29+t30+t31+t32+t33+t34+t35+t36+t37+t38+t39+t40)
Total := totalAverage == 'Average' ? Total / 40 : Total

plot(Total,'Total',colour)

// ————— Function to format large values.
f_formatValue(_v, _precision) =>    // Thx Alex P.!
    // float _v         : value to format.
    // string _precision: format suffix for precision ("" for none, ".00" for two digits, etc.)
    float _digits = math.log10(math.abs(_v))
    string _precisionFormat = "#" + _precision
    string _return = if _digits > 12
        str.tostring(_v / 1e12, _precisionFormat + "  T")
    else if _digits > 9
        str.tostring(_v / 1e9,  _precisionFormat + "  B")
    else if _digits > 6
        str.tostring(_v / 1e6,  _precisionFormat + "  M")
    else if _digits > 3
        str.tostring(_v / 1e3,  _precisionFormat + "  K")
    else
        str.tostring(_v,  "#" + _precisionFormat)

if barstate.islast
    Label = label.new(bar_index,Total,f_formatValue(Total, ".00")+i_01+' '+fPeriod+', '+totalAverage,textcolor=colour, color=color.rgb(69,69,69,100),style=label.style_label_left)
    label.delete(Label[1])