TOS CompoundValue code for RelativeStrength


Category:
0
0

Why does TOS use Compound Value function in their code for the RelativeStrength Study instead of a simple code as follows:

def rStrength = close/close(“SPX”) ;

Plot ans = rStrength;

 

Marked as spam
Posted by (Questions: 11, Answers: 16)
Asked on January 7, 2020 9:44 pm
654 views
0
Private answer

Well that would be a question best answered by TD Ameritrade themselves. But since you posted the question here I will explain that this line of code does:

Taken from the RelativeStrength chart study in Thinkorswim

def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);

This is a recursive statement. This is used to initialize the sr variable. In the case that the previous value of sr is Double.NaN, the statement substitutes the value of the RS variable in its place (the first bar on the chart). The sr variable is used to plot the flat horizontal red line, via the plot named "SRatio". This plot merely shows the starting value for the RS plot. The RS plot is the actual value of relative strength and does not require recursive statements in its computation.

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 9, 2020 11:52 am
0
I got it. Thank you.
( at February 3, 2020 6:12 pm)
0
Hello Pete. How can I make the "sr" plot from the First Bar TODAY (NOT vs Visible Data)? So if I am on a two or three day view on my chart it will plot for the current session only? Tks
( at March 24, 2022 7:57 am)
0
You can find an example of something similar in the code I published with the following video: https://www.hahn-tech.com/thinkorswim-scan-relative-strength/ However it does not work on intraday time frame. You would need to further modify the code to include an input to set the start time in addition to the start date. But this indicator is intended to be used on a daily time frame or higher in the first place. So that is not something I am interested in publishing.
( at March 24, 2022 8:20 am)
0
Thanks. Used the scan as an example and solved it.
( at March 24, 2022 8:48 am)