"array out of range" error when executing indicator

 
"array out of range" error when executing indicator

Hello I managed to "translate" a weis wave indicator from mql4 for to mql5 but when executing on the platform it gives the error "array out of range" line 49 (OnInit).

how fixet? Thank you.

code:

#property indicator_separate_window

#property indicator_buffers 6



#property indicator_color1 White

#property indicator_color2 Black



#property indicator_width1 2     

#property indicator_width2 2     





//:::::::::::::::::::::::::::::::::::::::::::::

//:::::::::::::::::::::::::::::::::::::::::::::::



input int dif=15;

double mov[];

double trend[];

double wave[];

double up[];

double dn[];

double vol[];



int firstrun;



int OnInit() {

  //:::::::::::::::::::::::::::::::::::::::::::::

  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);

  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);

  int Bars=Bars(Symbol(),PERIOD_CURRENT);

  double Point=Point();

  //Etc.

  //:::::::::::::::::::::::::::::::::::::::::::::::





// indicator_buffers(6);



SetIndexBuffer(0,up);

SetIndexBuffer(1,dn);

SetIndexBuffer(2,mov);

SetIndexBuffer(3,trend);

SetIndexBuffer(4,wave);

SetIndexBuffer(5,vol);



mov[Bars-1]=0;

trend[Bars-1]=0;

wave[Bars-1]=0;

up[Bars-1]=0;

dn[Bars-1]=0;

vol[Bars-1]=0;



   return(0);

   }

 

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {





  //:::::::::::::::::::::::::::::::::::::::::::::

  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);

  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);

  int Bars=Bars(Symbol(),PERIOD_CURRENT);

  double Point=Point();

  //Etc.

  //:::::::::::::::::::::::::::::::::::::::::::::::



   

   int limit, i;

   int counted_bars = prev_calculated;

   //----------------------------------

                                 

  

   //---

   if(counted_bars<0) return(counted_bars);

   //----

   if(counted_bars>0) counted_bars --;

   limit=Bars-counted_bars;

   

for(i=0;i<limit; i++) 

{



   if (i<Bars-1)

   

      {



      if (close[i]-close[i+1]>0) mov[i]=1;

      if (close[i]-close[i+1]==0) mov[i]=0;

      if (close[i]-close[i+1]<0) mov[i]=-1; 



      if ((mov[i]!=0) && (mov[i]!=mov[i+1])) {trend[i]=mov[i];} else {trend[i]=trend[i+1];} 



      if ((trend[i]!=wave[i+1]) && (MathAbs(close[i]-close[i+1])*10000>=dif)) {wave[i]=trend[i];} else {wave[i]=wave[i+1];}    



      if (wave[i]==wave[i+1]) {vol[i]=vol[i+1]+VOLUME_TICK;} else {vol[i]= VOLUME_TICK;}



      if (wave[i]==1) {up[i]=vol[i]; dn[i]=0;}

      if (wave[i]==-1) {dn[i]=vol[i]; up[i]=0;}

      

      }

   

   }

//--- return value of prev_calculated for next call

   return(rates_total);

   }

 got this code using a program that converts mal4 to mql5, but some adjustments are necessary.

The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks, as a small error in the expert or indicator logic can cause losses on the trading account. That is why we have developed a series of basic checks to ensure the required quality level of the Market products. If any errors are identified by the Market...
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button


 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. SetIndexBuffer(0,up);
    
    SetIndexBuffer(5,vol);
    
    
    mov[Bars-1]=0;
    ⋮
    vol[Bars-1]=0;
    You've set up your buffers, but they still have no size. They won't until OnCalculate is called.
  3. Why are you setting elements to zero when the default is EMPTY_VALUE?
 
Sergey Golubev:

Thanks i new from her ;)
 
William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. You've set up your buffers, but they still have no size. They won't until OnCalculate is called.
  3. Why are you setting elements to zero when the default is EMPTY_VALUE?
thank you i will test.