ARRAY OUT OF RANGE

 
Boa tarde, galera. 
Estou começando a aprender programação. Criei um indicador para rodar em um robô universal. Roda normalmente para gráficos inferiores a 4 minutos, para superiores ele da esse erro "Array out of Range" e não consigo visualizar o problema. Segue abaixo o código:


#property copyright "Vinícius"
#property link      ""
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Compra
#property indicator_label1  "Compra"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrAqua
#property indicator_style1  STYLE_SOLID
#property indicator_width1  3
//--- plot Venda
#property indicator_label2  "Venda"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  3
//--- indicator buffers
double         CompraBuffer[];
double         VendaBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,CompraBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,VendaBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,159);
   PlotIndexSetInteger(1,PLOT_ARROW,159);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
  
//---
    for(int i=MathMax(1,prev_calculated-1); i<rates_total; i++)
    
   {
   if(close[i]<low[i-1] && close[i]<low[i-2])
     {
   VendaBuffer[i]=close[i];
   }
   else
   {
   VendaBuffer[i]=0;
   }
   
   if(close[i]>high[i-1] && close[i]>high[i-2])
   {
   CompraBuffer[i]=close[i];
   }
   else
   {
   CompraBuffer[i]=0;
   }
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
   return(rates_total);   } //+------------------------------------------------------------------+
 
Vinicius Bernardes:
Tente definir um tamanho para o array
 
Tente começar na terceira vela ("for(int i=MathMax(<<2>>,prev_calculated-1)):"
for(int i=MathMax(2,prev_calculated-1); i<rates_total; i++)
    
   {
   if(close[i]<low[i-1] && close[i]<low[i-2])
     {
Razão: