Apply moving average to relative strength (correlation) indicator


Category:
0
0

Hi Pete, I’m trying to figure out how to apply a moving average to a relative strength (correlation) indicator. I have a security eg SPY in the main chart. The lower RS indicator has SPY:GLD. When I add the MA, to the RS, it’s the one for SPY or whatever security in in the main chart. Can you advise how to get it for the RS indicator. I appreciate your help. Thanks!

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 12, 2017 8:31 pm
845 views
1
Private answer

Great question. Be sure to check out the video we did on a scan for the relative strength. It is important to view this video to understand there is a default “starting point” for relative strength and we can manipulate that in the code: https://www.hahn-tech.com/thinkorswim-scan-relative-strength/

As for your request. This is the standard built in version of Relative Strength with two additional inputs for length and average type. At the end we append a new statement that plots the average of the RS plot.

Don’t forget to up-vote and answers that best solve your question!

#
# TD Ameritrade IP Company, Inc. (c) 2008-2017
#
declare lower;
input CorrelationWithSecurity = "GLD";
input length = 21;
input averageType = AverageType.SIMPLE;
def close2 = close(CorrelationWithSecurity);
plot RS = if close2 == 0 then 0 else close/close2;
RS.setDefaultColor(GetColor(6));
def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);
plot SRatio = sr;
SRatio.setDefaultColor(GetColor(5));
plot averageRS = MovingAverage(averageType, RS, 21);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 12, 2017 8:52 pm
0

Thanks Pete. Much appreciated!

( at April 12, 2017 9:58 pm)