Download MetaTrader 5

iBarShift returning invalid value

To add comments, please log in or register
You can test an application before buying it. Find out how to do that!
Ex Ovo Omnia
3146
Ex Ovo Omnia 2016.02.05 07:21 

I sometimes (thought rarely) receive "array out of range error" in the following code:

focusedIndex = iBarShift(NULL, 0, focusedDate);
if (focusedIndex>-1) {
   datetime realTime = Time[focusedIndex];
}

which leads me to a question, whether someone has explanation. Perhaps Time[focusedIndex] and iBarShift() work with different chart buffers, and may go out of sync, who knows.

And perhaps iTime() is the only one consistent with the iBarShift(). If there is a difference between Time[] and iTime(), I may be in need of large fixes throughout my entire code. 

Keith Watford
Moderator
9618
Keith Watford 2016.02.05 07:40  
The only case that I can think of your code returning the error would be if it was altered so that iBarShift calculates with a different timeframe.
Ex Ovo Omnia
3146
Ex Ovo Omnia 2016.02.05 07:55  

Not sure if I got your idea properly - what have been altered?

I forgot to mention, that the code was served from the OnChartEvent() function, which might be the weak point.

Keith Watford
Moderator
9618
Keith Watford 2016.02.05 08:19  

I meant if 

iBarShift(NULL, 0, focusedDate)

 was altered to

iBarShift(NULL, PERIOD_H4, focusedDate)

or any other timeframe where the returned shift is larger than the Bars on the current chart 

Ex Ovo Omnia
3146
Ex Ovo Omnia 2016.02.05 08:58  
I see... no, it is not related to this problem, in my case it appears on M1 every time. More likely it is because the i-functions are using different data sets than the arrays (snapshots from different times). I just like to avoid problems caused by mixing them, but any information about data management is lacking.
honest_knave
Moderator
2192
honest_knave 2016.02.05 09:14  
Ovo:
More likely it is because the i-functions are using different data sets than the arrays (snapshots from different times).
While I can't offer you any insight, I did have strong suspicions of this when exploring the problem I posted about the other day (connected and history updated)... results were inconclusive, but it seemed iTime() took longer to update than Time[] even when passing the current chart period to iTime().
To add comments, please log in or register