Relative Strength RP Labels For ThinkOrSwim

Nick

New member
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.
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:
I love Relative Strength scripts for trading on the current volatility of the market.
Thank you for sharing.
 
Last edited:
i like these both, and wondering how to get a row of six boxes along the side of the chart and not the line up across the top. We've seen it before and though its an alteration to the top indicator, the lower one will kill
 
why not go with seasonality , monthly stats, for say 5 or 10 years , i have a study if you would like it! let me know!
for instance BLDR , 100 % , november ,at an average gain at 13 percent, DAR october 100% average rate of 9%,PGNY, 100% april,
20% average gain,TREX 100% june, average gain 6%, all five year stats
Thanks, but I have a seasonality indicator that I use on my monthly chart for all available data. I use seasonality as a factor in my market awareness, headwind/tailwind, not in determining go/no go for a trade.
 
i like these both, and wondering how to get a row of six boxes along the side of the chart and not the line up across the top. We've seen it before and though its an alteration to the top indicator, the lower one will kill
Thanks. I know there is a way to do what you're talking about, but I prefer them across the top.
 
Here's a scan for hunting for either Bullish or Bearish relative performance (strength).

# Written by Nick 03/03/22

#Change the Input parameters to your liking and in the Plot section, either hash (#) or
# unhash the plot that you want to scan for, either Bull or Bear.

#Inputs
input ComparionSymbol = "SPY";
input AvgType = AverageType.SIMPLE;
input Price = FundamentalType.CLOSE;
input STMALength = 5;
input LTMALength = 21;

#Definitions
def SymbolPrc = Fundamental(Price);
def ComparisonPrc = Fundamental(Price, ComparionSymbol);
def STMA = MovingAverage(AvgType, SymbolPrc / ComparisonPrc, STMALength);
def LTMA = MovingAverage(AvgType, SymbolPrc / ComparisonPrc, LTMALength);
def MABull = STMA > LTMA;
def MABear = STMA <= LTMA;

#Plots for Scans
plot BullRP = if MABull then 1 else 0;
#plot BearRP = if MABear then 1 else 0;
 
Close STMALength & LTMALength, seems to me, quite tight to zero, would this find a repeating parabolic type increasing in both volume and RP strength if LTMALength pushed 160 or even 200?

only a guess, to see if a scan finds as stock which its pps may be building slowly into an event (RP)


Scanned stock chart
 
Last edited:
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.
Isn't this showing relative strength to only one sector and one industry which may not be related to the individual stock we may be looking? could this be adjusted so when you select a stock it will compare it to its own sector and industry along with the overall market?
 
Last edited by a moderator:
Isn't this showing relative strength to only one sector and one industry which may not be related to the individual stock we may be looking? could this be adjusted so when you select a stock it will compare it to its own sector and industry along with the overall market?
The sector field in a stock's data feed is limited to display only in watchlists and some ToS widgets. So we have no way of determining an equity's sector in scripts. So no way, to link a stock with its sector.

Scripts such as the one in this thread are our best workaround.
 
Isn't this showing relative strength to only one sector and one industry which may not be related to the individual stock we may be looking? could this be adjusted so when you select a stock it will compare it to its own sector and industry along with the overall market?
Yes to your first question. I'd love to do that, but I don't think that ToS can deliver that data. So, I get that information from StockCharts.com and then I have to change the input variables on the RPLabels indicator manually. It's a pain and a real problem. If anyone knows how to obtain a stock's market cap, sector, and industry group via Thinkscript, it would be greatly appreciated.
 
industries are definitely too many but could relative strength of stock to market SPY, QQQ and DOW and the 11 sectors be created by way of labels, total of 14 that would be green or red accordingly. Then all we would need is to know the sector of the stock which could be displayed in our watchlist? If anyone could do this code would probably be very useful to all
 
Yes to your first question. I'd love to do that, but I don't think that ToS can deliver that data. So, I get that information from StockCharts.com and then I have to change the input variables on the RPLabels indicator manually. It's a pain and a real problem. If anyone knows how to obtain a stock's market cap, sector, and industry group via Thinkscript, it would be greatly appreciated.
market cap, sector and industry group fields from the data feed are limited to display only in watchlists and some ToS widgets. So we have no way of accessing those elements in scripts.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
412 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