Download MetaTrader 5

Array out of range

To add comments, please log in or register
Use the Pocket to paste your content. It is convenient!
faraway030 2015.10.22 18:42 


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()
   double Volatility=0;
   double GridIncrement;

   for(int i=1;i<=VolPeriod;i++)

   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);

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.

Janusz Trojca 2015.10.22 19:31  

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


Normal way also should works properly:

UpGrid[i] = vUG;
DownGrid[i] = vDG;
To add comments, please log in or register