Download MetaTrader 5

array out of range error on previously working indicator

To add comments, please log in or register
Donald R Isbell Jr
283
Donald R Isbell Jr  

Here is my code that worked before:

  At top of code: AsianStartBars[14]; AsianEndBars[14];
int k=0;
   while(k<14) {
      for(int j=AsianStartBar1;j<iBars(symbol,tf);j++) {
         if(TimeHour(iTime(symbol,tf,j)) == ChannelStartHour && TimeMinute(iTime(symbol,tf,j)) == 0) {
            AsianStartBars[k] = j;
            k++;
         }
      }
   }
   int n=0;
   while(n<14) {
      for(int m=AsianStartBar;m<iBars(symbol,tf);m++) {
         if(TimeHour(iTime(symbol,tf,m)) == ChannelEndHour && TimeMinute(iTime(symbol,tf,m)) == 0) {
            AsianEndBars[n] = m+1;
            n++;
         }
      }
   }

The problems are line:

AsianStartBars[k] = j;

AsianEndBars[n] = m+1;

I don't know how to fix it. If someone nows how, it's much appreciated. Thank you.

Kindest regards,

Don

Алексей Тарабанов
7324
Алексей Тарабанов  
disbellj:

Here is my code that worked before:

The problems are line:

AsianStartBars[k] = j;

AsianEndBars[n] = m+1;

I don't know how to fix it. If someone nows how, it's much appreciated. Thank you.

Kindest regards,

Don


Do not modify external cyrcle before internal.
Donald R Isbell Jr
283
Donald R Isbell Jr  

tara,

Thanks so much tara! You ROCK!

whroeder1
15581
whroeder1  
   while(k<14) {
      for(int j=AsianStartBar1;j<iBars(symbol,tf);j++) {
         if(TimeHour(iTime(symbol,tf,j)) == ChannelStartHour && TimeMinute(iTime(symbol,tf,j)) == 0) {
            AsianStartBars[k] = j;
            k++;
         }
      }
   }
The while does NOTHING when you are inside the for.
// while(k<14) {
      for(int j=AsianStartBar1;j<iBars(symbol,tf);j++) {
         if(TimeHour(iTime(symbol,tf,j)) == ChannelStartHour && TimeMinute(iTime(symbol,tf,j)) == 0) {
            AsianStartBars[k] = j;
            k++; if(k >= 14) break;
         }
      }
// }
Donald R Isbell Jr
283
Donald R Isbell Jr  

WHRoeder,

Thank you for the further explanation. Like I said, the code I posted worked before the upgrade to new MQL4 code. I have now updated my code. Same results as I get on pre-upgrade ex4. Thanks again. Maybe this will also help anyone else having the same issue.

Kindest regards,

Don

Ian Venner
2584
Ian Venner  
I didnt work properly before the upgrade, MT4 just ignored the error and continued until it reached the end of the chart as defined by iBars() in the for loop. The new version generated the array error and quit the indicator when the code attempted to write to your array indexes [14] +
To add comments, please log in or register