#===================================================================
# Fundamental Data Labels (Enhanced)
# - Original concept: Mobius / MerryDay
# - Revision: Richard Campbell + GPT, 2025
#===================================================================
#-------------------------------------------------------
# COLOR PALETTE — FUNDAMENTAL TIER SYSTEM
#-------------------------------------------------------
# Used for: top-tier fundamentals such as excellent ROA/ROE, strong margins, or elite value (PE<10).
DefineGlobalColor("SuperiorBlue", CreateColor(102, 179, 255)); # Elite / Outstanding performance
# Used for: strong metrics, positive earnings, healthy balance sheet, good profitability.
DefineGlobalColor("ExcellentGreen", CreateColor(60, 208, 112)); # Strong / Healthy
# Used for: average fundamentals, normal valuation ranges, acceptable but not impressive metrics.
DefineGlobalColor("AcceptableGray", Color.LIGHT_GRAY); # Neutral / Average
# Used for: borderline metrics, elevated valuation, early warnings, “monitor this.”
DefineGlobalColor("CautionYellow", CreateColor(253, 253, 150)); # Caution / Borderline
# Used for: weak metrics, slightly negative trends, expensive valuation (but growth still possible).
DefineGlobalColor("WarningSoftRed", CreateColor(255, 185, 190)); # Mild Warning / Soft Negative
# Used for: worst-tier metrics, high risk, severe valuation extremes, or major financial issues.
DefineGlobalColor("DangerRed", CreateColor(234, 60, 83)); # High Risk / Major Warning
#-------------------------------------------------------
# LABEL / DISPLAY SETTINGS
#-------------------------------------------------------
# Master label visibility – turn ALL labels on/off at once.
input LabelDisplay = { default "< LABEL & DISPLAY SETTINGS >" };
# Master toggle – if "no", no labels will plot at all
input showLabels = yes;
# Label location on chart
input LabelLocation =
{
default "Top-Left",
"Top-Right",
"Bottom-Left",
"Bottom-Right"
};
def lblLoc =
if LabelLocation == LabelLocation."Top-Left" then Location.TOP_LEFT
else if LabelLocation == LabelLocation."Top-Right" then Location.TOP_RIGHT
else if LabelLocation == LabelLocation."Bottom-Left" then Location.BOTTOM_LEFT
else Location.BOTTOM_RIGHT;
#-------------------------------------------------------
# INPUTS – EARNINGS, CASH FLOW, & VALUATION
#-------------------------------------------------------
input ECFV = { default "< EARNINGS, CASH FLOW, & VALUATION >" };
# PE – Price/Earnings ratio using close / EPS(TTM).
# Lower can mean cheaper valuation, but negative means losing money.
# Classic quick valuation snapshot.
input PE_On = yes;
# EPS – Earnings Per Share (TTM).
# Positive and rising EPS is generally bullish; negative EPS = losing money.
# Used as the base for many other valuation ratios.
input EPS_On = yes;
# FCF – Free Cash Flow Per Share.
# Positive free cash flow is very important for financial health.
# Negative for long periods can signal stress.
input CashFlow_On = yes;
#-------------------------------------------------------
# INPUTS – PROFIT MARGINS
#-------------------------------------------------------
input ProfitsSection = { default "< PROFITABILITY MARGINS >" };
# Gross Profit Margin – (Sales - COGS) / Sales.
# Higher = better; negative or falling often a warning sign.
input GrossMargin_On = yes;
# Operating Profit Margin – core profitability from operations.
# Higher = better; negative means operations are not profitable.
input OperatingMargin_On = no;
# Net Profit Margin – bottom-line profit after all expenses and taxes.
# Higher = better; negative values = net loss.
input NetMargin_On = no;
#-------------------------------------------------------
# INPUTS – LIQUIDITY, LEVERAGE, & EFFICIENCY
#-------------------------------------------------------
input BalanceSection = { default "< BALANCE SHEET & EFFICIENCY >" };
# Current Ratio – Current Assets / Current Liabilities.
# > 1.0 means more near-term assets than liabilities. > 2.0 very comfortable.
input CurrentRatio_On = no;
# Quick Ratio – (Current Assets - Inventory) / Current Liabilities.
# Stricter liquidity test; >= 1.0 is generally considered healthy.
input QuickRatio_On = yes;
# ROA – Return On Assets (%).
# Profit generated per dollar of total assets. Higher is better.
input ROA_On = no;
# ROE – Return On Equity (%).
# Profit generated per dollar of shareholder equity. Higher is better.
input ROE_On = yes;
# SPS – Sales Per Share.
# Revenue per share; a positive number is generally a sign of a real business.
input SalesPerShare_On = yes;
# FCCR – Fixed Charge Coverage Ratio.
# Ability to cover fixed charges (like interest + lease) from earnings.
input FixedChargeCoverage_On = no;
# Asset Turnover – Total Asset Turnover.
# Measures how efficiently assets are used to generate sales.
input AssetTurnover_On = no;
# Financial Leverage – balance sheet leverage factor.
# Higher leverage = more risk; < 2 is generally considered moderate.
input FinancialLeverage_On = no;
# Book Value Per Share.
# Approximate net asset value per share.
input BookValue_On = no;
# LTD-to-Capital – Long Term Debt To Capital (%).
# Higher % = more debt load; very high values can be a warning.
input DebtToCapital_On = yes;
# Inventory Turnover – how fast inventory is sold and replaced.
# Very low can indicate weak demand; very high may indicate efficient operations.
input InventoryTurnover_On = no;
#-------------------------------------------------------
# INPUTS – DIVIDENDS & RATES
#-------------------------------------------------------
input DivSection = { default "< DIVIDENDS & RATES >" };
# Dividend Payout Ratio (% of earnings paid out as dividends).
# Very high payout can be unsustainable; very low = more retained earnings.
input DividendPayout_On = no;
# Dividend Per Share (TTM).
# Total dividend paid per share over trailing 12 months.
input DividendPerShare_On = no;
# Dividend Yield (%).
# Dividend per share divided by current price.
input DividendYield_On = no;
# Interest Rate – company-level effective interest rate.
input InterestRate_On = no;
# Tax Rate – effective tax rate.
input TaxRate_On = no;
#-------------------------------------------------------
# INPUTS – SCORES
#-------------------------------------------------------
input ScoreSection = { default "< SCORES & SUMMARY LABELS >" };
# Fundamental Score – existing composite score from original script.
input FundamentalScore_On = yes;
# Balance Sheet Score – new 0–10 numeric score for balance sheet strength.
input BalanceSheetScore_On = yes;
#-------------------------------------------------------
# FUNDAMENTAL SERIES
#-------------------------------------------------------
def fp = FiscalPeriod.YEAR;
#-------------------------------------------------------
# EPS / PE / CASH FLOW
#-------------------------------------------------------
def EPS_raw = EarningsPerShareTTM(fiscalPeriod = fp);
def EPS_TTM = if IsNaN(EPS_raw) then EPS_TTM[1] else EPS_raw;
def PE_raw = if EPS_TTM != 0 then close / EPS_TTM else Double.NaN;
def PE_val = Round(PE_raw, 1);
def FreeCashFlowPerSh_raw = FreeCashFlowPerShare();
def FreeCashFlowPerSh =
if IsNaN(FreeCashFlowPerSh_raw) then FreeCashFlowPerSh[1]
else FreeCashFlowPerSh_raw;
# Label: P/E
AddLabel(
showLabels and PE_On and !IsNaN(PE_val),
" P/E | " + Round(PE_val, 2) + " ",
if PE_val < 0 then GlobalColor("WarningSoftRed") # Negative EPS (losses)
else if PE_val < 10 then GlobalColor("SuperiorBlue") # Extremely strong value
else if PE_val < 15 then GlobalColor("ExcellentGreen") # Good value
else if PE_val < 30 then GlobalColor("AcceptableGray") # Normal valuation
else if PE_val < 60 then GlobalColor("CautionYellow") # Expensive
else if PE_val < 90 then GlobalColor("WarningSoftRed") # Very expensive (growth possible)
else GlobalColor("DangerRed"), # Hyper-expensive / highest risk
location = lblLoc
);
# Label: EPS-TTM
AddLabel(
showLabels and EPS_On and !IsNaN(EPS_TTM),
" EPS-TTM | " + AsDollars(EPS_TTM) + " ",
if EPS_TTM > 0 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
# Label: Free Cash Flow Per Share
AddLabel(
showLabels and CashFlow_On and !IsNaN(FreeCashFlowPerSh),
" FCF/Share | " + AsDollars(FreeCashFlowPerSh) + " ",
if FreeCashFlowPerSh > 0 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
# Earnings + Cash Flow + Valuation score component
def score_EarnCash =
if PE_val < 0 and FreeCashFlowPerSh < 0 and EPS_TTM < 0 then 0 else 5;
#-------------------------------------------------------
# PROFIT MARGINS
#-------------------------------------------------------
def Gross_Profit_Margin_raw = GrossProfitMargin();
def Gross_Profit_Margin =
if IsNaN(Gross_Profit_Margin_raw) then Gross_Profit_Margin[1]
else Gross_Profit_Margin_raw;
AddLabel(
showLabels and GrossMargin_On and !IsNaN(Gross_Profit_Margin),
" Gross Margin | " + Round(Gross_Profit_Margin, 2) + "% ",
if Gross_Profit_Margin > 0 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def Operating_Profit_Margin_raw = OperatingProfitMargin();
def Operating_Profit_Margin =
if IsNaN(Operating_Profit_Margin_raw) then Operating_Profit_Margin[1]
else Operating_Profit_Margin_raw;
AddLabel(
showLabels and OperatingMargin_On and !IsNaN(Operating_Profit_Margin),
" Operating Margin | " + Round(Operating_Profit_Margin, 2) + "% ",
if Operating_Profit_Margin > 0 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def Net_Profit_Margin_raw = NetProfitMargin();
def Net_Profit_Margin =
if IsNaN(Net_Profit_Margin_raw) then Net_Profit_Margin[1]
else Net_Profit_Margin_raw;
AddLabel(
showLabels and NetMargin_On and !IsNaN(Net_Profit_Margin),
" Net Margin | " + Round(Net_Profit_Margin, 2) + "% ",
if Net_Profit_Margin > 0 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def score_Profits =
if Gross_Profit_Margin > 0 or Net_Profit_Margin > 0 or Operating_Profit_Margin > 0 then 3 else 0;
#-------------------------------------------------------
# LIQUIDITY RATIOS
#-------------------------------------------------------
def CurRatio_raw = CurrentRatio();
def CurRatio =
if IsNaN(CurRatio_raw) then CurRatio[1]
else CurRatio_raw;
AddLabel(
showLabels and CurrentRatio_On and !IsNaN(CurRatio),
" Current Ratio | " + Round(CurRatio, 2) + " ",
if CurRatio > 2 then GlobalColor("AcceptableGray")
else if CurRatio >= 1 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def Quick_Ratio_raw = QuickRatio();
def Quick_Ratio =
if IsNaN(Quick_Ratio_raw) then Quick_Ratio[1]
else Quick_Ratio_raw;
AddLabel(
showLabels and QuickRatio_On and !IsNaN(Quick_Ratio),
" Quick Ratio | " + Round(Quick_Ratio, 2) + " ",
if Quick_Ratio > 2 then GlobalColor("AcceptableGray")
else if Quick_Ratio >= 1 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def score_Ratios =
if Quick_Ratio >= 1 or CurRatio >= 1 then 3 else 0;
#-------------------------------------------------------
# RETURNS (ROA / ROE)
#-------------------------------------------------------
def Return_On_Assets_raw = ReturnOnAssets();
def Return_On_Assets =
if IsNaN(Return_On_Assets_raw) then Return_On_Assets[1]
else Return_On_Assets_raw;
AddLabel(
showLabels and ROA_On and !IsNaN(Return_On_Assets),
" ROA | " + Round(Return_On_Assets, 2) + "% ",
if Return_On_Assets >= 15 then GlobalColor("SuperiorBlue")
else if Return_On_Assets >= 10 then GlobalColor("ExcellentGreen")
else if Return_On_Assets > 0 then GlobalColor("AcceptableGray")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def Return_On_Equity_raw = ReturnOnEquity();
def Return_On_Equity =
if IsNaN(Return_On_Equity_raw) then Return_On_Equity[1]
else Return_On_Equity_raw;
AddLabel(
showLabels and ROE_On and !IsNaN(Return_On_Equity),
" ROE | " + Round(Return_On_Equity, 2) + "% ",
if Return_On_Equity >= 15 then GlobalColor("SuperiorBlue")
else if Return_On_Equity >= 10 then GlobalColor("ExcellentGreen")
else if Return_On_Equity > 0 then GlobalColor("AcceptableGray")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def score_Returns =
if Return_On_Equity >= 10 or Return_On_Assets >= 10 then 1 else 0;
#-------------------------------------------------------
# SALES / EFFICIENCY
#-------------------------------------------------------
def Sales_Per_Share_raw = SalesPerShare();
def Sales_Per_Share =
if IsNaN(Sales_Per_Share_raw) then Sales_Per_Share[1]
else Sales_Per_Share_raw;
AddLabel(
showLabels and SalesPerShare_On and !IsNaN(Sales_Per_Share),
" Sales Per Share | " + AsDollars(Sales_Per_Share) + " ",
if Sales_Per_Share > 0 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def score_Sales_Per_Share = if Sales_Per_Share > 0 then 1 else 0;
def FixChgCovRatio_raw = FixedChargeCoverageRatio();
def FixChgCovRatio =
if IsNaN(FixChgCovRatio_raw) then FixChgCovRatio[1]
else FixChgCovRatio_raw;
AddLabel(
showLabels and FixedChargeCoverage_On and !IsNaN(FixChgCovRatio),
" Fixed Charge Coverage | " + Round(FixChgCovRatio, 2) + " ",
if FixChgCovRatio >= 1 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def Total_Asset_Turnover_raw = TotalAssetTurnover();
def Total_Asset_Turnover =
if IsNaN(Total_Asset_Turnover_raw) then Total_Asset_Turnover[1]
else Total_Asset_Turnover_raw;
AddLabel(
showLabels and AssetTurnover_On and !IsNaN(Total_Asset_Turnover),
" Asset Turnover | " + Round(Total_Asset_Turnover, 2) + " ",
if Total_Asset_Turnover > 1 then GlobalColor("ExcellentGreen")
else GlobalColor("AcceptableGray"),
location = lblLoc
);
def FinLev_raw = FinancialLeverage();
def FinLev =
if IsNaN(FinLev_raw) then FinLev[1]
else FinLev_raw;
AddLabel(
showLabels and FinancialLeverage_On and !IsNaN(FinLev),
" Financial Leverage | " + Round(FinLev, 2) + " ",
if FinLev > 0 and FinLev < 2 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def score_FinLev = if FinLev < 2 then 1 else 0;
def BookValue_raw = BookValuePerShare();
def BookValue =
if IsNaN(BookValue_raw) then BookValue[1]
else BookValue_raw;
AddLabel(
showLabels and BookValue_On and !IsNaN(BookValue),
" Book Value/Share | " + Round(BookValue, 2) + " ",
if BookValue < 2 then GlobalColor("SuperiorBlue")
else if BookValue < 3 then GlobalColor("ExcellentGreen")
else GlobalColor("AcceptableGray"),
location = lblLoc
);
def Long_Term_Debt_To_Capital_raw = LongTermDebtToCapital();
def Long_Term_Debt_To_Capital =
if IsNaN(Long_Term_Debt_To_Capital_raw) then Long_Term_Debt_To_Capital[1]
else Long_Term_Debt_To_Capital_raw;
AddLabel(
showLabels and DebtToCapital_On and !IsNaN(Long_Term_Debt_To_Capital),
" LT Debt/Capital | " + Round(Long_Term_Debt_To_Capital, 2) + "% ",
if Long_Term_Debt_To_Capital < 5 then GlobalColor("ExcellentGreen")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
def score_Long_Term_Debt_To_Capital =
if Long_Term_Debt_To_Capital < 5 then 1 else 0;
def Inventory_Turnover_raw = InventoryTurnover();
def Inventory_Turnover =
if IsNaN(Inventory_Turnover_raw) then Inventory_Turnover[1]
else Inventory_Turnover_raw;
AddLabel(
showLabels and InventoryTurnover_On and !IsNaN(Inventory_Turnover),
" Inventory Turnover | " + Round(Inventory_Turnover, 2) + " ",
if Inventory_Turnover < 5 then GlobalColor("WarningSoftRed")
else if Inventory_Turnover < 10 then GlobalColor("SuperiorBlue")
else if Inventory_Turnover < 15 then GlobalColor("AcceptableGray")
else GlobalColor("WarningSoftRed"),
location = lblLoc
);
#-------------------------------------------------------
# DIVIDENDS & RATES
#-------------------------------------------------------
def DivPayout_raw = DividendPayout();
def DivPayout =
if IsNaN(DivPayout_raw) then DivPayout[1]
else DivPayout_raw;
AddLabel(
showLabels and DividendPayout_On and !IsNaN(DivPayout),
" Dividend Payout | " + Round(DivPayout, 2) + "% ",
GlobalColor("AcceptableGray"),
location = lblLoc
);
def DivPerShare_raw = DividendsPerShareTTM();
def DivPerShare =
if IsNaN(DivPerShare_raw) then DivPerShare[1]
else DivPerShare_raw;
AddLabel(
showLabels and DividendPerShare_On and !IsNaN(DivPerShare),
" Dividend/Share | " + AsDollars(DivPerShare) + " ",
GlobalColor("AcceptableGray"),
location = lblLoc
);
def DivYield =
if IsNaN(DivPerShare) or close == 0 then Double.NaN
else DivPerShare / close;
AddLabel(
showLabels and DividendYield_On and !IsNaN(DivYield),
" Dividend Yield | " + AsPercent(DivYield) + " ",
GlobalColor("AcceptableGray"),
location = lblLoc
);
def Interest_Rate_raw = InterestRate();
def Interest_Rate =
if IsNaN(Interest_Rate_raw) then Interest_Rate[1]
else Interest_Rate_raw;
AddLabel(
showLabels and InterestRate_On and !IsNaN(Interest_Rate),
" Interest Rate | " + Round(Interest_Rate, 2) + "% ",
GlobalColor("AcceptableGray"),
location = lblLoc
);
def Tax_Rate_raw = TaxRate();
def Tax_Rate =
if IsNaN(Tax_Rate_raw) then Tax_Rate[1]
else Tax_Rate_raw;
AddLabel(
showLabels and TaxRate_On and !IsNaN(Tax_Rate),
" Tax Rate | " + Round(Tax_Rate, 2) + "% ",
GlobalColor("AcceptableGray"),
location = lblLoc
);
#-------------------------------------------------------
# BALANCE SHEET STRENGTH SCORE (0–10)
# Uses:
# - Current Ratio / Quick Ratio
# - LT Debt to Capital
# - Financial Leverage
# - Free Cash Flow per Share
# - Fixed Charge Coverage
#-------------------------------------------------------
# Liquidity score (0–3)
def LiquidityScore =
(if CurRatio >= 1 then 1 else 0) +
(if Quick_Ratio >= 1 then 1 else 0) +
(if CurRatio > 2 or Quick_Ratio > 2 then 1 else 0);
# Debt load & leverage score (0–3)
def DebtScore =
(if Long_Term_Debt_To_Capital < 5 then 1 else 0) +
(if Long_Term_Debt_To_Capital < 3 then 1 else 0) +
(if FinLev < 2 then 1 else 0);
# Cash generation score (0–2)
def CashScore =
if FreeCashFlowPerSh > 0 then
if FreeCashFlowPerSh > 0 and EPS_TTM > 0 then 2
else 1
else 0;
# Fixed charge coverage score (0–2)
def CoverageScore =
if FixChgCovRatio >= 1 then
if FixChgCovRatio >= 3 then 2
else 1
else 0;
#-------------------------------------------------------
# BALANCE SHEET SCORE (0–10)
# LiquidityScore (0–3)
# DebtScore (0–3)
# CashScore (0–2)
# CoverageScore (0–2)
#
# Color tiers:
# 9–10 → SuperiorBlue (elite)
# 7–8 → ExcellentGreen (strong)
# 5–6 → AcceptableGray (average)
# 3–4 → CautionYellow (borderline)
# 2 → WarningSoftRed (weak)
# 0–1 → DangerRed (high risk)
#-------------------------------------------------------
def BalanceSheetScoreRaw = LiquidityScore + DebtScore + CashScore + CoverageScore;
def BalanceSheetScore = Min(10, BalanceSheetScoreRaw);
# Spacer before balance sheet score / fundamental score block
AddLabel(
showLabels and FundamentalScore_On,
" ",
CreateColor(36, 36, 36),
location = lblLoc
);
AddLabel(
showLabels and BalanceSheetScore_On and !IsNaN(BalanceSheetScore),
" Balance Sheet | " + BalanceSheetScore + " / 10 ",
if BalanceSheetScore >= 9 then GlobalColor("SuperiorBlue") # Elite
else if BalanceSheetScore >= 7 then GlobalColor("ExcellentGreen") # Strong
else if BalanceSheetScore >= 5 then GlobalColor("AcceptableGray") # Average
else if BalanceSheetScore >= 3 then GlobalColor("CautionYellow") # Borderline
else if BalanceSheetScore >= 2 then GlobalColor("WarningSoftRed") # Weak
else GlobalColor("DangerRed"), # High risk
location = lblLoc
);
#-------------------------------------------------------
# FUNDAMENTAL SCORE (EXISTING COMPOSITE) – LAST LABEL
#-------------------------------------------------------
def score =
score_Returns
+ score_EarnCash
+ score_Ratios
+ score_Profits
+ score_FinLev
+ score_Sales_Per_Share
+ score_Long_Term_Debt_To_Capital;
# Spacer before final fundamental score
AddLabel(
showLabels and FundamentalScore_On,
" ",
CreateColor(36, 36, 36),
location = lblLoc
);
AddLabel(
showLabels and FundamentalScore_On,
" Fundamentals | " + score + " / 15 ",
if score >= 13 then GlobalColor("SuperiorBlue") # Elite
else if score >= 11 then GlobalColor("ExcellentGreen") # Strong
else if score >= 9 then GlobalColor("AcceptableGray") # Average
else if score >= 7 then GlobalColor("CautionYellow") # Borderline
else if score >= 5 then GlobalColor("WarningSoftRed") # # Weak
else GlobalColor("DangerRed"), # High risk
location = lblLoc
);