Array out of range

 

Can someone help with that? I made an indicator that work well, but sometime when change the symbol or time frame in the chart get this error. Here is the part of code than have problem.

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate( const int rates_total,      // tamanho da série de preços de entrada series 
                 const int prev_calculated,  // barras tratadas na chamada anterior 
                 const datetime& time[],     // Hora 
                 const double& open[],       // Open (abertura) 
                 const double& high[],       // High (máximo) 
                 const double& low[],        // Low (mínimo) 
                 const double& close[],      // Close (fechamento) 
                 const long& tick_volume[],  // Volume de Tick 
                 const long& volume[],       // Volume Real 
                 const int& spread[]         // Spread 
                 )
  {
//---
      
//--- the main loop of calculations
   int i,limit;
//--- preliminary calculations
   if(prev_calculated==0)
     {
      //--- set first candle
      candlesBuffer1[0]=open[0];
      candlesBuffer2[0]=high[0];
      candlesBuffer3[0]=low[0];
      candlesBuffer4[0]=close[0];
      limit=1;
     }
   else limit=prev_calculated-1;   
   CopyBuffer(mediahandle,0,0,rates_total,mediaBuffer);
//----
   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      candlesBuffer1[i]=open[i];
      candlesBuffer2[i]=high[i];
      candlesBuffer3[i]=low[i];
      candlesBuffer4[i]=close[i];
      //--- set color for every candle
      //---
      if(close[i]>open[i] && close[i]>mediaBuffer[i] && mediaBuffer[i]>mediaBuffer[i-1]) candlesColors[i]=0.0; // set color DodgerBlue
      else
      if(close[i]<open[i] && close[i]<mediaBuffer[i] && mediaBuffer[i]<mediaBuffer[i-1]) candlesColors[i]=1.0; // set color Red
      else                                            candlesColors[i]=clrNONE;
      //---
      
     }
      
//--- done
      
      //===================================================
      
      
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
 
Samuel Manoel De Souza:

Can someone help with that? I made an indicator that work well, but sometime when change the symbol or time frame in the chart get this error. Here is the part of code than have problem.

  1. Show ALL your code so we can try to recreate the problem.
  2. What is the EXACT error that you are experiencing?
 

Mql4 Lesson 33 Array Out of Range.. - What does it mean? 


 

The forum

Documentation

  • MQL4 Reference - Array Functions - ArraySize 

------------------

Forum on trading, automated trading systems and testing trading strategies

Something Interesting

Sergey Golubev, 2016.01.27 12:41

Just some example about how to solve An array is out of range issue (I personally had this issue few times so it may be good to read the thread about how we can solve this our error during the coding for example).


ArraySize - Array Functions - MQL4 Reference
ArraySize - Array Functions - MQL4 Reference
  • docs.mql4.com
"Zero dimension = Array size / (First dimension * Second dimension * Third dimension)"
 
Sergey Golubev:

The forum

Documentation

  • MQL4 Reference - Array Functions - ArraySize 

------------------



Thank you!