TradingView
Amphibiantrading
Jul 3, 2023 2:17 AM

Webby's RS Line 

Invesco QQQ Trust, Series 1NASDAQ

Description

The Relative Strength (RS) line is something many investors are familiar with. It is used to measure a stocks performance versus the S&P 500 and is typically calculated by dividing the closing price of the stock by the closing price of the S&P. This means if a stock moves up and the S&P moves down or the stock moves up more than the S&P the RS line will increase, if the stock moves down while the S&P moves up the line will decrease.

While the standard RS line is a powerful tool, Mike Webster recently discussed how he has made changes to the standard RS line and also uses a 21 exponential moving average of the RS line to help guide his decision making. This script puts those new twists on the standard RS line, by first calculating the RS line using the low of both the security and the S&P rather than the closing prices. Next it measures the 21-day exponential moving average of the RS line and plots the distance between the two as a histogram.

A strong trending stock that is out performing the market will see an extended period of a positive blue histogram signifying the RS line is above the 21-ema.



While on the other hand a stock in a downtrend that is underperforming will see a negative red histogram a red histogram signifying the RS line is below the 21-ema.


On top of all of that, the indicator also keeps 3 & 13 exponential moving average of the distance between the RS line and the 21 ema to help identify shorter term relative strength and capture more immediate shifts in momentum. Both of those are plotted on the histogram as well and will change color as they rise and fall making it easy to spot the direction.

Indicator options include:
  • Choose symbol to measure performance against
  • Change histogram colors
  • Choose ema line width


* Note this indicator does not plot the actual RS line, it is the histogram representing the distance between the RS line calculated using the lows and the 21 ema, as well as the two ema's of the relationship.

Release Notes

Update the name of the ema plots.
Comments
bartt59
Got my first alert (EMA1 cross above EMA2) today. I was about to message you when I first viewed the chart and saw these EMAs were nowhere n
illy5d
can you make it so we can change colors of the 3 and 13 ema?
Amphibiantrading
@illy5d, sure, I can add that option this week
bartt59
When attempting to set an alert for the crossing of the 2 ema plots I see "plot" listed twice. If I select the first "plot" and crossing I see "plot" listed only once and select it. Am I really setting the alert for the crossing of these 2 ema lines ?
Amphibiantrading
@bartt59, I just made a quick update to update the name of the plots. You should see Distance, EMA1 and EMA2 now
bartt59
@Amphibiantrading, Many thanks ! Perfect. Is there a way to point the ema1 crossing ema2 alert at a watchlist as opposed to single tickers only ?
Amphibiantrading
@bartt59, unfortunately we are only able to do single tickets. I hope they bring the capability to do a whole watchlist soon though. Would be an awesome feature
bartt59
@Amphibiantrading, agree ! Are you be able to convert this to thinkscript ? I am not fully code capable, more like code destroyer.
Amphibiantrading
@bartt59, I should be able to. Let me see when I get to my desk tomorrow and I’ll send you a Dm
bartt59
@Amphibiantrading, were you able to translate to ThinkScript ? I asked Chat GPT to translate. Have not had good results doing so. Let me know if it meets your approval. Thanks.
Here's the equivalent ThinkScript code for the provided Pine Script:

thinkscript
Copy code
# Webby's RS Line

declare lower;

# inputs
input index = "SPX";
input Color upColor = Color.BLUE;
input Color downColor = Color.RED;
input int emaWidth = 1;

# calculations
def spx = close(index);
def rs = (close / spx) * 100;
def ema = ExpAverage(rs, 21);
def dist = ((rs - ema) / rs) * 100;
def ema1 = ExpAverage(dist, 3);
def ema2 = ExpAverage(dist, 13);

# colors
def histCol = if dist > 0 then upColor else downColor;
def ema1Col = if ema1 > ema1[1] then Color.GREEN else Color.RED;
def ema2Col = if ema2 > ema2[1] then Color.GREEN else Color.RED;

# plots
plot Distance = dist;
Distance.SetDefaultColor(histCol);
Distance.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Distance.SetLineWeight(2);

plot EMA1 = ema1;
EMA1.SetDefaultColor(ema1Col);
EMA1.SetLineWeight(emaWidth);

plot EMA2 = ema2;
EMA2.SetDefaultColor(ema2Col);
EMA2.SetLineWeight(emaWidth);
More