Hello,
In the onCalculate method I often want to see for example the value of a moving average 10 bars back. To do that I have a loop that I run for every tick!
It is quite inefficient, as I calculate the same thing over and over again. Is there any way to pass previous calculations to the next bar?
Cheers
Why do you think that you have to loop back?
You don't have to loop back : simply use i+10 in the index (just make sure that i+10 is < Bars)
Ok, so I was not clear. For each bar I want to check i+1, i+2, i+3...i+20. So not just the 20th bar back but all bars back up to the 20th.
Imagine that I just want to check if fast MA(5) is below slow MA(10) for every of the 20 bars back. If there was a way to pass previous calculations maybe I wouldn't need to loop 20 bars back for every onCalculate call but implement some smarter algorithm.
Cheers
dmdamiyo: I have a loop that I run for every tick! It is quite inefficient, |
|
So I should have a global variable | What part of " add a non-visible buffer" was unclear? |
I should calculate only bar 0 in onCalculate | I didn't say that. After the initial run it should only be doing bar zero. No mind readers here, we can't see your code. |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
In the onCalculate method I often want to see for example the value of a moving average 10 bars back. To do that I have a loop that I run for every tick!
It is quite inefficient, as I calculate the same thing over and over again. Is there any way to pass previous calculations to the next bar?
Cheers