thanks for the reply , i think that's passed by default as false , specifying false did not change the behavior.
I just realized that you have "mq4" in your code header.
This is the MT5 subforum, so I deleted my Post #1 regarding MQL5 code.
I stopped coding MQL4 years ago. Hopefully someone else can chime in to help you.
@Moderators, please move this thread to the MT4 subforum.
thanks for the reply , the same code can be used on MQL5 it's just been written on mq4 editor
You're welcome.
Not exactly the same (pun intended). I compiled an mq5 file today from the CodeBase that was missing an exact in iBarShift(), and the Compiler threw an error. I fixed it by adding the exact.
A moderator corrected the formatting this time. Please format code properly in future; posts with improperly formatted code may be removed.
Three issues in your code:
1. RoundUpTime() is broken for aligned times
Your loop increments by exactly 60s, so CountedDatetime is always on a minute boundary. remainder = 0, so the function always adds a full extra minute — skipping every bar. Drop it, or use floor rounding:
datetime FloorTime(datetime time, ENUM_TIMEFRAMES period) { long s = PeriodSeconds(period); return (datetime)(time - time % s); }
2. Decreasing shifts = correct behavior
Shift 0 is the current bar, higher = older. Iterating forward in time gives naturally decreasing shifts. Not a bug.
3. Different shifts per symbol = normal
EURUSD shift 25055 vs NZDUSD shift 2745 at the same datetime just means each symbol has a different amount of M1 history loaded. They're correct individually.
Better approach for multi-symbol iteration — iterate by shift, not by time:
for(int sym = 0; sym < ArraySize(SymbolsList); sym++) { string symbol = SymbolsList[sym]; int startShift = iBarShift(symbol, PERIOD_M1, StartDate, false); for(int shift = startShift; shift >= 0; shift--) { datetime barTime = iTime(symbol, PERIOD_M1, shift); // process here } }
Also ensure history is loaded before calling iBarShift on off-chart symbols:
if(iBars(symbol, PERIOD_M1) == 0) continue;
thanks for all of you , i will see what i can do , and get back when there is an update
SymbolsList[0] = "EURUSD"; SymbolsList[1] = "NZDUSD"; SymbolsList[2] = "GBPAUD";
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I need help with this idea , i'm trying to create a on-chart multi-currency backtester , that iterate over time and symbols , and get the bar shift using iBarShift .
the problem is i'm getting inconsistent shift results , what i expected was to get the shifts in order from whatever start date until shift 0 .
but the iBarShift seems to give unordered results for ordered time iteration .
the other thing also is there are time jumps even if the data for that period is available and the iteration increase by 1 minute.
i tried also creating time RoundUp , but the same problem is faced.
here is my code :
Results i got :
Any help would be appreciated , Thanks