There is a lot of users who searched for iBarShift function like in MQL4.
But this function is no more include in MQL5, mainly because MQL5 provides all necessary basic, low-level, functions to process such operation in a library.
As an alternative, several programmers provided their MQL5 version. I found 4 different versions from circlesquares, komposter (from Codebase), dc2008 (from famous article Migrating From MQL4 to MQL5) or marketeer (Russian forum).
What I discovered, remarkably, is that all four versions are bugged, in the sense they don't reproduce exactly the MQL4 iBarShift(). Indeed, when the datetime given as input parameter, don't match with the opening of a candle, all versions return a wrong value.
So I decided to make some tests about accuracy and speed of these various functions, and of course to develop my version. You can find attached both the library with this new version, and a little script used to benchmark the functions.
Author: Alain Verleyen
Unfortunately for non-programmer, it's of little interest. iBarshift() is a function who permits to retrieve a bar/candle index from a date/time. It can be used in indicators and EA. There is direct benefit for traders.
the fact that it works well with 842 will not help as everybody is forced to update to latest version, or do you have a method to avoid the live updates?
well done for the updated routine
If the bar having the specified open time is missing, the function
will return -1 or the nearest bar shift depending on the exact.
Yesterday I did a test with build 842 on a MT5 broker. There is not yet an update to build 858/868.
If you are using Metaquotes demo-server then the update is immediate, but not with "normal" brokers, at least for some of them.
ah! okay, I understand the brokers control the update to their users when they are ready.
Yes, the Russian translated via Google tells a different story . . .
Search bar at the time. The function returns the offset of the bar, which owns the specified time. If there is no specified time bar ("hole" in the story), the function returns, depending on the parameter Exact , -1 or offset the nearest bar.
. . . it's not about the Open time but about the time being within the life of a bar . . .