Download MetaTrader 5

Critical error Array out of range

To add comments, please log in or register
elfunambolo
106
elfunambolo  

Hello, I have this error when run my EA:


This is my code to open #3 orders, where is the mistake?

int ticket[];
bool checkBuy = true;
int i=3;               //numero ordini

void OnTick()
  {
  
  if ( Close[1] > Close[2] && checkBuy) {
  
    esecuzioneStrategiaBuy();
    
    checkBuy = false;
  
    }
  
  
   if (!checkBuy) {     // revisione degli ordini                           
     
             if (OrdersTotal() > 0);
     
             else {     // non ci sono ordini in piattaforma
          
              checkBuy = true;
                       
           }
     
        }
  
  
   
  }





void esecuzioneStrategiaBuy(){

    for ( int x = 1; x <= i ; x++) {
    
    ticket[x] = OrderSend(Symbol(),OP_BUY,0.1,Ask,0,Bid - 1,Bid + 1," Buy ordine: ",0,0,clrCrimson);
   
    if (ticket[x] < 0) stampa("Errore in apertura Buy ordine #1 ", GetLastError());
   
   }
         
}
Carl Schreiber
7301
Carl Schreiber  

ticket[] is declared as dynamic array so it has initially size = 0.

May be you should read the chapter about "Array Functions" in the Reference (editor, F1)?

Or you read this?

Jose Francisco Casado Fernandez
3301
Jose Francisco Casado Fernandez  
ArrayResize(ticket, i);

for(int x = 0; x < i; x++)   {

//---------------------

}
To add comments, please log in or register