[Error] Array out of range

 

Hello everyone,

I'm just learning how to code a EA, I'm very happy if someone explain this error for me

This is my mini func

int Lenhmua(int Loailenh,short x, short y)
     {
     
     if (Loailenh==OP_BUY || Loailenh==OP_BUYLIMIT )
     {
          if (y==0)          
          GiaB[x][y]=MarketInfo(Tien[x],MODE_ASK);
          else GiaB[x][y]=GiaB[x][y-1]-Pips*Point;
          IDB_Tien[x][y]=OrderSend(Tien[x],Loailenh,Lots,NormalizeDouble(GiaB[x][y],Digits),0,0,GiaB[x][y]+Pips*Point,NULL,3453,0,clrNONE);
     };
     return(IDB_Tien[x][y]);
};

int Lenhban(int Loailenh,short x, short y)
     {
     
     if (Loailenh==OP_SELL || Loailenh==OP_SELLLIMIT )
     {
          if (y==0 && y>0)          
          GiaS[x][y]=MarketInfo(Tien[x],MODE_BID);
          else GiaS[x][y]=GiaS[x][y-1]+Pips*Point;
          IDS_Tien[x][y]=OrderSend(Tien[x],Loailenh,Lots,NormalizeDouble(GiaS[x][y],Digits),0,0,GiaS[x][y]-Pips*Point,NULL,3453,0,clrNONE);
     };
     return(IDS_Tien[x][y]);
};

And this is my Main EA

void start()
{
          for (i = 0; i<=5;i++)
          {    
               RefreshRates();
               while (IDB_Tien[a[i]][0] <=0) 
               {
               IDB_Tien[a[i]][0]= Lenhmua(OP_BUY,a[i],0);
               };
               Sleep(500);
               while (IDS_Tien[a[i]][0] <=0) 
               {
               IDS_Tien[a[i]][0]= Lenhban(OP_SELL,a[i],0);
               };
               Sleep(2000);
               while (IDB_Tien[a[i]][1] <=0) 
               {
               IDB_Tien[a[i]][1]= Lenhmua(OP_BUYLIMIT,a[i],1);
               };
               Sleep(500);
               while (IDS_Tien[a[i]][1] <=0) 
               {
               IDS_Tien[a[i]][1]= Lenhban(OP_SELLLIMIT,a[i],1);
               };
          };
return;
};

Thank you so much.

P/s: If i just use mini func alone, everything is ok so i don't think the problems is in the mini func

 

kissmez: I'm very happy if someone explain this error for me

  1. You know what the error is. Your index into some array is negative or greater or equal to the array size.
  2. We can't help further because we don't know which array, its size, or the index.
  3. Use the debugger or Print out your variables, and find out why.
 
whroeder1:
  1. You know what the error is. Your index into some array is negative or greater or equal to the array size.
  2. We can't help further because we don't know which array, its size, or the index.
  3. Use the debugger or Print out your variables, and find out why.
Oh. Thank you so much. I fixed it :D
Reason: