Download MetaTrader 5

Array out of range error

To add comments, please log in or register
You sell neither signals nor apps? No problem, everyone can make profit!
Nurudeen Amedu
41368
Nurudeen Amedu 2016.11.25 11:18 

when i call the attached indicator during run time like this:

double buff[];
   CopyBuffer(hHandle,0,0,Bars(_Symbol,_Period),buff);
      double UL = buff[Bars(NULL,0)-1];
   CopyBuffer(hHandle,1,0,Bars(_Symbol,_Period),buff);
      double UD = buff[Bars(NULL,0)-1];

 it works for a while but after 1 or 2 hours i get array out of range error and the EA is removed from chart

how can i fix this

Files:
iglevels.mq5 14 kb
Alain Verleyen
Moderator
30743
Alain Verleyen 2016.11.25 15:52  
Nurudeen Amedu:

when i call the attached indicator during run time like this:

double buff[];
   CopyBuffer(hHandle,0,0,Bars(_Symbol,_Period),buff);
      double UL = buff[Bars(NULL,0)-1];
   CopyBuffer(hHandle,1,0,Bars(_Symbol,_Period),buff);
      double UD = buff[Bars(NULL,0)-1];

 it works for a while but after 1 or 2 hours i get array out of range error and the EA is removed from chart

how can i fix this

You need to check the return value of CopyBuffer(), then act accordingly.

Not directly related but : Bars() is a function, you called it 4 times with the same parameter, call is once and record the value in a variable.

To add comments, please log in or register