ToS Indicator: RPLabels
After price itself, Relative Strength (RS) is my next most important technical reference point. Why? My goal is to outperform the US stock market (SPX) on a risk-adjusted basis (time in market). I can't accomplish that unless the assets that I'm trading are outperforming the market. In addition, there is a ton of research which supports the notion that your investing success is dependent upon buying leaders and ignoring laggards. Strength begets strength.
So, I examine Relative Performance (RP), the underlying's price divided by the comparison symbol's price (not Wilder's RSI), from the perspective of price phases. A Price Phase (PP) is the relationship of the indicator's value to a short-term (ST) and long-term (LT) moving average (MA) and the relationship of the MAs to each other. There are 6 phases, 3 bullish (Shades of Green Labels: Bullish, Caution, and Distribution) and 3 bearish (Shades of Red Labels: Accumulation, Recuperation, and Bearish). If the ST MA is greater than the LT MA, then the phase will be bullish and if the ST MA is less than or equal to the LT MA, then the phase is bearish. The type of phase is then determined by the relationship of RS to the MAs.
Depending upon the asset class, there are up to 6 RS comparisons. For a stock, there are 6 relationships: Symbol to Market, Symbol to Sector, Symbol to Industry, Sector to Market, Industry to Market, and Industry to Sector. All of these labels appear in the upper panel.
I found some corrections that needed to be made to the RPLabels code. Sorry for the inconvenience. Here is the corrected code.

After price itself, Relative Strength (RS) is my next most important technical reference point. Why? My goal is to outperform the US stock market (SPX) on a risk-adjusted basis (time in market). I can't accomplish that unless the assets that I'm trading are outperforming the market. In addition, there is a ton of research which supports the notion that your investing success is dependent upon buying leaders and ignoring laggards. Strength begets strength.
So, I examine Relative Performance (RP), the underlying's price divided by the comparison symbol's price (not Wilder's RSI), from the perspective of price phases. A Price Phase (PP) is the relationship of the indicator's value to a short-term (ST) and long-term (LT) moving average (MA) and the relationship of the MAs to each other. There are 6 phases, 3 bullish (Shades of Green Labels: Bullish, Caution, and Distribution) and 3 bearish (Shades of Red Labels: Accumulation, Recuperation, and Bearish). If the ST MA is greater than the LT MA, then the phase will be bullish and if the ST MA is less than or equal to the LT MA, then the phase is bearish. The type of phase is then determined by the relationship of RS to the MAs.
Depending upon the asset class, there are up to 6 RS comparisons. For a stock, there are 6 relationships: Symbol to Market, Symbol to Sector, Symbol to Industry, Sector to Market, Industry to Market, and Industry to Sector. All of these labels appear in the upper panel.
I found some corrections that needed to be made to the RPLabels code. Sorry for the inconvenience. Here is the corrected code.
Ruby:
# Written by Nick 02/26/22
# Change Log
# 03/03/22 Added ShowIndustryMarketCap to conditional statement for the Caution
# label for Industry to Market RP.
# 03/03/22 Corrected variable names in Labels for Symbol to Industry section.
# Documentation
# Each RP comparison (Symbol to Market, Symbol to Sector, Symbol to Industry,
# Sector to Market, Industry to Market, and Industry to Sector) can be turned
# on or off in the input section.
# Any valid symbol may be used for comparison.
# The type of average can be chosen by the user.
# The type of price or volume is selectable.
# The lengths of the short-term (ST) and long-term (LT) moving averages can be
# chosen by the user.
# By using the concept of Price Phases, these labels provide additional insight
# into the performance of the asset relative to its peers.
# Bullish = RP > Short-term (ST) Moving Average (MA) and RP > Long-term
# (LT) MA and ST MA > LTBullIndustryMC MA-Color: Green
# Caution = RP <= ST MA and RP > LT MA and ST MA > LT MA
# Distribution = RP <= ST MA and RP <= LT MA and ST MA > LT MA
# Accumulation = RP > ST MA and RP > LT MA and ST MA <= LT MA
# Recuperation = RP > ST MA and RP <= LT MA and ST MA <= LT MA
# Bearish = RP <= ST MA and RP <= LT MA and ST MA <= LT MA
#Inputs
input ShowSymbolMarketCap = Yes;
input MktCapSymbol = "SPY";
input ShowSymbolSector = Yes;
input ShowSectorMarketCap = Yes;
input SectorSymbol = "XLP";
input ShowSymbolIndustry = Yes;
input ShowIndustryMarketCap = Yes;
input ShowIndustrySector = Yes;
input IndustrySymbol = "$DJUSTB";
input AvgType = AverageType.SIMPLE;
input Price = FundamentalType.CLOSE;
input STMALength = 5;
input LTMALength = 21;
#Definitions-Price
def SymbolPrc = Fundamental(Price);
def MktCapPrc = Fundamental(Price, MktCapSymbol);
def SectorPrc = Fundamental(Price, SectorSymbol);
def IndustryPrc = Fundamental(Price, IndustrySymbol);
#Definitions-Symbol to Market Cap
def STMASymMC = MovingAverage(AvgType, SymbolPrc / MktCapPrc, STMALength);
def LTMASymMC = MovingAverage(AvgType, SymbolPrc / MktCapPrc, LTMALength);
def STBullSymMC = (SymbolPrc / MktCapPrc) > STMASymMC;
def LTBullSymMC = (SymbolPrc / MktCapPrc) > LTMASymMC;
def MABullSymMC = STMASymMC > LTMASymMC;
#Definitions-Symbol to Sector
def STMASymSector = MovingAverage(AvgType, SymbolPrc / SectorPrc, STMALength);
def LTMASymSector = MovingAverage(AvgType, SymbolPrc / SectorPrc, LTMALength);
def STBullSymSector = (SymbolPrc / SectorPrc) > STMASymSector;
def LTBullSymSector = (SymbolPrc / SectorPrc) > LTMASymSector;
def MABullSymSector = STMASymSector > LTMASymSector;
#Definitions-Symbol to Industry
def STMASymIndustry = MovingAverage(AvgType, SymbolPrc / IndustryPrc, STMALength);
def LTMASymIndustry = MovingAverage(AvgType, SymbolPrc / IndustryPrc, LTMALength);
def STBullSymIndustry = (SymbolPrc / IndustryPrc) > STMASymIndustry;
def LTBullSymIndustry = (SymbolPrc / IndustryPrc) > LTMASymIndustry;
def MABullSymIndustry = STMASymIndustry > LTMASymIndustry;
#Definitions-Sector to Market Cap
def STMASectorMC = MovingAverage(AvgType, SectorPrc / MktCapPrc, STMALength);
def LTMASectorMC = MovingAverage(AvgType, SectorPrc / MktCapPrc, LTMALength);
def STBullSectorMC = (SectorPrc / MktCapPrc) > STMASectorMC;
def LTBullSectorMC = (SectorPrc / MktCapPrc) > LTMASectorMC;
def MABullSectorMC = STMASectorMC > LTMASectorMC;
#Definitions-Industry to Market Cap
def STMAIndustryMC = MovingAverage(AvgType, IndustryPrc / MktCapPrc, STMALength);
def LTMAIndustryMC = MovingAverage(AvgType, IndustryPrc / MktCapPrc, LTMALength);
def STBullIndustryMC = (IndustryPrc / MktCapPrc) > STMAIndustryMC;
def LTBullIndustryMC = (IndustryPrc / MktCapPrc) > LTMAIndustryMC;
def MABullIndustryMC = STMAIndustryMC > LTMAIndustryMC;
#Defintions-Industry to Sector
def STMAIndustrySector = MovingAverage(AvgType, IndustryPrc / SectorPrc, STMALength);
def LTMAIndustrySector = MovingAverage(AvgType, IndustryPrc / SectorPrc, LTMALength);
def STBullIndustrySector = (IndustryPrc / SectorPrc) > STMAIndustrySector;
def LTBullIndustrySector = (IndustryPrc / SectorPrc) > LTMAIndustrySector;
def MABullIndustrySector = STMAIndustrySector > LTMAIndustrySector;
#Labels for Symbol Relative Performance to the Market
AddLabel(yes, if ShowSymbolMarketCap and STBullSymMC is true and LTBullSymMC is true and MABullSymMC is true then "Symbol to Market Cap RP (" + MktCapSymbol + "): Bullish" else "", Color.GREEN);
AddLabel(yes, if ShowSymbolMarketCap and STBullSymMC is false and LTBullSymMC is true and MABullSymMC is true then "Symbol to Market Cap RP (" + MktCapSymbol + "): Caution" else "", Color.LIGHT_GREEN);
AddLabel(yes, if ShowSymbolMarketCap and STBullSymMC is false and LTBullSymMC is false and MABullSymMC is true then "Symbol to Market Cap RP (" + MktCapSymbol + "): Distribution" else "", Color.DARK_GREEN);
AddLabel(yes, if ShowSymbolMarketCap and STBullSymMC is false and LTBullSymMC is false and MABullSymMC is false then "Symbol to Market Cap RP (" + MktCapSymbol + "): Bearish" else "", Color.RED);
AddLabel(yes, if ShowSymbolMarketCap and STBullSymMC is true and LTBullSymMC is false and MABullSymMC is false then "Symbol to Market Cap RP (" + MktCapSymbol + "): Recuperation" else "", Color.LIGHT_RED);
AddLabel(yes, if ShowSymbolMarketCap and STBullSymMC is true and LTBullSymMC is true and MABullSymMC is false then "Symbol to Market Cap RP (" + MktCapSymbol + "): Accumulation" else "", Color.DARK_RED);
#Labels for Symbol Relative Performance to its Sector
AddLabel(yes, if ShowSymbolSector and STBullSymSector is true and LTBullSymSector is true and MABullSymSector is true then "Symbol to Sector RP (" + SectorSymbol + "): Bullish" else "", Color.GREEN);
AddLabel(yes, if ShowSymbolSector and STBullSymSector is false and LTBullSymSector is true and MABullSymSector is true then "Symbol to Sector RP (" + SectorSymbol + "): Caution" else "", Color.LIGHT_GREEN);
AddLabel(yes, if ShowSymbolSector and STBullSymSector is false and LTBullSymSector is false and MABullSymSector is true then "Symbol to Sector RP (" + SectorSymbol + "): Distribution" else "", Color.DARK_GREEN);
AddLabel(yes, if ShowSymbolSector and STBullSymSector is false and LTBullSymSector is false and MABullSymSector is false then "Symbol to Sector RP (" + SectorSymbol + "): Bearish" else "", Color.RED);
AddLabel(yes, if ShowSymbolSector and STBullSymSector is true and LTBullSymSector is false and MABullSymSector is false then "Symbol to Sector RP (" + SectorSymbol + "): Recuperation" else "", Color.LIGHT_RED);
AddLabel(yes, if ShowSymbolSector and STBullSymSector is true and LTBullSymSector is true and MABullSymSector is false then "Symbol to Sector RP (" + SectorSymbol + "): Accumulation" else "", Color.DARK_RED);
#Labels for Symbol Relative Performance to its Industry Group
AddLabel(yes, if ShowSymbolIndustry and STBullSymIndustry is true and LTBullSymIndustry is true and MABullSymIndustry is true then "Symbol to Industry RP (" + IndustrySymbol + "): Bullish" else "", Color.GREEN);
AddLabel(yes, if ShowSymbolIndustry and STBullSymIndustry is false and LTBullSymIndustry is true and MABullSymIndustry is true then "Symbol to Industry RP (" + IndustrySymbol + "): Caution" else "", Color.LIGHT_GREEN);
AddLabel(yes, if ShowSymbolIndustry and STBullSymIndustry is false and LTBullSymIndustry is false and MABullSymIndustry is true then "Symbol to Industry RP (" + IndustrySymbol + "): Distribution" else "", Color.DARK_GREEN);
AddLabel(yes, if ShowSymbolIndustry and STBullSymIndustry is false and LTBullSymIndustry is false and MABullSymIndustry is false then "Symbol to Industry RP (" + IndustrySymbol + "): Bearish" else "", Color.RED);
AddLabel(yes, if ShowSymbolIndustry and STBullSymIndustry is true and LTBullSymIndustry is false and MABullSymIndustry is false then "Symbol to Industry RP (" + IndustrySymbol + "): Recuperation" else "", Color.LIGHT_RED);
AddLabel(yes, if ShowSymbolIndustry and STBullSymIndustry is true and LTBullSymIndustry is true and MABullSymIndustry is false then "Symbol to Industry RP (" + IndustrySymbol + "): Accumulation" else "", Color.DARK_RED);
#Labels for Sector Relative Performance to the Market
AddLabel(yes, if ShowSectorMarketCap and STBullSectorMC is true and LTBullSectorMC is true and MABullSectorMC is true then "Sector to Market Cap RP (" + MktCapSymbol + "): Bullish" else "", Color.GREEN);
AddLabel(yes, if ShowSectorMarketCap and STBullSectorMC is false and LTBullSectorMC is true and MABullSectorMC is true then "Sector to Market Cap RP (" + MktCapSymbol + "): Caution" else "", Color.LIGHT_GREEN);
AddLabel(yes, if ShowSectorMarketCap and STBullSectorMC is false and LTBullSectorMC is false and MABullSectorMC is true then "Sector to Market Cap RP (" + MktCapSymbol + "): Distribution" else "", Color.DARK_GREEN);
AddLabel(yes, if ShowSectorMarketCap and STBullSectorMC is false and LTBullSectorMC is false and MABullSectorMC is false then "Sector to Market Cap RP (" + MktCapSymbol + "): Bearish" else "", Color.RED);
AddLabel(yes, if ShowSectorMarketCap and STBullSectorMC is true and LTBullSectorMC is false and MABullSectorMC is false then "Sector to Market Cap RP (" + MktCapSymbol + "): Recuperation" else "", Color.LIGHT_RED);
AddLabel(yes, if ShowSectorMarketCap and STBullSectorMC is true and LTBullSectorMC is true and MABullSectorMC is false then "Sector to Market Cap RP (" + MktCapSymbol + "): Accumulation" else "", Color.DARK_RED);
#Labels for Industry Relative Performance to the Market
AddLabel(yes, if ShowIndustryMarketCap and STBullIndustryMC is true and LTBullIndustryMC is true and MABullIndustryMC is true then "Industry to Market Cap RP (" + MktCapSymbol + "): Bullish" else "", Color.GREEN);
AddLabel(yes, if ShowIndustryMarketCap and STBullIndustryMC is false and LTBullIndustryMC is true and MABullIndustryMC is true then "Industry to Market Cap RP (" + MktCapSymbol + "): Caution" else "", Color.LIGHT_GREEN);
AddLabel(yes, if ShowIndustryMarketCap and STBullIndustryMC is false and LTBullIndustryMC is false and MABullIndustryMC is true then "Industry to Market Cap RP (" + MktCapSymbol + "): Distribution" else "", Color.DARK_GREEN);
AddLabel(yes, if ShowIndustryMarketCap and STBullIndustryMC is false and LTBullIndustryMC is false and MABullIndustryMC is false then "Industry to Market Cap RP (" + MktCapSymbol + "): Bearish" else "", Color.RED);
AddLabel(yes, if ShowIndustryMarketCap and STBullIndustryMC is true and LTBullIndustryMC is false and MABullIndustryMC is false then "Industry to Market Cap RP (" + MktCapSymbol + "): Recuperation" else "", Color.LIGHT_RED);
AddLabel(yes, if ShowIndustryMarketCap and STBullIndustryMC is true and LTBullIndustryMC is true and MABullIndustryMC is false then "Industry to Market Cap RP (" + MktCapSymbol + "): Accumulation" else "", Color.DARK_RED);
#Labels for Industry Relative Performance to its Sector
AddLabel(yes, if ShowIndustrySector and STBullIndustrySector is true and LTBullIndustrySector is true and MABullIndustrySector is true then "Industry to Sector RP (" + SectorSymbol + "): Bullish" else "", Color.GREEN);
AddLabel(yes, if ShowIndustrySector and STBullIndustrySector is false and LTBullIndustrySector is true and MABullIndustrySector is true then "Industry to Sector RP (" + SectorSymbol + "): Caution" else "", Color.LIGHT_GREEN);
AddLabel(yes, if ShowIndustrySector and STBullIndustrySector is false and LTBullIndustrySector is false and MABullIndustrySector is true then "Industry to Sector RP (" + SectorSymbol + "): Distribution" else "", Color.DARK_GREEN);
AddLabel(yes, if ShowIndustrySector and STBullIndustrySector is false and LTBullIndustrySector is false and MABullIndustrySector is false then "Industry to Sector RP (" + SectorSymbol + "): Bearish" else "", Color.RED);
AddLabel(yes, if ShowIndustrySector and STBullIndustrySector is true and LTBullIndustrySector is false and MABullIndustrySector is false then "Industry to Sector RP (" + SectorSymbol + "): Recuperation" else "", Color.LIGHT_RED);
AddLabel(yes, if ShowIndustrySector and STBullIndustrySector is true and LTBullIndustrySector is true and MABullIndustrySector is false then "Industry to Sector RP (" + SectorSymbol + "): Accumulation" else "", Color.DARK_RED);
Last edited by a moderator: