iBarShift returning invalid value

Back to topics list To post a new topic, please log in or register
avatar
1109
Ovo 2016.02.05 08: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. 

 

avatar
Moderator
3404
GumRai 2016.02.05 08: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.
avatar
1109
Ovo 2016.02.05 08: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.

avatar
Moderator
3404
GumRai 2016.02.05 09: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 

avatar
1109
Ovo 2016.02.05 09: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.
avatar
735
honest_knave 2016.02.05 10: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().
Back to topics list  

To add comments, please log in or register