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:

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
# Website:
# v1.0

declare lower;
def nan = Double.NaN;
input showMostRecentHigh = {default "yes", "no"};

plot rslinePlot = reference RelativeStrength("SPX");
def recentHigh = HighestAll(rslinePlot);

# Output 
AddLabel(1, "RS Line - Price vs S&P 500", rslinePlot.TakeValueColor());

plot recentHighPlot = If (showMostRecentHigh == showMostRecentHigh."yes", recentHigh, nan);

Additional Posts of Interest