HammerJack:
Like iTime() ?
It would help if a similar function to return the open time.
HammerJack: So if one uses iOpen(Symbol(),Period(),Shift), for multiple pairs, how can you know that you are getting results for the very same bar?
You don't. You've got the problem backwards. Don't try to check for the same bar, find it.// double OpenEURUSD = iOpen("EURUSD",0,0); // The zero assumes the current chart is EURUSD // So just use the predefined variables. int iGBPUSD = iBarShift("GBPUSD", Period(), Time[0]); // Can't use zero because GBPUSD is NOT the current chart. // Find the correct shift and use it. double OpenEURUSD = Open[0]; double OpenGBPUSD = iOpen("GBPUSD", Period(), iGBPUSD);In the tester the current bar for the current chart is zero. But OTHER pairs are NOT tested/adjusted, their index can be in the thousands.
Thanks guys.
Would this be correct use of the mentioned code, to check that data from all needed bars is available?
string Pairs[] = {"EURUSD","GBPUSD","USDJPY"}; int BarShift[3]; int NewTime = Time[1]; bool AllBarsFound = True; for(int N =0; N<ArraySize(Pairs); N++){ BarShift[N] = iBarShift(Pairs[N],Period(),NewTime,True); if(BarShift[N]<0){AllBarsFound = False;} }
HammerJack:
So if one uses iOpen(Symbol(),Period(),Shift), for multiple pairs, how can you know that you are getting results for the very same bar?
Anybody have some thoughts on this?
It would help if a similar function to return the open time.
What about something like this:
string Pairs[] = {"EURUSD","GBPUSD","USDJPY"}; double OpenPrices[1]; int iBar = 1; // looking back 1 bar on current chart datetime BarTime = Time[iBar]; // looking at iBar's time if (Time[iBar] == BarTime) { OpenPrices[0] = Open[iBar]; Print ("Open price for ", Symbol(), " is ", DoubleToStr(OpenPrices[0], 5)); } for (int i = 0; i < ArraySize(Pairs); i++) { if (Pairs[i] == Symbol()) continue; if (BarTime == iTime(Pairs[i], Period(), iBar)) { ArrayResize(OpenPrices, ArraySize(OpenPrices)+1); OpenPrices[ArraySize(OpenPrices) - 1] = iOpen(Pairs[i], Period(), iBar); Print ("Open price for ", Pairs[i], " is ", DoubleToStr(OpenPrices[ArraySize(OpenPrices) - 1], 5)); } }
As RaptorUK mentioned, you will need to test for an error 4066. If you get an error 4066, just wait for about 10 seconds and then retry again.
Thanks for bringing up the error 4066. If ignored when it occurs, would iBarShift() return -1 ?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
So if one uses iOpen(Symbol(),Period(),Shift), for multiple pairs, how can you know that you are getting results for the very same bar?
Say that you have an EURUSD 1H chart open and at the opening of the new bar you want to load the bar open quote for EURUSD and GBPUSD.
double OpenEURUSD;
double OpenGBPUSD;
OpenEURUSD = iOpen("EURUSD",0,0);
OpenGBPUSD = iOpen("GBPUSD",0,0);
Then if the GBPUSD chart doesn't have the new bar yet, you get the open price of the previous bar compared to the EURUSD chart.
Anybody have some thoughts on this?
It would help if a similar function to return the open time.