Financial Fundamentals Labels for ThinkorSwim

@Pensar and everyone else Thanks for all the replies - I confirmed on the thinkScript lounge chat that stock functions ONLY work on certain charts, no where else in TOS

@halcyonguy , you’re right, the values don’t change often- I can easily copy the scan to excel and take it from there
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

This indicator displays fundamental data of a stock, including financial info such as Free Cash Flow, Profit Margin, etc., on your chart. Use on a Daily Chart. Useful for anyone interested in fundamental stock research.
AiGdPyb.png

Ruby:
#Fundamental Data Labels _Mobius 4/26/20 (found on OneNote)
#
# @MerryDay revised 4/21:
# my interpretation of positive/negative values; should be modified to meet your strategy
# then calculated an overall weighted score based on:
# https://tradestation.tradingappstore.com/products/FundamentalScore/document/Fundamental_Score.pdf
# and other information found on the web
declare lower;
declare hide_on_intraday;
input show_labels = yes ;
input show_summaries = no ;
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("Violet", CreateColor (200, 125, 255)) ;
DefineGlobalColor("GrayGreen",  CreateColor(155, 167, 76)) ;
DefineGlobalColor("LitePink", CreateColor (220, 180, 180)) ;
DefineGlobalColor("neutral",  color.light_gray) ;
def fp = FiscalPeriod.YEAR;
def EPS = EarningsPerShareTTM(fiscalPeriod = fp);
def PE = round(close / EPS,1);
AddLabel(show_labels and PE, "P/E ratio = " + Round(PE, 2),
                      if PE < 0 then GlobalColor("LitePink") else
                      if PE < 20 then GlobalColor("LabelGreen") else
                      if PE < 40 then GlobalColor("GrayGreen") else GlobalColor("Pre_Cyan"));

def EarnPerShare = if IsNaN(EarningsPerShareTTM())
                   then EarnPerShare[1]
                   else EarningsPerShareTTM();
AddLabel(show_labels and EarnPerShare, "EPS-TTM = " + AsDollars(EarnPerShare),
                      if EarnPerShare > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def FreeCashFlowPerSh = if isNaN(FreeCashFlowPerShare())
                        then FreeCashFlowPerSh[1]
                        else FreeCashFlowPerShare();
AddLabel(show_labels and FreeCashFlowPerSh, "Free Cash Flow Per Share = " + AsDollars(FreeCashFlowPerSh),
                  if FreeCashFlowPerSh > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_EarnCash = if PE <0 and FreeCashFlowPerSh < 0 and EarnPerShare < 0 then 0 else 5;

def Gross_Profit_Margin = if IsNaN(GrossProfitMargin())
                          then Gross_Profit_Margin[1]
                          else GrossProfitMargin();
AddLabel(show_labels and Gross_Profit_Margin, "Gross Profit Margin = " + Round(Gross_Profit_Margin, 2),
               if Gross_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Operating_Profit_Margin = if IsNaN(OperatingProfitMargin())
                              then Operating_Profit_Margin[1]
                              else OperatingProfitMargin();
AddLabel(show_labels and Operating_Profit_Margin, "Operating Profit Margin = " + Round(Operating_Profit_Margin, 2),              
              if Operating_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));


def Net_Profit_Margin = if IsNaN(NetProfitMargin())
                        then Net_Profit_Margin[1]
                        else NetProfitMargin();
AddLabel(show_labels and Net_Profit_Margin, "Net Profit Margin = " + Round(Net_Profit_Margin, 2),
               if Net_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Profits = if Gross_Profit_Margin>0 or Net_Profit_Margin>0 or Operating_Profit_Margin > 0 then 3 else 0 ;

def CurRatio = if IsNaN(CurrentRatio())
               then CurRatio[1]
               else CurrentRatio();
AddLabel(show_labels and CurRatio, "Current Ratio = " + Round(CurRatio, 2),
               if CurRatio > 2  then GlobalColor("GrayGreen") else
               if CurRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Quick_Ratio = if IsNaN(QuickRatio())
                  then Quick_Ratio[1]
                  else QuickRatio();
AddLabel(show_labels and Quick_Ratio, "Quick Ratio = " + Round(Quick_Ratio, 2),
               if Quick_Ratio > 2  then GlobalColor("GrayGreen") else
               if Quick_Ratio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Ratios = if Quick_Ratio >= 1 or CurRatio >= 1 then 3 else 0;

def Return_On_Assets = if IsNaN(ReturnOnAssets())
                       then Return_On_Assets[1]
                       else ReturnOnAssets();
AddLabel(show_labels and Return_On_Assets, "Return On Assets = " + Round(Return_On_Assets),
              if Return_On_Assets >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Assets >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Assets > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));


def Return_On_Equity = if IsNaN(ReturnOnEquity())
                       then Return_On_Equity[1]
                       else ReturnOnEquity();
AddLabel(show_labels and Return_On_Equity, "Return On Equity = " + Round(Return_On_Equity),
              if Return_On_Equity >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Equity >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Equity > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
def score_Returns = if Return_On_Equity >= 10 or Return_On_Assets >=10 then 1 else 0 ;


def Sales_Per_Share = if IsNaN(SalesPerShare())
                      then Sales_Per_Share[1]
                      else SalesPerShare();
AddLabel(show_labels and Sales_Per_Share, "Sales Per Share = " + Round(Sales_Per_Share, 2),
                      if Sales_Per_Share > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Sales_Per_Share = if Sales_Per_Share > 0 then 1 else 0;

def FixChgCovRatio = if IsNaN(FixedChargeCoverageRatio())
                     then FixChgCovRatio[1]
                     else FixedChargeCoverageRatio();
AddLabel(show_labels and FixChgCovRatio, "Fixed Charge Coverage Ratio = " + Round(FixChgCovRatio, 2),
                     if FixChgCovRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Total_Asset_Turnover = if IsNaN(TotalAssetTurnover())
                           then Total_Asset_Turnover[1]
                           else TotalAssetTurnover();
AddLabel(show_labels and Total_Asset_Turnover, "Total Asset Turnover = " + Round(Total_Asset_Turnover, 2),
               if Total_Asset_Turnover > 1 then GlobalColor("LabelGreen") else  GlobalColor("neutral"));

def FinLev = if IsNaN(FinancialLeverage())
             then FinLev[1]
             else FinancialLeverage();
AddLabel(show_labels and FinLev, "Financial Leverage = " + Round(FinLev, 2),
                      if FinLev > 0 and FinLev < 2 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_FinLev = if FinLev < 2 then 1 else 0;

def BookValue = if IsNaN(BookValuePerShare())
                then BookValue[1]
                else BookValuePerShare();
AddLabel(show_labels and BookValue, "Book Value Per Share = " + Round(BookValue),
                if BookValue < 2 then GlobalColor("Pre_Cyan") else
                if BookValue < 3 then GlobalColor("LabelGreen") else GlobalColor("neutral"));

def Long_Term_Debt_To_Capital = if IsNaN(LongTermDebtToCapital())
                                then Long_Term_Debt_To_Capital[1]
                                else LongTermDebtToCapital();
AddLabel(show_labels and Long_Term_Debt_To_Capital, "Long Term Debt To Capital = " + Round(Long_Term_Debt_To_Capital, 2),
 if Long_Term_Debt_To_Capital < 5 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Long_Term_Debt_To_Capital = if Long_Term_Debt_To_Capital < 5 then 1 else 0;

def Inventory_Turnover = if IsNaN(InventoryTurnover())
                         then Inventory_Turnover[1]
                         else InventoryTurnover();
AddLabel(show_labels and Inventory_Turnover, "Inventory Turnover = " + Round(Inventory_Turnover, 2),
               if Inventory_Turnover < 5  then GlobalColor("LitePink") else
               if Inventory_Turnover < 10 then GlobalColor("Pre_Cyan") else
               if Inventory_Turnover < 15 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));

def DivPayout = if IsNaN(DividendPayout())
                then DivPayout[1]
                else DividendPayout();
AddLabel(show_labels and DivPayout, "Dividend Payout = " + AsDollars(DivPayout), GlobalColor("neutral"));

def DivPerShare = if IsNaN(DividendsPerShareTTM())
                  then DivPerShare[1]
                  else DividendsPerShareTTM();
AddLabel(show_labels and DivPerShare, "Dividend Per Share = " + AsDollars(DivPerShare), GlobalColor("neutral"));

def Interest_Rate = if IsNaN(InterestRate())
                    then Interest_Rate[1]
                    else InterestRate();
AddLabel(show_labels and Interest_Rate, "Interest Rate = " + Round(Interest_Rate, 2), GlobalColor("neutral"));

def Tax_Rate = if IsNaN(TaxRate())
               then Tax_Rate[1]
               else TaxRate();
AddLabel(show_labels and Tax_Rate, "Tax Rate = " + Round(Tax_Rate, 2), GlobalColor("neutral"));

plot score = score_Returns + score_EarnCash + score_ratios + score_Profits
           + score_FinLev + score_Sales_Per_Share + score_Long_Term_Debt_To_Capital;
AddLabel(show_summaries, "SCORE: " + score,
if score >= 12 then GlobalColor("Pre_Cyan") else
if score >= 10 then GlobalColor("LabelGreen") else
if score >= 8 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
score.hide();

Link to shared study: http://tos.mx/zF4if7t
Thank you for this indicator of fundamental metrics. I can see it being very useful. Yet I am wondering if there is a way to plot each of these as a lower study, then you would easily be able to back test the metrics on a chart?
 
This indicator displays fundamental data of a stock, including financial info such as Free Cash Flow, Profit Margin, etc., on your chart. Use on a Daily Chart. Useful for anyone interested in fundamental stock research.
AiGdPyb.png

Ruby:
#Fundamental Data Labels _Mobius 4/26/20 (found on OneNote)
#
# @MerryDay revised 4/21:
# my interpretation of positive/negative values; should be modified to meet your strategy
# then calculated an overall weighted score based on:
# https://tradestation.tradingappstore.com/products/FundamentalScore/document/Fundamental_Score.pdf
# and other information found on the web
declare lower;
declare hide_on_intraday;
input show_labels = yes ;
input show_summaries = no ;
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("Violet", CreateColor (200, 125, 255)) ;
DefineGlobalColor("GrayGreen",  CreateColor(155, 167, 76)) ;
DefineGlobalColor("LitePink", CreateColor (220, 180, 180)) ;
DefineGlobalColor("neutral",  color.light_gray) ;
def fp = FiscalPeriod.YEAR;
def EPS = EarningsPerShareTTM(fiscalPeriod = fp);
def PE = round(close / EPS,1);
AddLabel(show_labels and PE, "P/E ratio = " + Round(PE, 2),
                      if PE < 0 then GlobalColor("LitePink") else
                      if PE < 20 then GlobalColor("LabelGreen") else
                      if PE < 40 then GlobalColor("GrayGreen") else GlobalColor("Pre_Cyan"));

def EarnPerShare = if IsNaN(EarningsPerShareTTM())
                   then EarnPerShare[1]
                   else EarningsPerShareTTM();
AddLabel(show_labels and EarnPerShare, "EPS-TTM = " + AsDollars(EarnPerShare),
                      if EarnPerShare > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def FreeCashFlowPerSh = if isNaN(FreeCashFlowPerShare())
                        then FreeCashFlowPerSh[1]
                        else FreeCashFlowPerShare();
AddLabel(show_labels and FreeCashFlowPerSh, "Free Cash Flow Per Share = " + AsDollars(FreeCashFlowPerSh),
                  if FreeCashFlowPerSh > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_EarnCash = if PE <0 and FreeCashFlowPerSh < 0 and EarnPerShare < 0 then 0 else 5;

def Gross_Profit_Margin = if IsNaN(GrossProfitMargin())
                          then Gross_Profit_Margin[1]
                          else GrossProfitMargin();
AddLabel(show_labels and Gross_Profit_Margin, "Gross Profit Margin = " + Round(Gross_Profit_Margin, 2),
               if Gross_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Operating_Profit_Margin = if IsNaN(OperatingProfitMargin())
                              then Operating_Profit_Margin[1]
                              else OperatingProfitMargin();
AddLabel(show_labels and Operating_Profit_Margin, "Operating Profit Margin = " + Round(Operating_Profit_Margin, 2),              
              if Operating_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));


def Net_Profit_Margin = if IsNaN(NetProfitMargin())
                        then Net_Profit_Margin[1]
                        else NetProfitMargin();
AddLabel(show_labels and Net_Profit_Margin, "Net Profit Margin = " + Round(Net_Profit_Margin, 2),
               if Net_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Profits = if Gross_Profit_Margin>0 or Net_Profit_Margin>0 or Operating_Profit_Margin > 0 then 3 else 0 ;

def CurRatio = if IsNaN(CurrentRatio())
               then CurRatio[1]
               else CurrentRatio();
AddLabel(show_labels and CurRatio, "Current Ratio = " + Round(CurRatio, 2),
               if CurRatio > 2  then GlobalColor("GrayGreen") else
               if CurRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Quick_Ratio = if IsNaN(QuickRatio())
                  then Quick_Ratio[1]
                  else QuickRatio();
AddLabel(show_labels and Quick_Ratio, "Quick Ratio = " + Round(Quick_Ratio, 2),
               if Quick_Ratio > 2  then GlobalColor("GrayGreen") else
               if Quick_Ratio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Ratios = if Quick_Ratio >= 1 or CurRatio >= 1 then 3 else 0;

def Return_On_Assets = if IsNaN(ReturnOnAssets())
                       then Return_On_Assets[1]
                       else ReturnOnAssets();
AddLabel(show_labels and Return_On_Assets, "Return On Assets = " + Round(Return_On_Assets),
              if Return_On_Assets >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Assets >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Assets > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));


def Return_On_Equity = if IsNaN(ReturnOnEquity())
                       then Return_On_Equity[1]
                       else ReturnOnEquity();
AddLabel(show_labels and Return_On_Equity, "Return On Equity = " + Round(Return_On_Equity),
              if Return_On_Equity >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Equity >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Equity > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
def score_Returns = if Return_On_Equity >= 10 or Return_On_Assets >=10 then 1 else 0 ;


def Sales_Per_Share = if IsNaN(SalesPerShare())
                      then Sales_Per_Share[1]
                      else SalesPerShare();
AddLabel(show_labels and Sales_Per_Share, "Sales Per Share = " + Round(Sales_Per_Share, 2),
                      if Sales_Per_Share > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Sales_Per_Share = if Sales_Per_Share > 0 then 1 else 0;

def FixChgCovRatio = if IsNaN(FixedChargeCoverageRatio())
                     then FixChgCovRatio[1]
                     else FixedChargeCoverageRatio();
AddLabel(show_labels and FixChgCovRatio, "Fixed Charge Coverage Ratio = " + Round(FixChgCovRatio, 2),
                     if FixChgCovRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Total_Asset_Turnover = if IsNaN(TotalAssetTurnover())
                           then Total_Asset_Turnover[1]
                           else TotalAssetTurnover();
AddLabel(show_labels and Total_Asset_Turnover, "Total Asset Turnover = " + Round(Total_Asset_Turnover, 2),
               if Total_Asset_Turnover > 1 then GlobalColor("LabelGreen") else  GlobalColor("neutral"));

def FinLev = if IsNaN(FinancialLeverage())
             then FinLev[1]
             else FinancialLeverage();
AddLabel(show_labels and FinLev, "Financial Leverage = " + Round(FinLev, 2),
                      if FinLev > 0 and FinLev < 2 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_FinLev = if FinLev < 2 then 1 else 0;

def BookValue = if IsNaN(BookValuePerShare())
                then BookValue[1]
                else BookValuePerShare();
AddLabel(show_labels and BookValue, "Book Value Per Share = " + Round(BookValue),
                if BookValue < 2 then GlobalColor("Pre_Cyan") else
                if BookValue < 3 then GlobalColor("LabelGreen") else GlobalColor("neutral"));

def Long_Term_Debt_To_Capital = if IsNaN(LongTermDebtToCapital())
                                then Long_Term_Debt_To_Capital[1]
                                else LongTermDebtToCapital();
AddLabel(show_labels and Long_Term_Debt_To_Capital, "Long Term Debt To Capital = " + Round(Long_Term_Debt_To_Capital, 2),
 if Long_Term_Debt_To_Capital < 5 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Long_Term_Debt_To_Capital = if Long_Term_Debt_To_Capital < 5 then 1 else 0;

def Inventory_Turnover = if IsNaN(InventoryTurnover())
                         then Inventory_Turnover[1]
                         else InventoryTurnover();
AddLabel(show_labels and Inventory_Turnover, "Inventory Turnover = " + Round(Inventory_Turnover, 2),
               if Inventory_Turnover < 5  then GlobalColor("LitePink") else
               if Inventory_Turnover < 10 then GlobalColor("Pre_Cyan") else
               if Inventory_Turnover < 15 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));

def DivPayout = if IsNaN(DividendPayout())
                then DivPayout[1]
                else DividendPayout();
AddLabel(show_labels and DivPayout, "Dividend Payout = " + AsDollars(DivPayout), GlobalColor("neutral"));

def DivPerShare = if IsNaN(DividendsPerShareTTM())
                  then DivPerShare[1]
                  else DividendsPerShareTTM();
AddLabel(show_labels and DivPerShare, "Dividend Per Share = " + AsDollars(DivPerShare), GlobalColor("neutral"));

def Interest_Rate = if IsNaN(InterestRate())
                    then Interest_Rate[1]
                    else InterestRate();
AddLabel(show_labels and Interest_Rate, "Interest Rate = " + Round(Interest_Rate, 2), GlobalColor("neutral"));

def Tax_Rate = if IsNaN(TaxRate())
               then Tax_Rate[1]
               else TaxRate();
AddLabel(show_labels and Tax_Rate, "Tax Rate = " + Round(Tax_Rate, 2), GlobalColor("neutral"));

plot score = score_Returns + score_EarnCash + score_ratios + score_Profits
           + score_FinLev + score_Sales_Per_Share + score_Long_Term_Debt_To_Capital;
AddLabel(show_summaries, "SCORE: " + score,
if score >= 12 then GlobalColor("Pre_Cyan") else
if score >= 10 then GlobalColor("LabelGreen") else
if score >= 8 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
score.hide();

Link to shared study: http://tos.mx/zF4if7t
Any way to add the Short Interest?
 
This indicator displays fundamental data of a stock, including financial info such as Free Cash Flow, Profit Margin, etc., on your chart. Use on a Daily Chart. Useful for anyone interested in fundamental stock research.
AiGdPyb.png

Ruby:
#Fundamental Data Labels _Mobius 4/26/20 (found on OneNote)
#
# @MerryDay revised 4/21:
# my interpretation of positive/negative values; should be modified to meet your strategy
# then calculated an overall weighted score based on:
# https://tradestation.tradingappstore.com/products/FundamentalScore/document/Fundamental_Score.pdf
# and other information found on the web
declare lower;
declare hide_on_intraday;
input show_labels = yes ;
input show_summaries = no ;
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("Violet", CreateColor (200, 125, 255)) ;
DefineGlobalColor("GrayGreen",  CreateColor(155, 167, 76)) ;
DefineGlobalColor("LitePink", CreateColor (220, 180, 180)) ;
DefineGlobalColor("neutral",  color.light_gray) ;
def fp = FiscalPeriod.YEAR;
def EPS = EarningsPerShareTTM(fiscalPeriod = fp);
def PE = round(close / EPS,1);
AddLabel(show_labels and PE, "P/E ratio = " + Round(PE, 2),
                      if PE < 0 then GlobalColor("LitePink") else
                      if PE < 20 then GlobalColor("LabelGreen") else
                      if PE < 40 then GlobalColor("GrayGreen") else GlobalColor("Pre_Cyan"));

def EarnPerShare = if IsNaN(EarningsPerShareTTM())
                   then EarnPerShare[1]
                   else EarningsPerShareTTM();
AddLabel(show_labels and EarnPerShare, "EPS-TTM = " + AsDollars(EarnPerShare),
                      if EarnPerShare > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def FreeCashFlowPerSh = if isNaN(FreeCashFlowPerShare())
                        then FreeCashFlowPerSh[1]
                        else FreeCashFlowPerShare();
AddLabel(show_labels and FreeCashFlowPerSh, "Free Cash Flow Per Share = " + AsDollars(FreeCashFlowPerSh),
                  if FreeCashFlowPerSh > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_EarnCash = if PE <0 and FreeCashFlowPerSh < 0 and EarnPerShare < 0 then 0 else 5;

def Gross_Profit_Margin = if IsNaN(GrossProfitMargin())
                          then Gross_Profit_Margin[1]
                          else GrossProfitMargin();
AddLabel(show_labels and Gross_Profit_Margin, "Gross Profit Margin = " + Round(Gross_Profit_Margin, 2),
               if Gross_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Operating_Profit_Margin = if IsNaN(OperatingProfitMargin())
                              then Operating_Profit_Margin[1]
                              else OperatingProfitMargin();
AddLabel(show_labels and Operating_Profit_Margin, "Operating Profit Margin = " + Round(Operating_Profit_Margin, 2),              
              if Operating_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));


def Net_Profit_Margin = if IsNaN(NetProfitMargin())
                        then Net_Profit_Margin[1]
                        else NetProfitMargin();
AddLabel(show_labels and Net_Profit_Margin, "Net Profit Margin = " + Round(Net_Profit_Margin, 2),
               if Net_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Profits = if Gross_Profit_Margin>0 or Net_Profit_Margin>0 or Operating_Profit_Margin > 0 then 3 else 0 ;

def CurRatio = if IsNaN(CurrentRatio())
               then CurRatio[1]
               else CurrentRatio();
AddLabel(show_labels and CurRatio, "Current Ratio = " + Round(CurRatio, 2),
               if CurRatio > 2  then GlobalColor("GrayGreen") else
               if CurRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Quick_Ratio = if IsNaN(QuickRatio())
                  then Quick_Ratio[1]
                  else QuickRatio();
AddLabel(show_labels and Quick_Ratio, "Quick Ratio = " + Round(Quick_Ratio, 2),
               if Quick_Ratio > 2  then GlobalColor("GrayGreen") else
               if Quick_Ratio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Ratios = if Quick_Ratio >= 1 or CurRatio >= 1 then 3 else 0;

def Return_On_Assets = if IsNaN(ReturnOnAssets())
                       then Return_On_Assets[1]
                       else ReturnOnAssets();
AddLabel(show_labels and Return_On_Assets, "Return On Assets = " + Round(Return_On_Assets),
              if Return_On_Assets >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Assets >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Assets > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));


def Return_On_Equity = if IsNaN(ReturnOnEquity())
                       then Return_On_Equity[1]
                       else ReturnOnEquity();
AddLabel(show_labels and Return_On_Equity, "Return On Equity = " + Round(Return_On_Equity),
              if Return_On_Equity >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Equity >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Equity > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
def score_Returns = if Return_On_Equity >= 10 or Return_On_Assets >=10 then 1 else 0 ;


def Sales_Per_Share = if IsNaN(SalesPerShare())
                      then Sales_Per_Share[1]
                      else SalesPerShare();
AddLabel(show_labels and Sales_Per_Share, "Sales Per Share = " + Round(Sales_Per_Share, 2),
                      if Sales_Per_Share > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Sales_Per_Share = if Sales_Per_Share > 0 then 1 else 0;

def FixChgCovRatio = if IsNaN(FixedChargeCoverageRatio())
                     then FixChgCovRatio[1]
                     else FixedChargeCoverageRatio();
AddLabel(show_labels and FixChgCovRatio, "Fixed Charge Coverage Ratio = " + Round(FixChgCovRatio, 2),
                     if FixChgCovRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Total_Asset_Turnover = if IsNaN(TotalAssetTurnover())
                           then Total_Asset_Turnover[1]
                           else TotalAssetTurnover();
AddLabel(show_labels and Total_Asset_Turnover, "Total Asset Turnover = " + Round(Total_Asset_Turnover, 2),
               if Total_Asset_Turnover > 1 then GlobalColor("LabelGreen") else  GlobalColor("neutral"));

def FinLev = if IsNaN(FinancialLeverage())
             then FinLev[1]
             else FinancialLeverage();
AddLabel(show_labels and FinLev, "Financial Leverage = " + Round(FinLev, 2),
                      if FinLev > 0 and FinLev < 2 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_FinLev = if FinLev < 2 then 1 else 0;

def BookValue = if IsNaN(BookValuePerShare())
                then BookValue[1]
                else BookValuePerShare();
AddLabel(show_labels and BookValue, "Book Value Per Share = " + Round(BookValue),
                if BookValue < 2 then GlobalColor("Pre_Cyan") else
                if BookValue < 3 then GlobalColor("LabelGreen") else GlobalColor("neutral"));

def Long_Term_Debt_To_Capital = if IsNaN(LongTermDebtToCapital())
                                then Long_Term_Debt_To_Capital[1]
                                else LongTermDebtToCapital();
AddLabel(show_labels and Long_Term_Debt_To_Capital, "Long Term Debt To Capital = " + Round(Long_Term_Debt_To_Capital, 2),
 if Long_Term_Debt_To_Capital < 5 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Long_Term_Debt_To_Capital = if Long_Term_Debt_To_Capital < 5 then 1 else 0;

def Inventory_Turnover = if IsNaN(InventoryTurnover())
                         then Inventory_Turnover[1]
                         else InventoryTurnover();
AddLabel(show_labels and Inventory_Turnover, "Inventory Turnover = " + Round(Inventory_Turnover, 2),
               if Inventory_Turnover < 5  then GlobalColor("LitePink") else
               if Inventory_Turnover < 10 then GlobalColor("Pre_Cyan") else
               if Inventory_Turnover < 15 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));

def DivPayout = if IsNaN(DividendPayout())
                then DivPayout[1]
                else DividendPayout();
AddLabel(show_labels and DivPayout, "Dividend Payout = " + AsDollars(DivPayout), GlobalColor("neutral"));

def DivPerShare = if IsNaN(DividendsPerShareTTM())
                  then DivPerShare[1]
                  else DividendsPerShareTTM();
AddLabel(show_labels and DivPerShare, "Dividend Per Share = " + AsDollars(DivPerShare), GlobalColor("neutral"));

def Interest_Rate = if IsNaN(InterestRate())
                    then Interest_Rate[1]
                    else InterestRate();
AddLabel(show_labels and Interest_Rate, "Interest Rate = " + Round(Interest_Rate, 2), GlobalColor("neutral"));

def Tax_Rate = if IsNaN(TaxRate())
               then Tax_Rate[1]
               else TaxRate();
AddLabel(show_labels and Tax_Rate, "Tax Rate = " + Round(Tax_Rate, 2), GlobalColor("neutral"));

plot score = score_Returns + score_EarnCash + score_ratios + score_Profits
           + score_FinLev + score_Sales_Per_Share + score_Long_Term_Debt_To_Capital;
AddLabel(show_summaries, "SCORE: " + score,
if score >= 12 then GlobalColor("Pre_Cyan") else
if score >= 10 then GlobalColor("LabelGreen") else
if score >= 8 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
score.hide();

Link to shared study: http://tos.mx/zF4if7t
Can you please provide scripts for PEG data in thinkorswim. Basically , I want to include PEG label in the above codes. Thanks
 
@majidg TOS platform does not provide the data necessary to calculate the PEG.
 
Last edited:
This is pretty neat!
I'm considering an attempt at converting all the values into percentages and plotting a line graph in a lower study to use as a technical indicator. Is this idea worth the effort?
 
Complete newbie to thinkscript. Can anyone tell me how I can get the following script to work. Struggling with the SalesPerShare stock fundamental function (no such variable error). I want to add this script to a new marketwatch column. Basically all I want to do is divide the SalesPerShare value by the last share price. Thanks!

declare lower;
def rev_per_share = SalesPerShare / close;
AddLabel (yes, "" + Round(rev_per_share,3), if rev_per_share > 0 then Color.Green else Color.Red);
 
hello. there are a couple things to change in your code.
...not sure what you want to see by using this , in addlabel
, "" +
but it won't display anything. maybe this is what you want?
, "rev/share " +

...SalesPerShare() needs the () at the end.

...SalesPerShare() data does not exist on every candle. it shows up on 1 candle, once a year. so you need a way to keep the value after finding it.

take a look at this study. it displays several fundamental parameters of a stock.
https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/

this formula reads SalesPerShare() data.
if it finds data that isn't an error, it puts the value into x. if SalesPerShare() is an error, then x is equal the previous candle value of x. this is how to pass a value from one candle to the next, by using an offset of [1], to look at the previous candle.

def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare();
 
hello. there are a couple things to change in your code.
...not sure what you want to see by using this , in addlabel
, "" +
but it won't display anything. maybe this is what you want?
, "rev/share " +

...SalesPerShare() needs the () at the end.

...SalesPerShare() data does not exist on every candle. it shows up on 1 candle, once a year. so you need a way to keep the value after finding it.

take a look at this study. it displays several fundamental parameters of a stock.
https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/

this formula reads SalesPerShare() data.
if it finds data that isn't an error, it puts the value into x. if SalesPerShare() is an error, then x is equal the previous candle value of x. this is how to pass a value from one candle to the next, by using an offset of [1], to look at the previous candle.

def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare();

Hi @halcyonguy , thanks for your reply and help, much appreciated.

I am trying to add scripts to personalize the marketwatch tab. I've left the "" in the addlabel instruction so that I only see the value in the marketwatch column and not the label as well which takes up too much space.

Also, by adding the script, I can reduce the decimals and color code to make it easier to visualise.

Unfortunately, adding the () at the end of SalesPerShare still gives me an error message (invalid symbol in Stock Fundamentals function):

declare lower;
def rev_per_share = SalesPerShare() / close;
AddLabel (yes, "" + Round(rev_per_share,3), if rev_per_share > 0 then Color.Green else Color.Red);


I can see the SalesPerShare values for each ticker symbol so I know the function is pulling information.

Here is a screenshot of what I am trying to achieve (hope this works):
nqEM91y.png
 
This indicator displays fundamental data of a stock, including financial info such as Free Cash Flow, Profit Margin, etc., on your chart. Use on a Daily Chart. Useful for anyone interested in fundamental stock research.
AiGdPyb.png

Ruby:
#Fundamental Data Labels _Mobius 4/26/20 (found on OneNote)
#
# @MerryDay revised 4/21:
# my interpretation of positive/negative values; should be modified to meet your strategy
# then calculated an overall weighted score based on:
# https://tradestation.tradingappstore.com/products/FundamentalScore/document/Fundamental_Score.pdf
# and other information found on the web
declare lower;
declare hide_on_intraday;
input show_labels = yes ;
input show_summaries = no ;
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("Violet", CreateColor (200, 125, 255)) ;
DefineGlobalColor("GrayGreen",  CreateColor(155, 167, 76)) ;
DefineGlobalColor("LitePink", CreateColor (220, 180, 180)) ;
DefineGlobalColor("neutral",  color.light_gray) ;
def fp = FiscalPeriod.YEAR;
def EPS = EarningsPerShareTTM(fiscalPeriod = fp);
def PE = round(close / EPS,1);
AddLabel(show_labels and PE, "P/E ratio = " + Round(PE, 2),
                      if PE < 0 then GlobalColor("LitePink") else
                      if PE < 20 then GlobalColor("LabelGreen") else
                      if PE < 40 then GlobalColor("GrayGreen") else GlobalColor("Pre_Cyan"));

def EarnPerShare = if IsNaN(EarningsPerShareTTM())
                   then EarnPerShare[1]
                   else EarningsPerShareTTM();
AddLabel(show_labels and EarnPerShare, "EPS-TTM = " + AsDollars(EarnPerShare),
                      if EarnPerShare > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def FreeCashFlowPerSh = if isNaN(FreeCashFlowPerShare())
                        then FreeCashFlowPerSh[1]
                        else FreeCashFlowPerShare();
AddLabel(show_labels and FreeCashFlowPerSh, "Free Cash Flow Per Share = " + AsDollars(FreeCashFlowPerSh),
                  if FreeCashFlowPerSh > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_EarnCash = if PE <0 and FreeCashFlowPerSh < 0 and EarnPerShare < 0 then 0 else 5;

def Gross_Profit_Margin = if IsNaN(GrossProfitMargin())
                          then Gross_Profit_Margin[1]
                          else GrossProfitMargin();
AddLabel(show_labels and Gross_Profit_Margin, "Gross Profit Margin = " + Round(Gross_Profit_Margin, 2),
               if Gross_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Operating_Profit_Margin = if IsNaN(OperatingProfitMargin())
                              then Operating_Profit_Margin[1]
                              else OperatingProfitMargin();
AddLabel(show_labels and Operating_Profit_Margin, "Operating Profit Margin = " + Round(Operating_Profit_Margin, 2),              
              if Operating_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));


def Net_Profit_Margin = if IsNaN(NetProfitMargin())
                        then Net_Profit_Margin[1]
                        else NetProfitMargin();
AddLabel(show_labels and Net_Profit_Margin, "Net Profit Margin = " + Round(Net_Profit_Margin, 2),
               if Net_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Profits = if Gross_Profit_Margin>0 or Net_Profit_Margin>0 or Operating_Profit_Margin > 0 then 3 else 0 ;

def CurRatio = if IsNaN(CurrentRatio())
               then CurRatio[1]
               else CurrentRatio();
AddLabel(show_labels and CurRatio, "Current Ratio = " + Round(CurRatio, 2),
               if CurRatio > 2  then GlobalColor("GrayGreen") else
               if CurRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Quick_Ratio = if IsNaN(QuickRatio())
                  then Quick_Ratio[1]
                  else QuickRatio();
AddLabel(show_labels and Quick_Ratio, "Quick Ratio = " + Round(Quick_Ratio, 2),
               if Quick_Ratio > 2  then GlobalColor("GrayGreen") else
               if Quick_Ratio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Ratios = if Quick_Ratio >= 1 or CurRatio >= 1 then 3 else 0;

def Return_On_Assets = if IsNaN(ReturnOnAssets())
                       then Return_On_Assets[1]
                       else ReturnOnAssets();
AddLabel(show_labels and Return_On_Assets, "Return On Assets = " + Round(Return_On_Assets),
              if Return_On_Assets >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Assets >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Assets > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));


def Return_On_Equity = if IsNaN(ReturnOnEquity())
                       then Return_On_Equity[1]
                       else ReturnOnEquity();
AddLabel(show_labels and Return_On_Equity, "Return On Equity = " + Round(Return_On_Equity),
              if Return_On_Equity >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Equity >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Equity > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
def score_Returns = if Return_On_Equity >= 10 or Return_On_Assets >=10 then 1 else 0 ;


def Sales_Per_Share = if IsNaN(SalesPerShare())
                      then Sales_Per_Share[1]
                      else SalesPerShare();
AddLabel(show_labels and Sales_Per_Share, "Sales Per Share = " + Round(Sales_Per_Share, 2),
                      if Sales_Per_Share > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Sales_Per_Share = if Sales_Per_Share > 0 then 1 else 0;

def FixChgCovRatio = if IsNaN(FixedChargeCoverageRatio())
                     then FixChgCovRatio[1]
                     else FixedChargeCoverageRatio();
AddLabel(show_labels and FixChgCovRatio, "Fixed Charge Coverage Ratio = " + Round(FixChgCovRatio, 2),
                     if FixChgCovRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Total_Asset_Turnover = if IsNaN(TotalAssetTurnover())
                           then Total_Asset_Turnover[1]
                           else TotalAssetTurnover();
AddLabel(show_labels and Total_Asset_Turnover, "Total Asset Turnover = " + Round(Total_Asset_Turnover, 2),
               if Total_Asset_Turnover > 1 then GlobalColor("LabelGreen") else  GlobalColor("neutral"));

def FinLev = if IsNaN(FinancialLeverage())
             then FinLev[1]
             else FinancialLeverage();
AddLabel(show_labels and FinLev, "Financial Leverage = " + Round(FinLev, 2),
                      if FinLev > 0 and FinLev < 2 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_FinLev = if FinLev < 2 then 1 else 0;

def BookValue = if IsNaN(BookValuePerShare())
                then BookValue[1]
                else BookValuePerShare();
AddLabel(show_labels and BookValue, "Book Value Per Share = " + Round(BookValue),
                if BookValue < 2 then GlobalColor("Pre_Cyan") else
                if BookValue < 3 then GlobalColor("LabelGreen") else GlobalColor("neutral"));

def Long_Term_Debt_To_Capital = if IsNaN(LongTermDebtToCapital())
                                then Long_Term_Debt_To_Capital[1]
                                else LongTermDebtToCapital();
AddLabel(show_labels and Long_Term_Debt_To_Capital, "Long Term Debt To Capital = " + Round(Long_Term_Debt_To_Capital, 2),
 if Long_Term_Debt_To_Capital < 5 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Long_Term_Debt_To_Capital = if Long_Term_Debt_To_Capital < 5 then 1 else 0;

def Inventory_Turnover = if IsNaN(InventoryTurnover())
                         then Inventory_Turnover[1]
                         else InventoryTurnover();
AddLabel(show_labels and Inventory_Turnover, "Inventory Turnover = " + Round(Inventory_Turnover, 2),
               if Inventory_Turnover < 5  then GlobalColor("LitePink") else
               if Inventory_Turnover < 10 then GlobalColor("Pre_Cyan") else
               if Inventory_Turnover < 15 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));

def DivPayout = if IsNaN(DividendPayout())
                then DivPayout[1]
                else DividendPayout();
AddLabel(show_labels and DivPayout, "Dividend Payout = " + AsDollars(DivPayout), GlobalColor("neutral"));

def DivPerShare = if IsNaN(DividendsPerShareTTM())
                  then DivPerShare[1]
                  else DividendsPerShareTTM();
AddLabel(show_labels and DivPerShare, "Dividend Per Share = " + AsDollars(DivPerShare), GlobalColor("neutral"));

def Interest_Rate = if IsNaN(InterestRate())
                    then Interest_Rate[1]
                    else InterestRate();
AddLabel(show_labels and Interest_Rate, "Interest Rate = " + Round(Interest_Rate, 2), GlobalColor("neutral"));

def Tax_Rate = if IsNaN(TaxRate())
               then Tax_Rate[1]
               else TaxRate();
AddLabel(show_labels and Tax_Rate, "Tax Rate = " + Round(Tax_Rate, 2), GlobalColor("neutral"));

plot score = score_Returns + score_EarnCash + score_ratios + score_Profits
           + score_FinLev + score_Sales_Per_Share + score_Long_Term_Debt_To_Capital;
AddLabel(show_summaries, "SCORE: " + score,
if score >= 12 then GlobalColor("Pre_Cyan") else
if score >= 10 then GlobalColor("LabelGreen") else
if score >= 8 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
score.hide();

Link to shared study: http://tos.mx/zF4if7t
Hi so just to confirm the higher the score and more green labels the better right?
 
This indicator displays fundamental data of a stock, including financial info such as Free Cash Flow, Profit Margin, etc., on your chart. Use on a Daily Chart. Useful for anyone interested in fundamental stock research.
AiGdPyb.png

Ruby:
#Fundamental Data Labels _Mobius 4/26/20 (found on OneNote)
#
# @MerryDay revised 4/21:
# my interpretation of positive/negative values; should be modified to meet your strategy
# then calculated an overall weighted score based on:
# https://tradestation.tradingappstore.com/products/FundamentalScore/document/Fundamental_Score.pdf
# and other information found on the web
declare lower;
declare hide_on_intraday;
input show_labels = yes ;
input show_summaries = no ;
DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("Violet", CreateColor (200, 125, 255)) ;
DefineGlobalColor("GrayGreen",  CreateColor(155, 167, 76)) ;
DefineGlobalColor("LitePink", CreateColor (220, 180, 180)) ;
DefineGlobalColor("neutral",  color.light_gray) ;
def fp = FiscalPeriod.YEAR;
def EPS = EarningsPerShareTTM(fiscalPeriod = fp);
def PE = round(close / EPS,1);
AddLabel(show_labels and PE, "P/E ratio = " + Round(PE, 2),
                      if PE < 0 then GlobalColor("LitePink") else
                      if PE < 20 then GlobalColor("LabelGreen") else
                      if PE < 40 then GlobalColor("GrayGreen") else GlobalColor("Pre_Cyan"));

def EarnPerShare = if IsNaN(EarningsPerShareTTM())
                   then EarnPerShare[1]
                   else EarningsPerShareTTM();
AddLabel(show_labels and EarnPerShare, "EPS-TTM = " + AsDollars(EarnPerShare),
                      if EarnPerShare > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def FreeCashFlowPerSh = if isNaN(FreeCashFlowPerShare())
                        then FreeCashFlowPerSh[1]
                        else FreeCashFlowPerShare();
AddLabel(show_labels and FreeCashFlowPerSh, "Free Cash Flow Per Share = " + AsDollars(FreeCashFlowPerSh),
                  if FreeCashFlowPerSh > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_EarnCash = if PE <0 and FreeCashFlowPerSh < 0 and EarnPerShare < 0 then 0 else 5;

def Gross_Profit_Margin = if IsNaN(GrossProfitMargin())
                          then Gross_Profit_Margin[1]
                          else GrossProfitMargin();
AddLabel(show_labels and Gross_Profit_Margin, "Gross Profit Margin = " + Round(Gross_Profit_Margin, 2),
               if Gross_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Operating_Profit_Margin = if IsNaN(OperatingProfitMargin())
                              then Operating_Profit_Margin[1]
                              else OperatingProfitMargin();
AddLabel(show_labels and Operating_Profit_Margin, "Operating Profit Margin = " + Round(Operating_Profit_Margin, 2),              
              if Operating_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));


def Net_Profit_Margin = if IsNaN(NetProfitMargin())
                        then Net_Profit_Margin[1]
                        else NetProfitMargin();
AddLabel(show_labels and Net_Profit_Margin, "Net Profit Margin = " + Round(Net_Profit_Margin, 2),
               if Net_Profit_Margin > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Profits = if Gross_Profit_Margin>0 or Net_Profit_Margin>0 or Operating_Profit_Margin > 0 then 3 else 0 ;

def CurRatio = if IsNaN(CurrentRatio())
               then CurRatio[1]
               else CurrentRatio();
AddLabel(show_labels and CurRatio, "Current Ratio = " + Round(CurRatio, 2),
               if CurRatio > 2  then GlobalColor("GrayGreen") else
               if CurRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Quick_Ratio = if IsNaN(QuickRatio())
                  then Quick_Ratio[1]
                  else QuickRatio();
AddLabel(show_labels and Quick_Ratio, "Quick Ratio = " + Round(Quick_Ratio, 2),
               if Quick_Ratio > 2  then GlobalColor("GrayGreen") else
               if Quick_Ratio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Ratios = if Quick_Ratio >= 1 or CurRatio >= 1 then 3 else 0;

def Return_On_Assets = if IsNaN(ReturnOnAssets())
                       then Return_On_Assets[1]
                       else ReturnOnAssets();
AddLabel(show_labels and Return_On_Assets, "Return On Assets = " + Round(Return_On_Assets),
              if Return_On_Assets >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Assets >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Assets > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));


def Return_On_Equity = if IsNaN(ReturnOnEquity())
                       then Return_On_Equity[1]
                       else ReturnOnEquity();
AddLabel(show_labels and Return_On_Equity, "Return On Equity = " + Round(Return_On_Equity),
              if Return_On_Equity >= 15 then GlobalColor("Pre_Cyan") else
              if Return_On_Equity >= 10 then GlobalColor("LabelGreen") else
              if Return_On_Equity > 0 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
def score_Returns = if Return_On_Equity >= 10 or Return_On_Assets >=10 then 1 else 0 ;


def Sales_Per_Share = if IsNaN(SalesPerShare())
                      then Sales_Per_Share[1]
                      else SalesPerShare();
AddLabel(show_labels and Sales_Per_Share, "Sales Per Share = " + Round(Sales_Per_Share, 2),
                      if Sales_Per_Share > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Sales_Per_Share = if Sales_Per_Share > 0 then 1 else 0;

def FixChgCovRatio = if IsNaN(FixedChargeCoverageRatio())
                     then FixChgCovRatio[1]
                     else FixedChargeCoverageRatio();
AddLabel(show_labels and FixChgCovRatio, "Fixed Charge Coverage Ratio = " + Round(FixChgCovRatio, 2),
                     if FixChgCovRatio >= 1 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));

def Total_Asset_Turnover = if IsNaN(TotalAssetTurnover())
                           then Total_Asset_Turnover[1]
                           else TotalAssetTurnover();
AddLabel(show_labels and Total_Asset_Turnover, "Total Asset Turnover = " + Round(Total_Asset_Turnover, 2),
               if Total_Asset_Turnover > 1 then GlobalColor("LabelGreen") else  GlobalColor("neutral"));

def FinLev = if IsNaN(FinancialLeverage())
             then FinLev[1]
             else FinancialLeverage();
AddLabel(show_labels and FinLev, "Financial Leverage = " + Round(FinLev, 2),
                      if FinLev > 0 and FinLev < 2 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_FinLev = if FinLev < 2 then 1 else 0;

def BookValue = if IsNaN(BookValuePerShare())
                then BookValue[1]
                else BookValuePerShare();
AddLabel(show_labels and BookValue, "Book Value Per Share = " + Round(BookValue),
                if BookValue < 2 then GlobalColor("Pre_Cyan") else
                if BookValue < 3 then GlobalColor("LabelGreen") else GlobalColor("neutral"));

def Long_Term_Debt_To_Capital = if IsNaN(LongTermDebtToCapital())
                                then Long_Term_Debt_To_Capital[1]
                                else LongTermDebtToCapital();
AddLabel(show_labels and Long_Term_Debt_To_Capital, "Long Term Debt To Capital = " + Round(Long_Term_Debt_To_Capital, 2),
 if Long_Term_Debt_To_Capital < 5 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
def score_Long_Term_Debt_To_Capital = if Long_Term_Debt_To_Capital < 5 then 1 else 0;

def Inventory_Turnover = if IsNaN(InventoryTurnover())
                         then Inventory_Turnover[1]
                         else InventoryTurnover();
AddLabel(show_labels and Inventory_Turnover, "Inventory Turnover = " + Round(Inventory_Turnover, 2),
               if Inventory_Turnover < 5  then GlobalColor("LitePink") else
               if Inventory_Turnover < 10 then GlobalColor("Pre_Cyan") else
               if Inventory_Turnover < 15 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));

def DivPayout = if IsNaN(DividendPayout())
                then DivPayout[1]
                else DividendPayout();
AddLabel(show_labels and DivPayout, "Dividend Payout = " + AsDollars(DivPayout), GlobalColor("neutral"));

def DivPerShare = if IsNaN(DividendsPerShareTTM())
                  then DivPerShare[1]
                  else DividendsPerShareTTM();
AddLabel(show_labels and DivPerShare, "Dividend Per Share = " + AsDollars(DivPerShare), GlobalColor("neutral"));

def Interest_Rate = if IsNaN(InterestRate())
                    then Interest_Rate[1]
                    else InterestRate();
AddLabel(show_labels and Interest_Rate, "Interest Rate = " + Round(Interest_Rate, 2), GlobalColor("neutral"));

def Tax_Rate = if IsNaN(TaxRate())
               then Tax_Rate[1]
               else TaxRate();
AddLabel(show_labels and Tax_Rate, "Tax Rate = " + Round(Tax_Rate, 2), GlobalColor("neutral"));

plot score = score_Returns + score_EarnCash + score_ratios + score_Profits
           + score_FinLev + score_Sales_Per_Share + score_Long_Term_Debt_To_Capital;
AddLabel(show_summaries, "SCORE: " + score,
if score >= 12 then GlobalColor("Pre_Cyan") else
if score >= 10 then GlobalColor("LabelGreen") else
if score >= 8 then GlobalColor("GrayGreen") else GlobalColor("LitePink"));
score.hide();

Link to shared study: http://tos.mx/zF4if7t
I see free cash flow per share, can you please provide the codes for cash flow per share?
 
I see free cash flow per share, can you please provide the codes for cash flow per share?
Ruby:
def FreeCashFlowPerSh = if isNaN(FreeCashFlowPerShare())
                        then FreeCashFlowPerSh[1]
                        else FreeCashFlowPerShare();
AddLabel(show_labels and FreeCashFlowPerSh, "Free Cash Flow Per Share = " + AsDollars(FreeCashFlowPerSh),
                  if FreeCashFlowPerSh > 0 then GlobalColor("LabelGreen") else GlobalColor("LitePink"));
 
hello. there are a couple things to change in your code.
...not sure what you want to see by using this , in addlabel
, "" +
but it won't display anything. maybe this is what you want?
, "rev/share " +

...SalesPerShare() needs the () at the end.

...SalesPerShare() data does not exist on every candle. it shows up on 1 candle, once a year. so you need a way to keep the value after finding it.

take a look at this study. it displays several fundamental parameters of a stock.
https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/

this formula reads SalesPerShare() data.
if it finds data that isn't an error, it puts the value into x. if SalesPerShare() is an error, then x is equal the previous candle value of x. this is how to pass a value from one candle to the next, by using an offset of [1], to look at the previous candle.

def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare();
Thanks. So we should set the fiscal period to quarter, correct?
 
Can someone tell me why I get the following error when I write the simple scan?

input price = close;
def EPS = EarningsPerShareTTM();
plot signal = EPS;

I get the following error:

Invalid symbol in Stock Fundamentals function.

Thanks
 
hello. there are a couple things to change in your code.
...not sure what you want to see by using this , in addlabel
, "" +
but it won't display anything. maybe this is what you want?
, "rev/share " +

...SalesPerShare() needs the () at the end.

...SalesPerShare() data does not exist on every candle. it shows up on 1 candle, once a year. so you need a way to keep the value after finding it.

take a look at this study. it displays several fundamental parameters of a stock.
https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/

this formula reads SalesPerShare() data.
if it finds data that isn't an error, it puts the value into x. if SalesPerShare() is an error, then x is equal the previous candle value of x. this is how to pass a value from one candle to the next, by using an offset of [1], to look at the previous candle.

def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare();

Hi again @halcyonguy. I keep trying but I can't seem to make the code work. I have added your formula and checked over the study from @MerryDay (https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/).

I get the error message "Invalid symbol in Stock Fundamentals function". I am adding the script in the MarketWatch custom formula.

declare lower;
declare hide_on_intraday;
input show_labels = yes ;
input show_summaries = no ;
def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare() ;
def rev_per_share = x / close;
AddLabel(show_labels and rev_per_share, "Revenue Per Share = " + Round(rev_per_share, 2));


Hoping you can help me make this work. Thanks again!
 
@majidg You cannot use fundamentals in the TOS scan in that manner. All we have available are the built-in fundamental scans which are under add filter -> fundamental
 
Managed to make the code work without the "Invalid symbol in Stock Fundamentals function" error:

def sales_per_share = compoundValue (1, if IsNaN(SalesPerShare()) then sales_per_share [1] else SalesPerShare(), 1);
def rev_per_share = sales_per_share / close;
AddLabel (yes, "" + Round(rev_per_share, 2));
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
461 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top