iHigh Function returning 0 for some but not others
Hi.
Check this:
int barsAvailable = iBars(Symbol(), PERIOD_D1); if (barsAvailable > 2) { D1_H0 = iHigh(Symbol(), PERIOD_D1, 0); D1_H1 = iHigh(Symbol(), PERIOD_D1, 1); D1_H2 = iHigh(Symbol(), PERIOD_D1, 2); D1_L0 = iLow(Symbol(), PERIOD_D1, 0); D1_L1 = iLow(Symbol(), PERIOD_D1, 1); D1_L2 = iLow(Symbol(), PERIOD_D1, 2); D1_O1 = iOpen(Symbol(), PERIOD_D1, 1); D1_C1 = iClose(Symbol(), PERIOD_D1, 1); } else { Print("Not enough bars available for this symbol."); }
This code ensures that your program only attempts to access historical data if it’s available. If not, you can log an error message or handle the absence of data in a meaningful way.
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)
I'm experiencing something strange. My code is as follows:
D1_H0 = iHigh(Symbol(), PERIOD_D1, 0);
D1_H1 = iHigh(Symbol(), PERIOD_D1, 1);
D1_H2 = iHigh(Symbol(), PERIOD_D1, 2);
D1_L0 = iLow (Symbol(), PERIOD_D1, 0);
D1_L1 = iLow (Symbol(), PERIOD_D1, 1);D1_L2 = iLow(Symbol(), PERIOD_D1, 2);
D1_O1 = iOpen(Symbol(), PERIOD_D1, 1);
D1_C1 = iClose(Symbol(), PERIOD_D1, 1);When I print these values, it will return the correct values for some symbols but for others it just returns 0. For example, US500 works but not US100. ETHUSD,BTCUSD works but not USDCAD.
For the working symbols, it will return the correct values for all OHLC values for all PERIODS (0, 1, 2)
For the non-working symbols, it will return the correct values for only OHCL values for PERIOD 1, but not PERIOD 1 or PERIOD 2
What in the world is going on?