iHigh sometimes return ERR_HISTORY_NOT_FOUND - 4401

 

Hello,

Sometimes i have a bug using functions iHigh, iLow, iClose on the current chart, and current Symbol. I use it like that (in an indicator):

    double HWeek = iHigh(Symbol(),PERIOD_W1,0);
    double LPWeek = iLow(Symbol(),PERIOD_W1,1);
    double LWeek = iLow(Symbol(),PERIOD_W1,0);

Sometimes when i change symbol on mt5, it returns 0... i have to change ut one time or two times to get the correct values.

The last error returns ERR_HISTORY_NOT_FOUND - 4401

i don't understand why it works, and sometimes not.

Someone can help me?

I am running on mt5 5.00 build 2085


Thank you!!

 

It seems having this type of error it's always possible, and i have to try to get it another time on the next tick ...

 
The timeframe W1 is probably different from the current chart's timeframe. In MT5 when an indicator is launched, 'foreign' history data might not have been completely loaded upon the first call to OnCalculate. This can be well observed when the terminal is being restarted. The iHigh/iLow calls act as a sort of request for W1 history data that due to this oddity sometimes cannot be served immediately but will be pursued in the terminal's background. You need to check for that. If you get a no history error you need to postpone the indicator calculation until the calls succeed.
 
dimberaid19    double HWeek = iHigh(Symbol(),PERIOD_W1,0);
On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
          Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
          Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
          SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum 2019.09.03

 
Thank you for your replies !
Reason: