I’m a huge fan of Investors.com MarketSmith charting application. Their implementation of a Relative Strength Line (RS Line) is my go-to indicator.

In MarketSmith, the RS Line represents a stock’s performance versus the S&P 500. If you are looking at a weekly chart, the RS Line is the performance of the stock over the past week versus the S&P 500 over that same time frame. The same logic applies to the daily and monthly charts, only the time frames are different.

If a stock moves up for the day/week/month and the S&P 500 does not, the RS Line will move up. If a stock ends the day/week/month flat, yet the S&P 500 moves up, the RS Line will go down.

I use TradingView as a means to create my own indicators through their scripting language, Pine Script. With my fondness of the RS Line in MarketSmith, I thought I’d share an RS Line indicator for other TradingView users.

Head over to TradingView to install the RS Line indicator .


MarketSmith RS Line

One primary goal was to create an indicator with a similar look and feel as the RS Line in MarketSmith. Here’s a screenshot of Shopify (SHOP) with the RS Line shown in the gray box:

Compare and contrast the chart above to the RS Line indicator for TradingView:


RS Line Customizable Settings

I’ve added two features to my custom RS Line script. First, I added an option to show the RS Line with colors that indicate the direction of each move.

Second, the RS Line can be moved up/down on the chart. This can be helpful based on the resolution you are viewing (daily, weekly, etc).


RS Line in Pine Script

The code for the RS Line is shown below. If you use the code in your own indicator, please keep the header comment with the links intact.

//@version=4

// Please don't remove this header comment 
//
// This Relative Strength Line (RS Line) indicator is designed to mimic 
// the RS Line information as shown on Investors.com MarketSmith charting application.
//
// The RS Line represents a stock’s performance versus the S&P 500. 
// If you are looking at a weekly chart, the RS Line is the performance of 
// the stock over the past week versus the S&P 500 over that same time frame. 
// The same logic applies to the daily and monthly charts, only the time frames are different.
//
// If a stock moves up for the day/week/month and the S&P 500 does not, 
// the RS Line will move up. If a stock ends the day/week/month flat, 
// yet the S&P 500 moves up, the RS Line will go down.
//
// The daily chart can have a little more “noise” as it reflects price movements
// on a more frequent basis. Look to the weekly and monthly RS Line to 
// get a view of the longer term trend.
//
// v1 - Original release
// v2 - Enable editing of plot line so color can be changed
// v3 - Add support for any index. Change default line color to dark gray (works with dark or light mode)

study(title = "RS Line - Gauge Performance vs S&P 500", shorttitle = "RS Line", overlay = true, max_bars_back = 100)

//---------------------------------------------------------
// User configurable values and variable initialization
//----------------------------------------------------------
iIndex = input(title="Index", type = input.symbol, defval="SPX")
iOffset = input(title = "Vertical offset of RS Line", type = input.integer, minval = 1, maxval = 50, defval = 25)
iChangeColor = input(title = "Change color based on direction?", type = input.bool, defval = false)

var float previousRatio = 0

//---------------------------------------------------------
// Calculations
//----------------------------------------------------------
spx = security(iIndex, "D", close)

// RS Line ratio
ratio = (close / spx) * 100

//---------------------------------------------------------
// Plot the RS Line using the requested offset and color
//----------------------------------------------------------
ratioColor = iChangeColor ? (ratio > previousRatio?  color.green : color.red) : #C6C8CC
plot(ratio * iOffset, color = ratioColor, title ="RS Line", editable = true)

// Save ratio for next bar comparison
previousRatio := ratio

RS Line – Live in TradingView

You can find the RS Line, and the Pine Script code, on my PlayTheTrade profile in the scripts area of TradingView.

The chart below is a live view of the RS Line in TradingView.