2 different dates for 1st bar - page 2

 

I have had similar problems before, I think if your indicator tries to access a bar which is not in the chart it will give a default date of that 1970's date.

This might occur if you use buffer[i+1] type calculations. Obviously when your indicator begins on the first bar of the chart which has number 64999, buffer[i+1] is looking for bar number 65000 which does not exist. Similar problems might occur with moving averages.

I get around this in my indicators like this at the beginning of the main indicator loop:

if(i>Bars-drawbegin-1) continue;

drawbegin is set earlier to not draw however many bars are used as "lookback" bars so not only does the indicator not try to draw lines for those bars, the indicator loop ignores them too so when it starts there are enough previous bars available for calculations that need them.

 
SDC:
I get around this in my indicators like this at the beginning of the main indicator loop:
if(i>Bars-drawbegin-1) continue;

drawbegin is set earlier to not draw however many bars are used as "lookback" bars so not only does the indicator not try to draw lines for those bars, the indicator loop ignores them too so when it starts there are enough previous bars available for calculations that need them.
Or the equivalent
iCountedBars = MathMax(IndicatorCounted(), drawbegin);
for (int iBar = Bars -1 -iCountedBars; i >= 0; i--){ ...
 

WHRoeder:
Or the equivalent

iCountedBars = MathMax(IndicatorCounted(), drawbegin);
for (int iBar = Bars -1 -iCountedBars; i >= 0; i--){ ...



Yes thats even better, more efficient outside the loop ...