♥ 0 |
In something I have been working on, I have to (a) determine the closing price x bars ago – ie. close[x] (b) find the average closing price since that date . average(close,x) x was determined through my code and so is not a constant, which Think Script needs in these situations. From your answers to others I could learn that using getValue() solves my problem(a). But I could not find a solution for problem (b) so far – i.e.for average(close,x). Hope you can also refer me to some of your indicators where you solved this issue, so that I can learn using your examples
Thanks Arun.
Marked as spam
|
Private answer
There may not be a solution to this. But I have an idea. I will need to see the rest of your code in order to know if my solution will work. I understand you probably don’t want to make that public. So you may have to submit a project request and handle this as a paid solution. I haven’t solved this before so I have not examples to offer for you to review. About the only thing I can imagine that we could use is the fold statement. Which is Thinkorswim’s low tech way of looping through bars on the chart. You can read about it here: http://toslc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/fold.html If we could perform real loop statements in Thinkorswim this would be easily solved. Marked as spam
|
Please log in to post questions.
Yes, the last parameter of CompoundValue initializes the value of the first bar, but only if the first parameter is set to 1 (first bar). You may also use an if statement as the last parameter. You will find there is a lot more to this if you experiment. So you can set the first parameter to 5 and use a recursive if statement in the third parameter to determine the value of those first 5 bars.
Very happy to hear you remembered to use the debugging method I described earlier. I use that for every single project I do. Nice work. You should post that as a New Answer instead of just a comment. Since you did come up with a solution. Have fun!