What’s the correct way of getting previous values of an indicator?
- This topic has 3 replies, 2 voices, and was last updated 2 years ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
Forums › ProRealTime English forum › ProBuilder support › What’s the correct way of getting previous values of an indicator?
Hi all
I’m trying to get the values of previous bars of an indicator, and this is what I’m trying to do:
ema100 = ExponentialAverage[100](close)
ema100_20barsbefore = ema100[20]
Is this correct?
Also how do I check if an indicator actually has a value at a certain point? Like at the start of the day maybe some indicators don’t have values yet, and if I do indicator[20] its value maybe invalidate because of that.
Your code is correct.
I am not sure I understood your second question. If you check your chart you will spot the value retained now by any variable and the one of the 20th previous bar. Is this what you meant?
Thanks <span class=”bbp-author-name”>robertogozzi</span>
What I mean by 2nd question is that, sometimes an indicator may not have values.
For example, ExponentialAverage[100](close) don’t have values for the initial bars, not sure if it’s exactly 100 bars or some other value. If you move your mouse cursor to the bars in the beginning, in the values displayed(open, close etc) it doesn’t have a value. Not sure if this is something I’m doing wrong.
And the weird thing is, when I try make a simple indicator that checks if some indicator has value, such as ema100 > 0, it correctly detects that at first the indicator doesn’t have value for certain number of bars. But when I try to use the exact checking logic to do backtest, it would generate orders at bars where clearly there’s no indicator value.
I think this is due to the fact that ProOrder and ProBackTest preload form 2000 bars (default) up to 10K bars. Try using this line at the beginning of your code:
1 |
DEFPARAM PreLoadBars = 0 //10000 max allowed |