1

I am trying to add indicator code, which works perfectly on its own, to an EA MQL4 source. While everything compiles just fine, the terminal tab shows the above error.

Both errors occuring relate to tick[i+k].

double ticks[];
double tick[];

int init() {

   ArrayResize(ticks,TotalBars); ArraySetAsSeries(ticks,true);
   ArrayResize(tick,TotalBars); ArraySetAsSeries(tick,true);
   return(0);
}

int start() {

for (i=TotalBars-1; i>=0; i--)
   {
         avg = tick[i];
            for (k=1; k<AveragePeriod && tick[i+k]!=0; k++) avg += tick[i+k];
                                                                avg /= k;
         ....

I want to prevent iCustom calls. What could be the issue?

Thank you.

Michael
  • 11
  • 2
  • `tick[i+k]` sometimes does not exist because i can be number of bars you have (and array is already resized to that size) and k can be large (e.g. if AveragePeriod = 13 then k is in (1;12)). you should think of this scenario and choose what to do. I would suggest to start looping over i from TotalBars-1-AveragePeriod) – Daniel Kniaz Jul 24 '20 at 10:24
  • Yes, now I see. Thanks again. – Michael Jul 24 '20 at 19:42

0 Answers0