Error: array out of range

 
Hi everyone, I was testing this new indicator in the strategy tester and the error: array out of range (56.22) came out. If anyone can help me out, thanks.
//+------------------------------------------------------------------+
//|                                            ProvaTrendLinesGV.mq5 |
//|                                               Verzeletti Giorgio |
//|                                    giorgio.verzele2001@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Verzeletti Giorgio"
#property link      "giorgio.verzele2001@gmail.com"
#property version   "1.00"
#property indicator_chart_window

input string            InpFont="Arial";         // Font 
input int               InpFontSize=10;          // Grandezza del font 
input color             InpColor=clrRed;         // Colore 
input double            InpAngle=0;              // Angolo di pendenza in gradi 
input ENUM_ANCHOR_POINT InpAnchor=ANCHOR_CENTER; // Tipo di ancora 
input bool              InpBack=false;           // Oggetto di sottofondo 
input bool              InpSelection=false;      // Evidenzia di movimento 
input bool              InpHidden=true;          // Nascosta nella lista oggetti 
input long              InpZOrder=0;             // Priorità per il click del mouse 

input int CalcBars=100;
input int NumLevels=10; //dopo modificalo
input double GridSize=0.001; //MODIFICALO

int MyFractalsDefinition=0;
double MyLevelsArray[];
string LabelName[];
//string Labeltext;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()   //AGGIUNGI I BUFFERS
  {
   double StartPrice=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);  //dopo modificalo
   double MyLevelsUpArray[];     //above the StartPrice
   double MyLevelsDownArray[];   //under the StartPrice
   datetime date[];
   
   MyFractalsDefinition=iFractals(_Symbol,_Period);
   if(MyFractalsDefinition==INVALID_HANDLE)
     {
      printf("Error obtaining handle");
      return(INIT_FAILED);
     }
   ArrayResize(MyLevelsUpArray,NumLevels+1); 
   ArrayResize(MyLevelsDownArray,NumLevels+1); 
   
   MyLevelsUpArray[0]=StartPrice;
   MyLevelsDownArray[0]=StartPrice;
   
   CopyTime(Symbol(),Period(),0,1,date);

   for(int conta=0; conta<=NumLevels; conta=conta+1)     //DOPO MAGARI SCEGLI MEGLIO LO START PRICE
     {
      MyLevelsUpArray[conta+1]=MyLevelsUpArray[conta]+GridSize;
      MyLevelsDownArray[conta+1]=MyLevelsDownArray[conta]-GridSize;
     }
   for(int conta=NumLevels+1; conta>0; conta=conta-1)
     {
      MyLevelsArray[NumLevels+1-conta]=MyLevelsDownArray[conta];
     }
   for(int conta=0; conta<=NumLevels; conta=conta+1)
     {
      MyLevelsArray[NumLevels+1+conta]=MyLevelsUpArray[conta];    //contiene tutti i livelli in ordine crescente di prezzo
     }

   for(int conta=0; conta<=2*NumLevels; conta=conta+1)
     {
      LabelName[conta]="Zone "+(string)conta;
     }
   for(int i=0;i<2*NumLevels;i+=1)
     {
      //--- crea il testo 
      TextCreate(0,LabelName[i],0,date[0],MyLevelsArray[i]+(GridSize/2),"ciao",InpFont,InpFontSize,      
         InpColor,InpAngle,InpAnchor,InpBack,InpSelection,InpHidden,InpZOrder);     //DOPO MODIFICA LA DATA (ECC.) PER CREARE LA "TABELLA" (LINEE VERT. E ORIZ.)
     }
     
   return(INIT_SUCCEEDED);
  }
//...
 

You are accessing array elements from 0 to NumLevels+1, that makes NumLevels+2 items. So you either need to run your for variable from 0 to NumLevels-1, or resize the arrays larger.

Either:

ArrayResize(MyLevelsUpArray,NumLevels+2);

or:

for(int conta=0; conta<=NumLevels-1; conta++)
 
lippmaje:

You are accessing array elements from 0 to NumLevels+1, that makes NumLevels+2 items. So you either need to run your for variable from 0 to NumLevels-1, or resize the arrays larger.

Thanks very much
Reason: