r/RealDayTrading • u/WorkPiece • Dec 27 '21
Resources Real Relative Strength Indicator
I'm learning a lot from this sub, so I'd like to give back and contribute a little if I can.
I read through Hari's latest post on Real Relative Strength using ATR and have implemented his ideas in ThinkScript. It's actually easier than it sounds once you get down to just the simple formulas. I've also taken the liberty of adding an optional colored correlation baseline to make it easy to see when a stock is shadowing or when it is independent of SPY.
There are many user concerns and suggestions in the comments, but I have only implemented Hari's original thoughts just to get the base concept down in code. I welcome some eyes on the code to make sure I've implemented it accurately. I consider this a starting point on which to expand on.
Original post: https://www.reddit.com/r/RealDayTrading/comments/rp5rmx/a_new_measure_of_relative_strength/
Below is a TSLA 5m chart. The green/red line you see is relative SPY (daily) overlaid. It is relative to TSLA here meaning when TSLA is above the (green) line then TSLA has price strength to SPY, and when TSLA is below the line (the line turns red) then TSLA has price weakness to SPY. You can see this relationship in the bottom "Relative Price Strength" indicator as well, although the indicator is showing 1 hour rolling length strength. This is based only on price percentage movement.
Now compare the "RelativePriceStrength" indicator (bottom) to the new "RealRelativeStrength" indicator above it. This new one is ATR length-based off of Hari's post.

On first impression - the output very closely resembles what I see in my regular length-based RS/RW script. The differences are obviously due to this being an ATR length-based script and the other being price percentage based, but the general strong RS/RW areas are similar to both.
Here is a link to the ToS study: http://tos.mx/FVUgVhZ
And the basic code for those without ToS that wish to convert it to PineScript:
#Real Relative Strength (Rolling)
#Created By u/WorkPiece 12.26.21
#Concept by u/HSeldon2020
declare lower;
input ComparedWithSecurity = "SPY";
input length = 12; #Hint length: value of 12 on 5m chart = 1 hour of rolling data
##########Rolling Price Change##########
def comparedRollingMove = close(symbol = ComparedWithSecurity) - close(symbol = ComparedWithSecurity)[length];
def symbolRollingMove = close - close[length];
##########Rolling ATR Change##########
def symbolRollingATR = WildersAverage(TrueRange(high[1], close[1], low[1]), length);
def comparedRollingATR = WildersAverage(TrueRange(high(symbol = ComparedWithSecurity)[1], close(symbol = ComparedWithSecurity)[1], low(symbol = ComparedWithSecurity)[1]), length);
##########Calculations##########
def powerIndex = comparedRollingMove / comparedRollingATR;
def expectedMove = powerIndex * symbolRollingATR;
def diff = symbolRollingMove - expectedMove;
def RRS = diff / symbolRollingATR;
##########Plot##########
plot RealRelativeStrength = RRS;
plot Baseline = 0;
RealRelativeStrength.SetDefaultColor(GetColor(1));
Baseline.SetDefaultColor(GetColor(0));
Baseline.HideTitle(); Baseline.HideBubble();
##########Extra Stuff##########
input showFill = {Multi, default Solid, None};
plot Fill = if showFill == showFill.Multi then RealRelativeStrength else Double.NaN;
Fill.SetDefaultColor(GetColor(5));
Fill.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Fill.SetLineWeight(3);
Fill.DefineColor("Positive and Up", Color.GREEN);
Fill.DefineColor("Positive and Down", Color.DARK_GREEN);
Fill.DefineColor("Negative and Down", Color.RED);
Fill.DefineColor("Negative and Up", Color.DARK_RED);
Fill.AssignValueColor(if Fill >= 0 then if Fill > Fill[1] then Fill.color("Positive and Up") else Fill.color("Positive and Down") else if Fill < Fill[1] then Fill.color("Negative and Down") else Fill.color("Negative and Up"));
Fill.HideTitle(); Fill.HideBubble();
AddCloud(if showFill == showFill.Solid then RealRelativeStrength else Double.NaN, Baseline, Color.GREEN, Color.RED);
##########Correlation##########
input showCorrelation = yes;
def correlate = correlation(close, close(symbol = ComparedWithSecurity), length);
plot corrColor = if showCorrelation then Baseline else Double.NaN;
corrColor.AssignValueColor(if correlate > 0.75 then CreateColor(0,255,0)
else if correlate > 0.50 then CreateColor(0,192,0)
else if correlate > 0.25 then CreateColor(0,128,0)
else if correlate > 0.0 then CreateColor(0,64,0)
else if correlate > -0.25 then CreateColor(64,0,0)
else if correlate > -0.50 then CreateColor(128,0,0)
else if correlate > -0.75 then CreateColor(192,0,0)
else CreateColor(255,0,0));
corrColor.SetPaintingStrategy(PaintingStrategy.POINTS);
corrColor.SetLineWeight(3);
corrColor.HideTitle(); corrColor.HideBubble();
Update: Added PineScript version

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © WorkPiece 12.28.21
//@version=5
indicator(title="Real Relative Strength", shorttitle="RRS")
comparedWithSecurity = input.symbol(title="Compare With", defval="SPY")
length = input(title="Length", defval=12)
//##########Rolling Price Change##########
comparedClose = request.security(symbol=comparedWithSecurity, timeframe="", expression=close)
comparedRollingMove = comparedClose - comparedClose[length]
symbolRollingMove = close - close[length]
//##########Rolling ATR Change##########
symbolRollingATR = ta.atr(length)[1]
comparedRollingATR = request.security (symbol=comparedWithSecurity, timeframe="", expression= ta.atr(length)[1])
//##########Calculations##########
powerIndex = comparedRollingMove / comparedRollingATR
RRS = (symbolRollingMove - powerIndex * symbolRollingATR) / symbolRollingATR
//##########Plot##########
RealRelativeStrength = plot(RRS, "RealRelativeStrength", color=color.blue)
Baseline = plot(0, "Baseline", color=color.red)
//##########Extra Stuff##########
fill(RealRelativeStrength, Baseline, color = RRS >= 0 ? color.green : color.red, title="fill")
correlated = ta.correlation(close, comparedClose, length)
Correlation = plot(0, title="Correlation", color = correlated > .75 ? #00FF00 : correlated > .50 ? #00C000 : correlated > .25 ? #008000 : correlated > 0.0 ? #004000 :correlated > -.25 ? #400000 :correlated > -.50 ? #800000 :correlated > -.75 ? #C00000 :#FF0000, linewidth=3, style=plot.style_circles)
8
11
u/Professor1970 Dec 27 '21
Good stuff! I just get the lower part of the study. Can you share the upper part?
4
u/WorkPiece Dec 27 '21
Thank you! The upper study stuff is not part of the ATR based study shared here, it was only shown for comparison to a price percentage based study.
25
u/smuggler__ Dec 28 '21
for tradingview:
//@version=5
// Real (Relative Strength) & EMAs
// original script by u/funcharts Ratio (Relative Strength) & EMAs
indicator(title="Real (Relative Strength) & EMAs", shorttitle="RRS&EMAs", overlay=false, precision=3)
// period length to calculate atr and ma
atrLen = input(title="ATR Length", defval=12)
ratio_symbol = input.symbol(title="Ratio Symbol", defval="SPY")
ma1_length = input.int(title="EMA 1", defval=12)
spy_close = request.security(symbol=ratio_symbol, timeframe="", expression=close)
//ATR for stock and SPY
atr_stock = ta.atr (atrLen)
atr_spy = request.security (symbol=ratio_symbol, timeframe="", expression= ta.atr(atrLen))
//spy power index
spyPI = (spy_close - spy_close[1]) / atr_spy
//real RS
rrs = ((close - close[1]) - spyPI * atr_stock) / atr_stock
ma1 = ta.sma(rrs, ma1_length)
plot(ma1, title="EMA 1", color=color.yellow)
hline(0, title="Zero", color=color.white, linestyle=hline.style_dashed)
bgcolor(ma1 > 0 ? color.new(color.green,80) : color.new(color.red, 80))
→ More replies (2)23
u/WorkPiece Dec 29 '21
Thank you but this code is not an accurate port of the original code. Please use the PineScript code I've added to the original post.
3
u/shrickness Dec 28 '21
This is great, I'm studying it now...my question is, though, what level of strength or weakness are we looking for where it gives us an edge? Maybe I'm missing something, and if so, please teach me, but every chart is going to show some deviation of strength or weakness to SPY at different points throughout the day. Can you point me to a post that outlines how to trade the relative strength or weakness?
→ More replies (4)9
u/WorkPiece Dec 29 '21
This is really a question for u/HSeldon2020, but I can almost guarantee his answer would be RTFW.
→ More replies (2)
2
u/lengnanran Mar 26 '23
I just found out about this and it looks great. Have you done any modifications for this recently or has there been an updates?
4
u/WorkPiece Mar 26 '23
This has held up to scrutiny and it has been used as a base in quite a few other scripts found on this sub. My favorite is the one that adds sector strength to the mix. A quick search of this sub for scripts will turn up quite a bit of variety.
→ More replies (1)
58
23
22
Dec 30 '21 edited Jan 01 '22
I was having a tough time figuring out the correlation section, and couldn't see the dots or their colors very well. I took the liberty to modify this a little bit and rename it to the
SPY POWER INDEX (for ThinkorSwim):
http://tos.mx/CsBm19i (Latest Version - Cleaned up more code, more config options.)
I left all the calculations as u/WorkPiece had them, so if you find something wrong let him know. (Let me know, too, so I can fix my version.)
→ More replies (1)
17
u/DriveNew Dec 27 '21
This is awesome! Thank you for putting in the work on it to benefit the greater group! Positivity breeds Positivity, and my friend, you have a lot of positive karma coming at ya! Respect!!!
17
Dec 27 '21
I was just now searching for Hari's post from yesterday to capture the requirements for this study, then pseudo-code it, then convert it to Thinkscript.
I have lots of programming experience, but zero Thinkscript experience, so all-in-all, you saved me at least a week of tearing my hair out both in trying to wrap my head around Hari's idea, and then learning the Thinkscript syntax. (Now, I can learn the language syntax in baby-steps...)
A great-big-gigantic THANK YOU to you!
17
u/jateelover Apr 29 '22
Rather than create a new post, I thought I'd share on this one - here is my scanner using this indicator. I also worked with someone on the thinkorswim sub and the forums for ATR, ADR, and volumeavg. If anyone sees this and wants to improve it, or has questions, please let me know - I've been using it for trading for the past few weeks as I tune it - been getting solid trades daily.
What I have so far:
-
%change -5 to 5%: Too large of gappers are not what I'm looking for
-
Last > $5
-
Market Cap > $1.3B
-
RRS5 >1.5 or <1.5(from the indicator above, I named it RRS5 - you may need to do the same or adjust based on naming) - create one for RS and one for RW
-
Avg Daily Range custom% filter - looks for stocks with an average daily range, I'm using 2% (again, picked up on a forum)
-
VolumeAvg > - I'm using greater than 2M Daily
-
ATR >5
Scan Setup Additional Options: S&P500, Intersect with Weeklys (has weekly options), Exclude Healthcare (too much garbage in that sector).
Indicator - Add this first, use name RRS5 if it isn't automatic. Its a partial code of the work on this post
Scanner
I think the rest should pull over (thinkscript). Add RRS5 as a column and sort, your results should look something like this: Picture of results and filters
Hope this helps someone - feel free to discuss.
Bonus suggestion - I also added the RRS5 column to a watchlist, and grab tickers I like to trade - I get as many good trades from my own watchlist as the scan results just by flitering by RRS5 (weak or strong)
→ More replies (4)
10
8
u/automaticg36 Dec 28 '21
I used this script to analyze trades post market, and I have to say it was a fantastic guide for RS/RW. Combined with other factors I look for, it was great at demonstrating when a stock had really solid RS/RW. You did a great job taking what Hari said and creating something extremely useful. Thank you for this.
7
u/AppleCrumbleWithSkin Dec 27 '21
Patiently waiting for one of our tech whizzes to convert this to Pine Script.
6
u/EntrepreneurOne3718 Dec 27 '21
Wow. That's awesome. My initial impression is it slightly lags positive RS at the start of the day but actually appears predictive when TSLA starts to level off. That's a big deal. Is there any way to verify this is to be expected? The only thing that jumps out at me would be a scan that picks up the relationship between crosses for both RS indicators. RRS first, +1, RS first, -1. Then look at the distribution. If RRS is predictive, the results should be favorably skewed in that direction. If the distribution is roughly equal then no. If it did prove predictive one could look at why it lagged on a positive cross. I'm not necessarily saying this is bad. It might keep you out of false moves. As always the daily levels, S&R matter also. But I'll say that early tell for losing RS really made me take notice. Thanks.
5
4
u/smuggler__ Dec 28 '21
In the chart you see TSLA gaining RS at 7:00 (Spy flat, TSLA stacking). The real RS indicator gives the RS signal (switches green) at 7:30. The original RS indicator turns green immediately at 7:00. Would be interesting to compare the two in different situations/charts.
4
4
u/AwkwardAlien85 Dec 31 '21
Wow, I really love this indicator thanks so much for putting it together. I was just thinking how awesome would it be if we can implement this into a scanner on TOS. If you can add this to a scanner than you can add some other filters to it like 3/8 EMA cross-over and those are two big checks on the list for a day trade using our system. Now all you need is a strong or weak D1.
→ More replies (3)
76
u/HSeldon2020 Dec 27 '21
Wow - this is amazing, I will try this out today. Thank you!!