Array out of range error

 

Hello every one,

Can I find a solution to this erreur "Array out of range"? My strategy is based on the intraday support and resistance levels, It's working fine in backtesting and a demo account. But the checker MQL5 detects this error in line 499 (double ret...0...).

     }
   double cHigh[];
   ArraySetAsSeries(cHigh, true);
   CopyHigh(Symbol(), Period(), start_index, count, cHigh);
   double ret = cHigh[ArrayMaximum(cHigh, 0, count)];
   if (draw) DrawLine("Resistance", ret, count, start_index);
   return(ret);
  }
Files:
array_range.png  14 kb
 
Abdeljalil El Kedmiri:

Hello every one,

Can I find a solution to this erreur "Array out of range"? My strategy is based on the intraday support and resistance levels, It's working fine in backtesting and a demo account. But the checker MQL5 detects this error in line 499 (double ret...0...).

You need to validate/error check CopyHigh.

 
Dominik Christian Egert #:
You need to validate/error check CopyHigh.

And ArrayMaximum() which can returns -1.
 

Thanks you Dominik and Alain for the answers.

My problem was that the checker use D1 time frame (for Gold) to backtest my startegy  that needs a smaller time frame than daily as it is calculated from the time of day.

so the solution was to use a condition to stop checking other conditions if the time frame is daily.