Financial data on tradingview

This is the first code I have created to show financial information of companies on Tradingview.

To start with something basic I have entered just some data: revenue, gross profit, operating income, EBITDA, and free cashflow.

This link contains the financial data you can use on PINE.

What can you check on the selection pane?

On “period”, you can show the data related to:

  • the fiscal quarters
  • or the fiscal years.

You can select a pack of financial data that I have organized in sections:

  • Revenue & earnings
  • EPS & DPS (EPS, EPS estimate, DPS and dividend payout ratio )
  • Debt (total debt, total equity and cash & equivalents)
  • Returns (ROE, ROIC, ROA and R&D revenue to ratio)

. I recommend to just select one of them, in other case the chart is a mess.

Some screenshots

An example of the “Revenue & Earnings” chart (values in millions):

An example of “EPS & DPS” chart, than contains:

  • Earning per share basic
  • Earning estimate (so you can see if the met the target, passed or missed).
  • Dividend per share.
  • Dividend payout ratio.

An example of debt and equities (values in millions):

An example of what I have called “Returns”, that is ROE, ROIC, ROA and R&D revenue to ratio:

The code

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © @joapen www.joapen.com

//@version=4
study("P1 Fundamentals", shorttitle="Fundamentals", precision=6, overlay=false)
ZEROLINE = 0
MILLION = 1000000

// ---------- Inputs
output = input(defval="Per Share", title='Output type', options=["Per Share", "% of mcap", "Actual"])
// select data by fiscal quarter or by fiscal year
period = input(defval="FQ", title='Period', options=["FQ", "FY"])

// ---------- Variable initializations
// In case you want to add more data you can see all parameters available on the link below
// https://www.tradingview.com/pine-script-reference/v4/?solution=43000564727#fun_financial

// Revenue and Earnings
rev = financial(syminfo.tickerid, "TOTAL_REVENUE", period) / MILLION
op_income = financial(syminfo.tickerid, "OPER_INCOME", period) / MILLION
grossProfit = financial(syminfo.tickerid, "GROSS_PROFIT", period) / MILLION
ebitda = financial(syminfo.tickerid, "EBITDA", period) / MILLION
op_expenses = financial(syminfo.tickerid, "OPERATING_EXPENSES", period) / MILLION * -1
fcf = financial(syminfo.tickerid, "FREE_CASH_FLOW", period) / MILLION

// Show it? //
showR_E = input(true, title = "Show Revenue & Earnings?")
plot(showR_E?rev:na, title="Revenue", color=color.blue, linewidth=3, style=plot.style_area, transp=90)
plot(showR_E?rev:na, title="Revenue", color=color.purple, linewidth=3, style=plot.style_linebr)
plot(showR_E?grossProfit:na, title="Gross Profit", color=color.blue, linewidth=3, style=plot.style_linebr)
plot(showR_E?ebitda:na, title="EBITDA", color=color.aqua, linewidth=3, style=plot.style_linebr)
plot(showR_E?op_expenses:na, title="Operating Expenses", color=color.orange, linewidth=3, style=plot.style_linebr)
plot(showR_E?fcf:na, title="FCF", color=color.lime, linewidth=3, style=plot.style_linebr)

// EPS & DPS
eps = financial(syminfo.tickerid, "EARNINGS_PER_SHARE_BASIC", period) / MILLION
epsE = financial(syminfo.tickerid, "EARNINGS_ESTIMATE", period) / MILLION
dps = financial(syminfo.tickerid, "DPS_COMMON_STOCK_PRIM_ISSUE", period) / MILLION
dpayout = financial(syminfo.tickerid, "DIVIDEND_PAYOUT_RATIO", period) / 100

// Show it? //
showE_D = input(false, title = "Show EPS & DPS?")
plot(showE_D?eps:na, title="EPS", color=color.blue, linewidth=3, style=plot.style_linebr)
plot(showE_D?epsE:na, title="EPSE", color=color.teal, linewidth=1, style=plot.style_linebr)
plot(showE_D?dps:na, title="DPS", color=color.orange, linewidth=3, style=plot.style_linebr)
plot(showE_D?dpayout:na, title="Dividend payout ratio", color=color.red, linewidth=2, style=plot.style_linebr)

// Returns History and Analysis
roe = financial(syminfo.tickerid, "RETURN_ON_EQUITY", period) / 100
roic = financial(syminfo.tickerid, "RETURN_ON_INVESTED_CAPITAL", period) / 100
roa = financial(syminfo.tickerid, "RETURN_ON_ASSETS", period) / 100
RandDtoRevenueRatio = financial(syminfo.tickerid, "RESEARCH_AND_DEVELOP_TO_REVENUE", period) / 100

// Show it? then plot it //
showReturn = input(false, title = "Show Returns?")
plot(showReturn?roe:na, title="ROE", color=color.blue, linewidth=3, style=plot.style_linebr)
plot(showReturn?roic:na, title="ROIC", color=color.teal, linewidth=3, style=plot.style_linebr)
plot(showReturn?roa:na, title="ROA", color=color.purple, linewidth=3, style=plot.style_linebr)
plot(showReturn?RandDtoRevenueRatio:na, title="R&D revenue to ratio", color=color.green, linewidth=3, style=plot.style_linebr)
hline(showReturn?0.2:na, color=color.orange, linewidth=2)

hline(ZEROLINE)

I will do some other similar ones with: Basic EPS, data related to debt, and some data related to the balance sheet.

Any suggestion of improvement is welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *