Array out of range

 

Hi,


today I started my first project in MQL5 and right at the beginning I'm very frustrated, yet.

I wanted to draw some lines at prices from an array. I never had problems with arrays, but in MQL5 I don't get it working.

For any reason I get the error message "array out of range" and the EA will get removed. Where is my mistake? :/


At the top:

input int VolPeriod= 14;
input int VolRatio = 3;
input int GridSize = 10;

double UpGrid[],DownGrid[];

And the function:

void RefreshGrid()
  {
   ArrayResize(UpGrid,GridSize/2,1);
   ArrayResize(DownGrid,GridSize/2,1);
   
   double Volatility=0;
   double GridIncrement;

   for(int i=1;i<=VolPeriod;i++)
     {
      Volatility+=iHigh(Symbol(),Period(),i)-iLow(Symbol(),Period(),i);
     }

   GridIncrement=NormalizeDouble(Volatility/VolPeriod,Digits())*VolRatio;
   
   for(int i=0;i<(GridSize/2);i++)
     {
      double vUG = SymbolInfoDouble(Symbol(),SYMBOL_BID)+GridIncrement*(i+1);
      double vDG = SymbolInfoDouble(Symbol(),SYMBOL_BID)-GridIncrement*(i+1);
      
      ArrayFill(UpGrid,i,i,vUG);
      ArrayFill(DownGrid,i,i,vDG);
     }
  }

I also tried the normal way 'UpGrid[i] = value;' instead of ArrayFill, but that also won't work.


Would be very happy if anyone could solve the problem.

 

You have a bug in ArrayFill function. Third param is number of elements to fill so this should be 1 in this case:

ArrayFill(UpGrid,i,1,vUG);
ArrayFill(DownGrid,i,1,vDG);

Normal way also should works properly:

UpGrid[i] = vUG;
DownGrid[i] = vDG;