Array out of range problem

 

Hi,

I am trying start me EA but it's drop error Array out of range in the below rows on some pairs:

for(int j=2; j<barsQuantity; j++)
     {
      if((High[j]==highBar || Low[j]==highBar) && TrendSHORT)


 barsQuantity set as 3000 as extern variable:

p.s. if I set barsQuantity as 2000 - the problem dissappears.

I am some new in mql4 and tried find in the answer. Please help! 

 
romanfa:

Hi,

I am trying start me EA but it's drop error Array out of range in the below rows on some pairs:

for(int j=2; j<barsQuantity; j++)
     {
      if((High[j]==highBar || Low[j]==highBar) && TrendSHORT)


 barsQuantity set as 3000 as extern variable:

p.s. if I set barsQuantity as 2000 - the problem dissappears.

I am some new in mql4 and tried find in the answer. Please help! 

It sounds like you have between 2000 and 3000 bars on the chart.

If you try to access the index of a bar that doesn't exist, you will get that error. Have a look for Bars and/or rates_total

 
honest_knave:

It sounds like you have between 2000 and 3000 bars on the chart.

If you try to access the index of a bar that doesn't exist, you will get that error. Have a look for Bars and/or rates_total

Yes, you was right. Thank you! After downloading from history center the problem disappears.

 

How can I add some check to avoid this error? 

 
Take a look at whroeder1's post here
Reason: