financials-on-chart.pine
Copy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradingView
//@version=5
indicator("Financials on Chart", "", true)
// Financials on Chart
// v5, 2023.05.27
// This code was written using the recommendations from the Pine Script™ User Manual's Style Guide:
// https://www.tradingview.com/pine-script-docs/en/v5/writing/Style_guide.html
//#region ———————————————————— Constants
// Default values for display.
color LINK_WATER = #D1D4DC
color BG_COL = #1848CC
color BG_DN = #C90707
string TS1 = "tiny"
string TS2 = "small"
string TS3 = "normal"
string TS4 = "large"
string TS5 = "huge"
string TS6 = "auto"
string LG = " Legend"
// Financial periods.
string FQ = "Financial Quarter"
string FY = "Financial Year"
string TT = "Trailing Twelve Months"
// Financial legends.
string F_NA = "⸺"
string F000 = "█ INCOME STATEMENTS █"
string F001 = " After tax other income/expense"
string F002 = " Average basic shares outstanding"
string F003 = " Other COGS"
string F004 = " Cost of goods"
string F005 = " Deprecation and amortization"
string F006 = " Diluted net income available to common stockholders"
string F007 = " Diluted shares outstanding"
string F008 = " Dilution adjustment"
string F009 = " Discontinued operations"
string F010 = " Basic EPS"
string F011 = " Diluted EPS"
string F012 = " EBIT"
string F013 = " EBITDA"
string F014 = " Equity in earnings"
string F015 = " Gross profit"
string F016 = " Taxes"
string F017 = " Interest capitalized"
string F018 = " Interest expense on debt"
string F019 = " Non-controlling/minority interest"
string F020 = " Net income before discontinued operations"
string F021 = " Net income"
string F022 = " Non-operating income, excl. interest expenses"
string F023 = " Interest expense, net of interest capitalized"
string F024 = " Non-operating interest income"
string F025 = " Operating income"
string F026 = " Operating expenses (excl. COGS)"
string F027 = " Miscellaneous non-operating expense"
string F028 = " Other operating expenses, total"
string F029 = " Preferred dividends"
string F030 = " Pretax equity in earnings"
string F031 = " Pretax income"
string F032 = " Research & development"
string F033 = " Selling/general/admin expenses, other"
string F034 = " Selling/general/admin expenses, total"
string F035 = " Non-operating income, total"
string F036 = " Total operating expenses"
string F037 = " Total revenue"
string F038 = " Unusual income/expense"
string F100 = "█ BALANCE SHEET █"
string F101 = " Accounts payable"
string F102 = " Accounts receivable - trade, net"
string F103 = " Accrued payroll"
string F104 = " Accumulated depreciation, total"
string F105 = " Additional paid-in capital/Capital surplus"
string F106 = " Tangible book value per share"
string F107 = " Book value per share"
string F108 = " Capitalized lease obligations"
string F109 = " Capital and operating lease obligations"
string F110 = " Cash & equivalents"
string F111 = " Cash and short term investments"
string F112 = " Common equity, total"
string F113 = " Common stock par/Carrying value"
string F114 = " Current portion of LT debt and capital leases"
string F115 = " Deferred income, current"
string F116 = " Deferred income, non-current"
string F117 = " Deferred tax assets"
string F118 = " Deferred tax liabilities"
string F119 = " Dividends payable"
string F120 = " Goodwill, net"
string F121 = " Income tax payable"
string F122 = " Net intangible assets"
string F123 = " Inventories - finished goods"
string F124 = " Inventories - progress payments & other"
string F125 = " Inventories - raw materials"
string F126 = " Inventories - work in progress"
string F127 = " Investments in unconsolidated subsidiaries"
string F128 = " Long term debt excl. lease liabilities"
string F129 = " Long term debt"
string F130 = " Long term investments"
string F131 = " Note receivable - long term"
string F132 = " Other long term assets, total"
string F133 = " Minority interest"
string F134 = " Notes payable"
string F135 = " Operating lease liabilities"
string F136 = " Other common equity"
string F137 = " Other current assets, total"
string F138 = " Other current liabilities"
string F139 = " Other intangibles, net"
string F140 = " Other investments"
string F141 = " Other liabilities, total"
string F142 = " Other receivables"
string F143 = " Other short term debt"
string F144 = " Paid in capital"
string F145 = " Gross property/plant/equipment"
string F146 = " Net property/plant/equipment"
string F147 = " Preferred stock, carrying value"
string F148 = " Prepaid expenses"
string F149 = " Provision for risks & charge"
string F150 = " Retained earnings"
string F151 = " Short term debt excl. current portion of LT debt"
string F152 = " Short term debt"
string F153 = " Short term investments"
string F154 = " Shareholders' equity"
string F155 = " Total assets"
string F156 = " Total current assets"
string F157 = " Total current liabilities"
string F158 = " Total debt"
string F159 = " Total equity"
string F160 = " Total inventory"
string F161 = " Total liabilities"
string F162 = " Total liabilities & shareholders' equities"
string F163 = " Total non-current assets"
string F164 = " Total non-current liabilities"
string F165 = " Total receivables, net"
string F166 = " Treasury stock - common"
string F200 = "█ CASHFLOW █"
string F201 = " Amortization"
string F202 = " Capital expenditures - fixed assets"
string F203 = " Capital expenditures"
string F204 = " Capital expenditures - other assets"
string F205 = " Cash from financing activities"
string F206 = " Cash from investing activities"
string F207 = " Cash from operating activities"
string F208 = " Deferred taxes (cash flow)"
string F209 = " Depreciation & amortization (cash flow)"
string F210 = " Change in accounts payable"
string F211 = " Change in accounts receivable"
string F212 = " Change in accrued expenses"
string F213 = " Change in inventories"
string F214 = " Change in other assets/liabilities"
string F215 = " Change in taxes payable"
string F216 = " Changes in working capital"
string F217 = " Common dividends paid"
string F218 = " Depreciation/depletion"
string F219 = " Free cash flow"
string F220 = " Funds from operations"
string F221 = " Issuance/retirement of debt, net"
string F222 = " Issuance/retirement of long term debt"
string F223 = " Issuance/retirement of other debt"
string F224 = " Issuance/retirement of short term debt"
string F225 = " Issuance/retirement of stock, net"
string F226 = " Net income (cash flow)"
string F227 = " Non-cash items"
string F228 = " Other financing cash flow items, total"
string F229 = " Financing activities - other sources"
string F230 = " Financing activities - other uses"
string F231 = " Other investing cash flow items, total"
string F232 = " Investing activities - other sources"
string F233 = " Investing activities - other uses"
string F234 = " Preferred dividends paid"
string F235 = " Purchase/acquisition of business"
string F236 = " Purchase of investments"
string F237 = " Repurchase of common & preferred stock"
string F238 = " Purchase/sale of business, net"
string F239 = " Purchase/sale of investments, net"
string F240 = " Reduction of long term debt"
string F241 = " Sale of common & preferred stock"
string F242 = " Sale of fixed assets & businesses"
string F243 = " Sale/maturity of investments"
string F244 = " Issuance of long term debt"
string F245 = " Total cash dividends paid"
string F300 = "█ STATISTICS █"
string F301 = " Accruals"
string F302 = " Altman Z-score"
string F303 = " Asset turnover"
string F304 = " Beneish M-score"
string F305 = " Buyback yield %"
string F306 = " Cash conversion cycle"
string F307 = " Cash to debt ratio"
string F308 = " COGS to revenue ratio"
string F309 = " Current ratio"
string F310 = " Days sales outstanding"
string F311 = " Days inventory"
string F312 = " Days payable"
string F313 = " Debt to assets ratio"
string F314 = " Debt to EBITDA ratio"
string F315 = " Debt to equity ratio"
string F316 = " Debt to revenue ratio"
string F317 = " Dividend payout ratio %"
string F318 = " Dividend yield %"
string F319 = " Dividends per share - common stock primary issue"
string F320 = " EPS estimates"
string F321 = " EPS basic one year growth"
string F322 = " EPS diluted one year growth"
string F323 = " EBITDA margin %"
string F324 = " Effective interest rate on debt %"
string F325 = " Enterprise value to EBITDA ratio"
string F326 = " Enterprise value"
string F327 = " Equity to assets ratio"
string F328 = " Enterprise value to EBIT ratio"
string F329 = " Enterprise value to revenue ratio"
string F330 = " Float shares outstanding"
string F331 = " Free cash flow margin %"
string F332 = " Fulmer H factor"
string F333 = " Goodwill to assets ratio"
string F334 = " Graham's number"
string F335 = " Gross margin %"
string F336 = " Gross profit to assets ratio"
string F337 = " Interest coverage"
string F338 = " Inventory to revenue ratio"
string F339 = " Inventory turnover"
string F340 = " KZ index"
string F341 = " Long term debt to total assets ratio"
string F342 = " Net current asset value per share"
string F343 = " Net income per employee"
string F344 = " Net margin %"
string F345 = " Number of employees"
string F346 = " Operating earnings yield %"
string F347 = " Operating margin %"
string F348 = " PEG ratio"
string F349 = " Piotroski F-score"
string F350 = " Price earnings ratio forward"
string F351 = " Price sales ratio forward"
string F352 = " Price to free cash flow ratio"
string F353 = " Price to tangible book ratio"
string F354 = " Quality ratio"
string F355 = " Quick ratio"
string F356 = " Research & development to revenue ratio"
string F357 = " Return on assets %"
string F358 = " Return on equity adjusted to book value %"
string F359 = " Return on equity %"
string F360 = " Return on invested capital %"
string F361 = " Return on tangible assets %"
string F362 = " Return on tangible equity %"
string F363 = " Revenue one year growth"
string F364 = " Revenue per employee"
string F365 = " Revenue estimates"
string F366 = " Shares buyback ratio %"
string F367 = " Sloan ratio %"
string F368 = " Springate score"
string F369 = " Sustainable growth rate"
string F370 = " Tangible common equity ratio"
string F371 = " Tobin's Q (approximate)"
string F372 = " Total common shares outstanding"
string F373 = " Zmijewski score"
string F400 = "█ CALCULATED █"
string F401 = " Market Capitalization"
string F402 = " Earnings Yield"
string F403 = " Price Book Ratio"
string F404 = " Price Earnings Ratio"
string F405 = " Price-To-Sales Ratio"
string BG = "⛆"
string POS_TT = "Position on the chart."
string WTH_TT = "0-100. Use 0 to auto-size height and width."
string BG_TT = "These attributes apply to all the display. You can customize the text size and the background color for individual values in the section below."
string PER_TT = "Fields are: Value, Period and Precision.\nPERIOD\n• 'Financial Quarter' is not available for Dividends payable, Notes payable, Other short term debt, Float shares outstanding, KZ index, Net income per employee, Number of employees, Revenue per employee.\n• The 'Trailing Twelve Months' period is only available for Basic EPS and EBITDA."
//#endregion
//#region ———————————————————— Inputs
string GRP0 = "══════════ Position & Size ══════════"
string yPosInput = input.string("top" , "↕" , inline = "01", group = GRP0, options = ["top", "middle", "bottom"])
string xPosInput = input.string("right" , "↔" , inline = "01", group = GRP0, options = ["left", "center", "right"], tooltip = POS_TT)
int rowHeightInput = input.int(0 , "|" , inline = "02", group = GRP0, minval = 0, maxval = 100)
int colWidthInput = input.int(0 , "—" , inline = "02", group = GRP0, minval = 0, maxval = 100, tooltip = WTH_TT)
color textColorInput = input.color(LINK_WATER, "Text" , inline = "03", group = GRP0)
string textSizeInput = input.string(TS6 , "" , inline = "03", group = GRP0, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color tableBgInput = input.color(BG_COL , BG , inline = "03", group = GRP0)
color tableBgDnInput = input.color(BG_DN , "🡓" , inline = "03", group = GRP0, tooltip = BG_TT)
string currencyInput = input.string("" , "Conversion" , inline = "04", group = GRP0, options = ["", "USD", "EUR", "CAD", "JPY", "GBP", "HKD", "CNY", "NZD", "RUB", "AUD", "CHF", "NOK", "SEK", "SGD", "TRY", "ZAR", "MYR", "KRW", "USDT", "INR"])
bool showCurrencyInput = input.bool(true , "Show currencyInput" , inline = "04", group = GRP0)
bool abbrValuesInput = input.bool(true , "Abbreviate large values", group = GRP0)
string GRP1 = "═════════════ Row 1 ═════════════"
string typeInput1 = input.string(F401 , "", inline = "11", group = GRP1,
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])
string periodInput1 = input.string(FY , "", inline = "11", group = GRP1, options = [FY, FQ, TT], tooltip = PER_TT)
int precInput1 = input.int(3 , "", inline = "11", group = GRP1, minval = 0, maxval = 10)
string legendInput1 = input.string("" , LG, inline = "12", group = GRP1)
string textSize1 = input.string(TS6 , "", inline = "12", group = GRP1, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg1 = input.color(BG_COL, BG, inline = "12", group = GRP1)
string GRP2 = "═════════════ Row 2 ═════════════"
string typeInput2 = input.string(F402 , "" , inline = "21", group = GRP2,
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])
string periodInput2 = input.string(FY , "", inline = "21", group = GRP2, options = [FY, FQ, TT])
int precInput2 = input.int(2 , "", inline = "21", group = GRP2, minval = 0, maxval = 10)
string legendInput2 = input.string("" , LG, inline = "22", group = GRP2)
string textSize2 = input.string(TS6 , "", inline = "22", group = GRP2, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg2 = input.color(BG_COL, BG, inline = "22", group = GRP2)
string GRP3 = "═════════════ Row 3 ═════════════"
string typeInput3 = input.string(F403 , "", inline = "31", group = GRP3,
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])
string periodInput3 = input.string(FY , "", inline = "31", group = GRP3, options = [FY, FQ, TT])
int precInput3 = input.int(2 , "", inline = "31", group = GRP3, minval = 0, maxval = 10)
string legendInput3 = input.string("" , LG, inline = "32", group = GRP3)
string textSize3 = input.string(TS6 , "", inline = "32", group = GRP3, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg3 = input.color(BG_COL, BG, inline = "32", group = GRP3)
string GRP4 = "═════════════ Row 4 ═════════════"
string typeInput4 = input.string(F404 , "", inline = "41", group = GRP4,
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])
string periodInput4 = input.string(FY , "", inline = "41", group = GRP4, options = [FY, FQ, TT])
int precInput4 = input.int(2 , "", inline = "41", group = GRP4, minval = 0, maxval = 10)
string legendInput4 = input.string("" , LG, inline = "42", group = GRP4)
string textSize4 = input.string(TS6 , "", inline = "42", group = GRP4, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg4 = input.color(BG_COL, BG, inline = "42", group = GRP4)
string GRP5 = "═════════════ Row 5 ═════════════"
string typeInput5 = input.string(F405 , "", inline = "51", group = GRP5,
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])
string periodInput5 = input.string(FY , "", inline = "51", group = GRP5, options = [FY, FQ, TT])
int precInput5 = input.int(2 , "", inline = "51", group = GRP5, minval = 0, maxval = 10)
string legendInput5 = input.string("" , LG, inline = "52", group = GRP5)
string textSize5 = input.string(TS6 , "", inline = "52", group = GRP5, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg5 = input.color(BG_COL, BG, inline = "52", group = GRP5)
string GRP6 = "═════════════ Row 6 ═════════════"
string typeInput6 = input.string(F013 , "", inline = "61", group = GRP6,
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])
string periodInput6 = input.string(FY , "", inline = "61", group = GRP6, options = [FY, FQ, TT])
int precInput6 = input.int(3 , "", inline = "61", group = GRP6, minval = 0, maxval = 10)
string legendInput6 = input.string("" , LG, inline = "62", group = GRP6)
string textSize6 = input.string(TS6 , "", inline = "62", group = GRP6, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg6 = input.color(BG_COL, BG, inline = "62", group = GRP6)
string GRP7 = "═════════════ Row 7 ═════════════"
string typeInput7 = input.string(F364 , "", inline = "71", group = GRP7,
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])
string periodInput7 = input.string(FY , "", inline = "71", group = GRP7, options = [FY, FQ, TT])
int precInput7 = input.int(3 , "", inline = "71", group = GRP7, minval = 0, maxval = 10)
string legendInput7 = input.string("" , LG, inline = "72", group = GRP7)
string textSize7 = input.string(TS6 , "", inline = "72", group = GRP7, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg7 = input.color(BG_COL, BG, inline = "72", group = GRP7)
string GRP8 = "═════════════ Row 8 ═════════════"
string typeInput8 = input.string(F373 , "", inline = "81", group = GRP8,
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])
string periodInput8 = input.string(FY , "", inline = "81", group = GRP8, options = [FY, FQ, TT])
int precInput8 = input.int(2 , "", inline = "81", group = GRP8, minval = 0, maxval = 10)
string legendInput8 = input.string("" , LG, inline = "82", group = GRP8)
string textSize8 = input.string(TS6 , "", inline = "82", group = GRP8, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg8 = input.color(BG_COL, BG, inline = "82", group = GRP8)
string GRP9 = "═════════════ Row 9 ═════════════"
string typeInput9 = input.string(F_NA , "", inline = "91", group = GRP9,
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])
string periodInput9 = input.string(FY , "", inline = "91", group = GRP9, options = [FY, FQ, TT])
int precInput9 = input.int(0 , "", inline = "91", group = GRP9, minval = 0, maxval = 10)
string legendInput9 = input.string("" , LG, inline = "92", group = GRP9)
string textSize9 = input.string(TS6 , "", inline = "92", group = GRP9, options = [TS1, TS2, TS3, TS4, TS5, TS6])
color bg9 = input.color(BG_COL, BG, inline = "92", group = GRP9)
// Table used to display values.
var table display = table.new(yPosInput + "_" + xPosInput, 2, 10, border_width = 2)
//#endregion
//#region ———————————————————— Functions
// @function Converts a string from one the financial metrics to a string capapatible with the `request.financial()` function.
// @param userFinancialChoice (simple string) A string matching one of the metrics listed in the "Financial Legends" section.
// @returns (string) From the `userFinancialChoice` `options` `Fxxx` string, the `id` argument to be used with a `request.financial()` call, unless a calculated financial in the `F4xx` range was chosen.
getId(simple string userFinancialChoice) =>
string result = switch userFinancialChoice
F001 => "AFTER_TAX_OTHER_INCOME"
F002 => "BASIC_SHARES_OUTSTANDING"
F003 => "COST_OF_GOODS_EXCL_DEP_AMORT"
F004 => "COST_OF_GOODS"
F005 => "DEP_AMORT_EXP_INCOME_S"
F006 => "DILUTED_NET_INCOME"
F007 => "DILUTED_SHARES_OUTSTANDING"
F008 => "DILUTION_ADJUSTMENT"
F009 => "DISCONTINUED_OPERATIONS"
F010 => "EARNINGS_PER_SHARE_BASIC"
F011 => "EARNINGS_PER_SHARE_DILUTED"
F012 => "EBIT"
F013 => "EBITDA"
F014 => "EQUITY_IN_EARNINGS"
F015 => "GROSS_PROFIT"
F016 => "INCOME_TAX"
F017 => "INTEREST_CAPITALIZED"
F018 => "INTEREST_EXPENSE_ON_DEBT"
F019 => "MINORITY_INTEREST_EXP"
F020 => "NET_INCOME_BEF_DISC_OPER"
F021 => "NET_INCOME"
F022 => "NON_OPER_INCOME"
F023 => "NON_OPER_INTEREST_EXP"
F024 => "NON_OPER_INTEREST_INCOME"
F025 => "OPER_INCOME"
F026 => "OPERATING_EXPENSES"
F027 => "OTHER_INCOME"
F028 => "OTHER_OPER_EXPENSE_TOTAL"
F029 => "PREFERRED_DIVIDENDS"
F030 => "PRETAX_EQUITY_IN_EARNINGS"
F031 => "PRETAX_INCOME"
F032 => "RESEARCH_AND_DEV"
F033 => "SELL_GEN_ADMIN_EXP_OTHER"
F034 => "SELL_GEN_ADMIN_EXP_TOTAL"
F035 => "TOTAL_NON_OPER_INCOME"
F036 => "TOTAL_OPER_EXPENSE"
F037 => "TOTAL_REVENUE"
F038 => "UNUSUAL_EXPENSE_INC"
F101 => "ACCOUNTS_PAYABLE"
F102 => "ACCOUNTS_RECEIVABLES_NET"
F103 => "ACCRUED_PAYROLL"
F104 => "ACCUM_DEPREC_TOTAL"
F105 => "ADDITIONAL_PAID_IN_CAPITAL"
F106 => "BOOK_TANGIBLE_PER_SHARE"
F107 => "BOOK_VALUE_PER_SHARE"
F108 => "CAPITAL_LEASE_OBLIGATIONS"
F109 => "CAPITAL_OPERATING_LEASE_OBLIGATIONS"
F110 => "CASH_N_EQUIVALENTS"
F111 => "CASH_N_SHORT_TERM_INVEST"
F112 => "COMMON_EQUITY_TOTAL"
F113 => "COMMON_STOCK_PAR"
F114 => "CURRENT_PORT_DEBT_CAPITAL_LEASES"
F115 => "DEFERRED_INCOME_CURRENT"
F116 => "DEFERRED_INCOME_NON_CURRENT"
F117 => "DEFERRED_TAX_ASSESTS"
F118 => "DEFERRED_TAX_LIABILITIES"
F119 => "DIVIDENDS_PAYABLE"
F120 => "GOODWILL"
F121 => "INCOME_TAX_PAYABLE"
F122 => "INTANGIBLES_NET"
F123 => "INVENTORY_FINISHED_GOODS"
F124 => "INVENTORY_PROGRESS_PAYMENTS"
F125 => "INVENTORY_RAW_MATERIALS"
F126 => "INVENTORY_WORK_IN_PROGRESS"
F127 => "INVESTMENTS_IN_UNCONCSOLIDATE"
F128 => "LONG_TERM_DEBT_EXCL_CAPITAL_LEASE"
F129 => "LONG_TERM_DEBT"
F130 => "LONG_TERM_INVESTMENTS"
F131 => "LONG_TERM_NOTE_RECEIVABLE"
F132 => "LONG_TERM_OTHER_ASSETS_TOTAL"
F133 => "MINORITY_INTEREST"
F134 => "NOTES_PAYABLE_SHORT_TERM_DEBT"
F135 => "OPERATING_LEASE_LIABILITIES"
F136 => "OTHER_COMMON_EQUITY"
F137 => "OTHER_CURRENT_ASSETS_TOTAL"
F138 => "OTHER_CURRENT_LIABILITIES"
F139 => "OTHER_INTANGIBLES_NET"
F140 => "OTHER_INVESTMENTS"
F141 => "OTHER_LIABILITIES_TOTAL"
F142 => "OTHER_RECEIVABLES"
F143 => "OTHER_SHORT_TERM_DEBT"
F144 => "PAID_IN_CAPITAL"
F145 => "PPE_TOTAL_GROSS"
F146 => "PPE_TOTAL_NET"
F147 => "PREFERRED_STOCK_CARRYING_VALUE"
F148 => "PREPAID_EXPENSES"
F149 => "PROVISION_F_RISKS"
F150 => "RETAINED_EARNINGS"
F151 => "SHORT_TERM_DEBT_EXCL_CURRENT_PORT"
F152 => "SHORT_TERM_DEBT"
F153 => "SHORT_TERM_INVEST"
F154 => "SHRHLDRS_EQUITY"
F155 => "TOTAL_ASSETS"
F156 => "TOTAL_CURRENT_ASSETS"
F157 => "TOTAL_CURRENT_LIABILITIES"
F158 => "TOTAL_DEBT"
F159 => "TOTAL_EQUITY"
F160 => "TOTAL_INVENTORY"
F161 => "TOTAL_LIABILITIES"
F162 => "TOTAL_LIABILITIES_SHRHLDRS_EQUITY"
F163 => "TOTAL_NON_CURRENT_ASSETS"
F164 => "TOTAL_NON_CURRENT_LIABILITIES"
F165 => "TOTAL_RECEIVABLES_NET"
F166 => "TREASURY_STOCK_COMMON"
F201 => "AMORTIZATION"
F202 => "CAPITAL_EXPENDITURES_FIXED_ASSETS"
F203 => "CAPITAL_EXPENDITURES"
F204 => "CAPITAL_EXPENDITURES_OTHER_ASSETS"
F205 => "CASH_F_FINANCING_ACTIVITIES"
F206 => "CASH_F_INVESTING_ACTIVITIES"
F207 => "CASH_F_OPERATING_ACTIVITIES"
F208 => "CASH_FLOW_DEFERRED_TAXES"
F209 => "CASH_FLOW_DEPRECATION_N_AMORTIZATION"
F210 => "CHANGE_IN_ACCOUNTS_PAYABLE"
F211 => "CHANGE_IN_ACCOUNTS_RECEIVABLE"
F212 => "CHANGE_IN_ACCRUED_EXPENSES"
F213 => "CHANGE_IN_INVENTORIES"
F214 => "CHANGE_IN_OTHER_ASSETS"
F215 => "CHANGE_IN_TAXES_PAYABLE"
F216 => "CHANGES_IN_WORKING_CAPITAL"
F217 => "COMMON_DIVIDENDS_CASH_FLOW"
F218 => "DEPRECIATION_DEPLETION"
F219 => "FREE_CASH_FLOW"
F220 => "FUNDS_F_OPERATIONS"
F221 => "ISSUANCE_OF_DEBT_NET"
F222 => "ISSUANCE_OF_LONG_TERM_DEBT"
F223 => "ISSUANCE_OF_OTHER_DEBT"
F224 => "ISSUANCE_OF_SHORT_TERM_DEBT"
F225 => "ISSUANCE_OF_STOCK_NET"
F226 => "NET_INCOME_STARTING_LINE"
F227 => "NON_CASH_ITEMS"
F228 => "OTHER_FINANCING_CASH_FLOW_ITEMS_TOTAL"
F229 => "OTHER_FINANCING_CASH_FLOW_SOURCES"
F230 => "OTHER_FINANCING_CASH_FLOW_USES"
F231 => "OTHER_INVESTING_CASH_FLOW_ITEMS_TOTAL"
F232 => "OTHER_INVESTING_CASH_FLOW_SOURCES"
F233 => "OTHER_INVESTING_CASH_FLOW_USES"
F234 => "PREFERRED_DIVIDENDS_CASH_FLOW"
F235 => "PURCHASE_OF_BUSINESS"
F236 => "PURCHASE_OF_INVESTMENTS"
F237 => "PURCHASE_OF_STOCK"
F238 => "PURCHASE_SALE_BUSINESS"
F239 => "PURCHASE_SALE_INVESTMENTS"
F240 => "REDUCTION_OF_LONG_TERM_DEBT"
F241 => "SALE_OF_STOCK"
F242 => "SALES_OF_BUSINESS"
F243 => "SALES_OF_INVESTMENTS"
F244 => "SUPPLYING_OF_LONG_TERM_DEBT"
F245 => "TOTAL_CASH_DIVIDENDS_PAID"
F301 => "ACCRUALS_RATIO"
F302 => "ALTMAN_Z_SCORE"
F303 => "ASSET_TURNOVER"
F304 => "BENEISH_M_SCORE"
F305 => "BUYBACK_YIELD"
F306 => "CASH_CONVERSION_CYCLE"
F307 => "CASH_TO_DEBT"
F308 => "COGS_TO_REVENUE"
F309 => "CURRENT_RATIO"
F310 => "DAY_SALES_OUT"
F311 => "DAYS_INVENT"
F312 => "DAYS_PAY"
F313 => "DEBT_TO_ASSET"
F314 => "DEBT_TO_EBITDA"
F315 => "DEBT_TO_EQUITY"
F316 => "DEBT_TO_REVENUE"
F317 => "DIVIDEND_PAYOUT_RATIO"
F318 => "DIVIDENDS_YIELD"
F319 => "DPS_COMMON_STOCK_PRIM_ISSUE"
F320 => "EARNINGS_ESTIMATE"
F321 => "EARNINGS_PER_SHARE_BASIC_ONE_YEAR_GROWTH"
F322 => "EARNINGS_PER_SHARE_DILUTED_ONE_YEAR_GROWTH"
F323 => "EBITDA_MARGIN"
F324 => "EFFECTIVE_INTEREST_RATE_ON_DEBT"
F325 => "ENTERPRISE_VALUE_EBITDA"
F326 => "ENTERPRISE_VALUE"
F327 => "EQUITY_TO_ASSET"
F328 => "EV_EBIT"
F329 => "EV_REVENUE"
F330 => "FLOAT_SHARES_OUTSTANDING"
F331 => "FREE_CASH_FLOW_MARGIN"
F332 => "FULMER_H_FACTOR"
F333 => "GOODWILL_TO_ASSET"
F334 => "GRAHAM_NUMBERS"
F335 => "GROSS_MARGIN"
F336 => "GROSS_PROFIT_TO_ASSET"
F337 => "INTERST_COVER"
F338 => "INVENT_TO_REVENUE"
F339 => "INVENT_TURNOVER"
F340 => "KZ_INDEX"
F341 => "LONG_TERM_DEBT_TO_ASSETS"
F342 => "NCAVPS_RATIO"
F343 => "NET_INCOME_PER_EMPLOYEE"
F344 => "NET_MARGIN"
F345 => "NUMBER_OF_EMPLOYEES"
F346 => "OPERATING_EARNINGS_YIELD"
F347 => "OPERATING_MARGIN"
F348 => "PEG_RATIO"
F349 => "PIOTROSKI_F_SCORE"
F350 => "PRICE_EARNINGS_FORWARD"
F351 => "PRICE_SALES_FORWARD"
F352 => "PRICE_TO_FREE_CASH_FLOW"
F353 => "PRICE_TO_TANGIBLE_BOOK"
F354 => "QUALITY_RATIO"
F355 => "QUICK_RATIO"
F356 => "RESEARCH_AND_DEVELOP_TO_REVENUE"
F357 => "RETURN_ON_ASSETS"
F358 => "RETURN_ON_EQUITY_ADJUST_TO_BOOK"
F359 => "RETURN_ON_EQUITY"
F360 => "RETURN_ON_INVESTED_CAPITAL"
F361 => "RETURN_ON_TANG_ASSETS"
F362 => "RETURN_ON_TANG_EQUITY"
F363 => "REVENUE_ONE_YEAR_GROWTH"
F364 => "REVENUE_PER_EMPLOYEE"
F365 => "SALES_ESTIMATES"
F366 => "SHARE_BUYBACK_RATIO"
F367 => "SLOAN_RATIO"
F368 => "SPRINGATE_SCORE"
F369 => "SUSTAINABLE_GROWTH_RATE"
F370 => "TANGIBLE_COMMON_EQUITY_RATIO"
F371 => "TOBIN_Q_RATIO"
F372 => "TOTAL_SHARES_OUTSTANDING"
F373 => "ZMIJEWSKI_SCORE"
=> ""
// @function Checks if the user-defined metric is denoted in currency.
// @param userFinancialChoice (simple string) A string matching one of the metrics listed in the "Financial Legends" section.
// @returns (bool) True if the `userFinancialChoice`'s units are currency.
valueIsInCurrency(simple string userFinancialChoice) =>
bool result = switch userFinancialChoice
F302 => false
F304 => false
F305 => false
F306 => false
F307 => false
F308 => false
F309 => false
F310 => false
F311 => false
F312 => false
F313 => false
F314 => false
F315 => false
F316 => false
F317 => false
F318 => false
F319 => false
F321 => false
F322 => false
F323 => false
F324 => false
F325 => false
F327 => false
F328 => false
F329 => false
F330 => false
F331 => false
F332 => false
F333 => false
F334 => false
F335 => false
F336 => false
F337 => false
F338 => false
F339 => false
F340 => false
F341 => false
F342 => false
F344 => false
F345 => false
F346 => false
F347 => false
F348 => false
F349 => false
F350 => false
F351 => false
F352 => false
F353 => false
F354 => false
F355 => false
F356 => false
F357 => false
F358 => false
F359 => false
F360 => false
F361 => false
F362 => false
F363 => false
F366 => false
F367 => false
F368 => false
F369 => false
F370 => false
F371 => false
F372 => false
F373 => false
F402 => false
F403 => false
F404 => false
F405 => false
=> true
// @function Formats large values.
// @param value (series float) Value to format.
// @param precision (seires string) Format suffix for precision ("" for none, ".00" for two digits, etc.).
// @returns (string) A formatted string of the `value` to the desired `precision` in one of the stepped unit symbols (K, M, B, T).
formatValue(series float value, series string precision) =>
float digits = math.log10(math.abs(value))
string precisionFormat = "#" + precision
string result = switch
digits > 12 => str.tostring(value / 1e12, precisionFormat + " T")
digits > 9 => str.tostring(value / 1e9, precisionFormat + " B")
digits > 6 => str.tostring(value / 1e6, precisionFormat + " M")
digits > 3 => str.tostring(value / 1e3, precisionFormat + " K")
=> str.tostring(value, "#" + precisionFormat)
// @function Concatenates a result string by multiplying an input string a set number of times.
// @param count (simple int) The number of iterations to add the input string to the result.
// @param str (simple string) The string to be concatenated.
// @returns (string) A string by concatenating `count` times the `str`.
stringOf(simple int count, simple string str) =>
var string msg = na
var int i = 0
while i < count
msg += str
i += 1
string result = msg
// @function Converts a price to a user defined currency using `request.security()`.
// @param price (series float) The price to convert.
// @param currency (simple string) The currency to convert
// @returns (float) Returns a value in the user-chosen currency converted from `price`.
convertCurrency(series float price, simple string currency) =>
float convertedClose = request.security(syminfo.tickerid, timeframe.period, close, currency = currency, ignore_invalid_symbol = true)
float ratio = convertedClose / close
float result = math.round_to_mintick(price * ratio)
// @function Will calculate a finacial ratio if the input string matches one of the 5 metrics (MC, TSO, TR, EPS, or BVPS).
// @param financialId (simple string) A string matching one of the metrics listed in the "Financial Legends" section.
// @returns (float) A calculated financial if `financialId` corresponds to one, `na` otherwise.
calculatedFinancial(simple string financialId) =>
float tso = request.financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ", ignore_invalid_symbol = true)
float tr = request.financial(syminfo.tickerid, "TOTAL_REVENUE", "TTM", ignore_invalid_symbol = true)
float eps = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE", "TTM", ignore_invalid_symbol = true)
float bvps = request.financial(syminfo.tickerid, "BOOK_VALUE_PER_SHARE", "FQ", ignore_invalid_symbol = true)
float marketCap = tso * close
float earningsYield = (eps / close) * 100.
float priceBookRatio = close / bvps
float priceEarningsRatio = close / eps
float priseSalesRatio = marketCap / tr
float result = switch financialId
F401 => marketCap
F402 => earningsYield
F403 => priceBookRatio
F404 => priceEarningsRatio
F405 => priseSalesRatio
=> na
result
// @function Populates a row of table cells with a user-selcted financial measure.
// @param pos (simple int) The position of the row in the display table.
// @param tab (table) The table to which the cells belong.
// @param desc (simple string) The user-selected metric to display. (Must be one of the measures oulined in "Financial Legends").
// @param period (simple string) The time period for which the metrics pertain to ie. quaterly, yearly, etc. Options are "FQ", "FY", or "TTM".
// @param precision (simple int) The precision after the decimal for numbers displayed.
// @param legend (simple string) An optional user-defined replacement for the financial metric displayed in the left column.
// @param textSize (simple string) The size of the text.
// @param bg (simple color) The background color of the table cell.
// @returns (void) Fetches or calculates one user-selected financial in the selected currencyInput (if one is selected), and displays it.
printFinancial(simple int pos, table tab, simple string desc, simple string period, simple int precision, simple string legend, simple string textSize, simple color bg) =>
string valuePeriod = period == FQ ? "FQ" : period == FY ? "FY" : "TTM"
bool valueIsInCurrency = valueIsInCurrency(desc)
string valuePrecision = (precision == 0 ? "" : ".") + stringOf(precision, "0")
string builtinId = getId(desc)
bool userChoseABuiltin = builtinId != ""
string valueId = userChoseABuiltin ? builtinId : "BASIC_SHARES_OUTSTANDING"
string legendToPrint = legend != "" ? " " + legend : desc
string sizeTxt = textSize == TS6 ? textSizeInput : textSize
color legendBg = bg == BG_COL ? tableBgInput : bg
float financialCalculated = if desc == F401 or desc == F402 or desc == F403 or desc == F404 or desc == F405
calculatedFinancial(desc)
bool userMadeASelection = userChoseABuiltin or not na(financialCalculated)
float financialBuiltin = request.financial(syminfo.tickerid, valueId, valuePeriod, ignore_invalid_symbol = true)
float financialRaw = nz(financialCalculated, financialBuiltin)
float financialConverted = convertCurrency(financialRaw, currencyInput)
float financial = valueIsInCurrency ? financialConverted : financialRaw
color valueBg = financial < 0 ? tableBgDnInput : legendBg
int row = pos - 1
string currency = not showCurrencyInput or not valueIsInCurrency ? "" : currencyInput == "" ? syminfo.currency : currencyInput
string str = na(financial) ? "" : " " + (abbrValuesInput ? formatValue(financial, valuePrecision) : str.tostring(financial, "###,###,###,###,###,###" + valuePrecision)) + " " + currency
if userMadeASelection and barstate.islastconfirmedhistory
table.cell(tab, 0, row, legendToPrint, colWidthInput, rowHeightInput, textColorInput, text.align_left, text.align_center, sizeTxt, legendBg)
table.cell(tab, 1, row, str, colWidthInput, rowHeightInput, textColorInput, text.align_left, text.align_center, sizeTxt, valueBg)
if userMadeASelection and barstate.islast
table.cell_set_text(tab, 1, row, str)
//#endregion
//#region ———————————————————— Display
printFinancial(1, display, typeInput1, periodInput1, precInput1, legendInput1, textSize1, bg1)
printFinancial(2, display, typeInput2, periodInput2, precInput2, legendInput2, textSize2, bg2)
printFinancial(3, display, typeInput3, periodInput3, precInput3, legendInput3, textSize3, bg3)
printFinancial(4, display, typeInput4, periodInput4, precInput4, legendInput4, textSize4, bg4)
printFinancial(5, display, typeInput5, periodInput5, precInput5, legendInput5, textSize5, bg5)
printFinancial(6, display, typeInput6, periodInput6, precInput6, legendInput6, textSize6, bg6)
printFinancial(7, display, typeInput7, periodInput7, precInput7, legendInput7, textSize7, bg7)
printFinancial(8, display, typeInput8, periodInput8, precInput8, legendInput8, textSize8, bg8)
printFinancial(9, display, typeInput9, periodInput9, precInput9, legendInput9, textSize9, bg9)
bgcolor(color.new(tableBgInput, 100))
//#endregion
Show all 854 lines