Austin, TX
Experience: Advanced
Platform: ThinkOrSwim
Trading: Currency, index, commodity futures
Posts: 9 since Mar 2012
Thanks Given: 18
Thanks Received: 8
|
Hi, this seems to work. You can adjust the length and type of moving average if needed. The additional code is shown in bold.
Best of luck to you.
# RelativeStrength_with_MA
declare lower;
input length = 50;
input averageType = AverageType.Simple;
input CorrelationWithSecurity = "SPX";
def close2 = close(CorrelationWithSecurity);
plot RS = if close2 == 0 then 0 else close/close2;
plot RSavg = MovingAverage(averageType, RS, length);
RS.setDefaultColor(GetColor(6));
RSavg.setDefaultColor(Color.RED);
def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);
plot SRatio = sr;
SRatio.setDefaultColor(GetColor(5));
|