array out of range when I try to use

 

I get the error when I try to get the value of the following code.

buf_Kairi[i]=NormalizeDouble((High-Low)/Low,digit);

I thought the number of bars is not enough for this calculation, so

I tried to prevent this error by adding the condition such as " if (bars >  limit + Inp_HighPeriod + Inp_LowPeriod)  ". 

However, it didn't work.

Now I have no idea what's wrong.

Please give me advice on this problem.

Any advice would be great helpful.


void OnTick()input int Inp_HighPeriod = 20;
input int Inp_LowPeriod = 10;
input int Inp_MAPeriod = 30;
input ENUM_MA_METHOD Inp_MAMode = MODE_SMA;

input int digit = 3;
input bool bool_light = true;
input int light_count = 500;
double buf_MA[];
double buf_Kairi[];
input int limit = 100;


void OnTick()

{

  for(int i = 0;i<limit;i++)
   {
      double High=iHigh(_Symbol,0,iHighest(_Symbol,0,MODE_HIGH,Inp_HighPeriod,i));
      double Low=iLow(_Symbol,0,iLowest(_Symbol,0,MODE_LOW,Inp_LowPeriod,i));
      buf_Kairi[i]=NormalizeDouble((High-Low)/Low,digit);
   }

}
 
metamitsu:

I get the error when I try to get the value of the following code.

I thought the number of bars is not enough for this calculation, so

I tried to prevent this error by adding the condition such as " if (bars >  limit + Inp_HighPeriod + Inp_LowPeriod)  ". 

However, it didn't work.

Now I have no idea what's wrong.

Please give me advice on this problem.

Any advice would be great helpful.


Resize your array to create space, before trying yo set it's values.
 
Nelson Wanyama:
Resize your array to create space, before trying yo set it's values.

Thank you. I  added the following code and it worked.

     ArrayResize(buf_Kairi,100,100);

     ArrayResize(buf_Kairi_b,100,100);

 

Don't double post! You already had another thread open.

          General rules and best pratices of the Forum. - General - MQL5 programming forum 2017.07.19
Reason: