thanks for your help!
I don't know, it runs correctly here (MC7.0) with an indicator with a user specified MaxBarsBack of 20:
Yes, with a simple indicator, currentbar and MaxBarsBack works like expected at my version (7.4 beta 2). Quite sure I'm doing something wrong here.
Here is the rather simple test code, which generates this strange output:
Code: Select all
Print("CB:",currentbar," MB:", MaxBarsBack);
if currentbar > extATRPeriod then
For cnt=0 to (10+currentbar)
if High[cnt]>HighValue then //High on position cnt higher then previous maximum?
HighValue=High[cnt]; //Store new Maximum
In this example I have set MaxBarsBack by the properties-dialog of the study to an user specific value of 20.
This code does nothing else then constantly finding the Maximum of all bars except the first 10.
For cnt=0 to (10+currentbar) => MaxBarsBack is 20, so this loop should end at the 10th bar of the chart.
Of course there would be a way to avoid this problem, but I'd like to understand, why MaxBarsBack changes the value while the indicator is active and currentbar restarts at 0 at this time. I could not find in EL documentation, what this behaviour could cause.
I really would appreciate, if somebody could give me a hint.