RS Line and Recent High in thinkscript

One very helpful gauge within MarketSmith is the RS Line, which represents a stock’s performance versus the S&P 500. As growth traders, we look for an upward trending RS Line.

In addition to MarketSmith, I also use thinkorswim, as I can write scripts to customize the charts, do back-testing and otherwise tinker with the UI. I thought it might be a nice addition to my workspace to show an RS Line indicator.

The calculation of the RS Line couldn’t be easier, divide the stock price by the S&P 500 index value. This is made even simpler as thinkorswim has a study that does the math for you: RelativeStrength.

Given there is a study within thinkorswim, you can simply add the study and you’re good to go. I opted to code the study in thinkscript and reference RelativeStrength as I wanted to add a plot line to indicate the most recent high.

RS Line and Recent High

Here’s how the RS line looks within thinkorswim. The red line is drawn across the most recent high for the timeframe shown.

There is just one option for this study, you can turn on/off the recent high indicator.


Installing the RS Line Study in thinkorswim

If you have thinkorswim installed, click here to install the RS Line study from the thinkorswim Sharing Center.

You can also copy/paste the link into thinkorswim’s Open Shared Item feature, the link is: https://tos.mx/PFemO5w

RS Line thinkscript Code

If you prefer to create your own script in TOS and copy/paste the code, the script is shown below. If you use the code in your own study, it would be appreciated if you keep the header comment with the links intact.

# RS Line and Recent High
#
# Written by:  @JohnMuchow http://twitter.com/JohnMuchow
# Website:     PlayTheTrade.com
#
# v1.0
declare lower;
def nan = Double.NaN;
input showMostRecentHigh = {default "yes", "no"};
plot rslinePlot = reference RelativeStrength("SPX");
rslinePlot.SetDefaultColor(Color.CYAN);
rslinePlot.HideBubble();
rslinePlot.HideTitle();
def recentHigh = HighestAll(rslinePlot);
#--------------------------
# Output 
#--------------------------
AddLabel(1, "RS Line - Price vs S&P 500", rslinePlot.TakeValueColor());
plot recentHighPlot = If (showMostRecentHigh == showMostRecentHigh."yes", recentHigh, nan);
recentHighPlot.hideBubble();
recentHighPlot.HideTitle();

Additional Posts of Interest

4 Comments

  1. Hi John.. Thx for this study. Very useful. While it works on the desktop, somehow on the mobile app, it is not showing the RS line. Would you know why? Thank you!!

    • John

      September 27, 2020 at 5:12 pm

      Hi Shashi, I’ve read about issues others have had with studies on the mobile app. It might be worthwhile to inquire with TDA to see if they have any advice.

  2. This doesn’t appear to render the same scale as MarketSmith ? I saved a screen shot from this mornings IBD live which showed ETSY @ RS Rating of 91. The thinkscript produced a value of 40.2566 (Y value of .042566). Also, how do I get this to auto populate the Y value in the table ?