CopyRates array working Live but fails on Backtesting returning Critical Error

 

Hello There this is my code

  MqlRates candle[];
  ArraySetAsSeries(candle,true);
  CopyRates(_Symbol,PERIOD_H4,0,3,candle);
//-- 

This Array works perfect on Live Trading but going to backtest whenever that array gets used it provides Critical error in that line 

 
Omega J Msigwa:

Hello There this is my code

This Array works perfect on Live Trading but going to backtest whenever that array gets used it provides Critical error in that line 

I  think I figured this out ?? Maybe the error was poor history quality causing retrieving  of data from that array to provide unknown value , i Changed my Testing period forward to almost current days and it now works , if there is any other best way than that , I would like to hear from ya !!

 
  1. It gets a critical error because you don't bother to check your return codes.

    Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  2. 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 - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20

    On MT5: Unless the current chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.

              Error 4806 while using CopyBuffer() - Expert Advisors and Automated Trading - MQL5 programming forum #10 2020.12.15
              Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum 2019.05.31
              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 #2 2018.07.17
              SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum 2019.09.03