Download MetaTrader 5

Libraries: iBarShift

To add comments, please log in or register
Automated-Trading
Admin
105110
Automated-Trading  

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

Ronnie Mansolillo
5625
Ronnie Mansolillo  
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
Alain Verleyen
Moderator
32825
Alain Verleyen  
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.

Ronnie Mansolillo
5625
Ronnie Mansolillo  
Ok thank you Ange
Alain Verleyen
Moderator
32825
Alain Verleyen  
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.
Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
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 . . .
Paul Anscombe
4257
Paul Anscombe  
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

Alain Verleyen
Moderator
32825
Alain Verleyen  
RaptorUK:
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 . . .
When you said that mql4 documentation is incorrect, are you referring to ?

If the bar having the specified open time is missing, the function will return -1 or the nearest bar shift depending on the exact.

So my function returns exactly the same as mql4 version. If exact is false, it returns the shift of the bar containing the time value and not necessarily the nearest bar shift.
Alain Verleyen
Moderator
32825
Alain Verleyen  
MaxTrader:

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

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.

Paul Anscombe
4257
Paul Anscombe  
angevoyageur:

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.

 thanks 

Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
angevoyageur:
When you said that mql4 documentation is incorrect, are you referring to ?

"If the bar having the specified open time is missing, the function will return -1 or the nearest bar shift depending on the exact."

So my function returns exactly the same as mql4 version. If exact is false, it returns the shift of the bar containing the time value and not necessarily the nearest bar shift.

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 . . .

12
To add comments, please log in or register