iBarShift - library for MetaTrader 5

iBarShift - library for MetaTrader 5

There are a lot of users who searched for iBarShift function like in MQL4.

But this function is not included 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 dont reproduce exactly the MQL4 iBarShift(). Indeed, when the datetime given as input parameter, dont 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.

As a side note, iBarShift() isnt always the best way to realize some task in MQL5. Depending of your algorithm, there can be better method.

Edit: 2014.10.03. Version 1.02 posted (fixed a bug if requested time is superior to last bar start time).

Download iBarShift - library for MetaTrader 5

Related News

Latest News
UBS Sees Risk of Swiss Recession If Virus Hits Europe Hard
26.02.2020 17:18
(Bloomberg) -- Switzerland faces the risk of a recession if the coronavirus outbreak leads to quarantines or businesses closures in Europe, according to UBS Group AG. Europe is already on high alert amid a rise in cases, with Italy forced to put some of the country into lockdown. While supply chain disruptions in Asia probably won’t have a major
Read more
Retail Sales to Overcome Uncertainties Like Coronavirus to Rise in 2020
26.02.2020 17:15
By Kim Khan Investing.com – U.S. Retail sales will continue to climb this year, overcoming uncertainty due to the coronavirus, trade wars and the presidential election, the National Retail Federation said Wednesday. Sales will rise 3.5% to 4.1% to between $3.93 trillion and $3.95 trillion in 2020, the NRF said. Online sales will be up
Read more
U.S. retail sales expected to cross $3.9 trillion in 2020: NRF
26.02.2020 17:12
(Reuters) - U.S. retail sales are expected to rise between 3.5% and 4.1% to more than $3.9 trillion this year, the National Retail Federation (NRF) said on Wednesday, despite fears surrounding the coronavirus outbreak. The trade body expects sales to be between $3.93 trillion and $3.95 trillion, citing steady wage growth and consumer confidence
Read more
Enel agrees on need to provide Italy with ultrabroadband network
26.02.2020 17:09
MILAN (Reuters) - Italy's Enel (MI:ENEI) said on Wednesday it agreed on the need to provide the country with an ultrabroadband network, after Economy Minister Roberto Gualtieri urged parties involved in the plan to find an agreement. Open Fiber, jointly owned by utility Enel and state lender CDP, is spending billions of euros to build an
Read more
Climate change could add around $100 billion to costs of extreme weather
26.02.2020 17:06
LONDON (Reuters) - Climate change could add around $100 billion, or more than 20%, to the global cost of extreme weather events such as floods, heatwaves and droughts by 2040, research from Cambridge University showed on Wednesday. The findings come from the university's Climate Change Business Risk Index, which uses climate modeling data to
Read more