Array out of range error

 

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
 
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.

Reason: