Libraries: iBarShift

 

iBarShift:

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.

Results of the iBarShift benchmark for the 5 versions.

Author: Alain Verleyen

 
Hi Ange, can I ask you as a non-programmer but a curios trader what  is a iBarShift and what benefits  can receive by using this program? Thanks
 
Rosiman:
Hi Ange, can I ask you as a non-programmer but a curios trader what  is a iBarShift and what benefits  can receive by using this program? Thanks

Hi Ronnie,

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.

 
Ok thank you Ange
 

Before you publish code with such loud claims, you should have tested it or something.... It just hangs the terminal:

 
komposter :

Before you post code with such rhetoric, would check it, that is ... He just hangs terminal:

What kind of rhetoric are you talking about?

Don't worry, I checked it. It's not my code that hangs terminal, it's a new MT5/mql5 bug (build 858? - 868).

iBarshift benchmark with build 842

All versions, including yours, are bugged when tested with DateTime not matching the bar open time.

 
There is currently a bug with mql5 build 868 (maybe also 858) which results to a very slow execution of my iBarshift() version. Bug is reported to service desk. All is working well with build 842.
 
angevoyageur:

All versions, including yours, are bugged when tested with DateTime not matching the bar open time.

What does this have to do with the bar open time? What's the error?

 
Can you explain how your Function works in relation to the exact parameter ?  what I mean is what is returned ?  the English Documentation for iBarShift() is incorrect . . .
 
angevoyageur:
There is currently a bug with mql5 build 868 (maybe also 858) which results to a very slow execution of my iBarshift() version. Bug is reported to service desk. All is working well with build 842.

Hi,

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 

thanks

 
DC2008 :

And where is the opening of the bar? What is wrong?

In the example above, this is the M15 time frame, so 21:14 is the time belonging to the bar with 11 shift starting at 21:00, not bar 10 starting at 21:15. You can check what is on the chart and compare with iBarShift () in MQL4.