About out of range error

 
   int counta=0;
   int countb=0;
   int countc=0;
   int countd=0;
   double HHV[10];
   int HHVX[10];
   double LLV[10];
   int LLVX[10];

   int counted_bars=IndicatorCounted();    

   for(int i=0;i<100;i++) // GET CLOSES THAT ARE LOWER THAN PREVIOUS CANDLE'S CLOSE
    { 
    if(iCustom(NULL,PERIOD_CURRENT,"Zigzag_with_line_at_lows_and_line_at_highs",Iperiod,4,3,3,i) != 0) 
       {
        HHV[counta++]=iCustom(NULL,PERIOD_CURRENT,"Zigzag_with_line_at_lows_and_line_at_highs",Iperiod,4,3,3,i); // <<- out of range
        HHVX[countc++] = i;
       }

    } 

   
   for(int x=0;x<80;x++) // GET CLOSES THAT ARE LOWER THAN PREVIOUS CANDLE'S CLOSE
     {
     if(iCustom(NULL,PERIOD_CURRENT,"Zigzag_with_line_at_lows_and_line_at_highs",Iperiod,4,3,4,x) != 0)
       {
        LLV[countb++]=iCustom(NULL,PERIOD_CURRENT,"Zigzag_with_line_at_lows_and_line_at_highs",Iperiod,4,3,4,x); // <- out of range
        LLVX[countd++] = x;
       }
 
      }
      ArrayResize(HHV,counta); // shrink to true size     
      ArrayResize(LLV,countb); // shrink to true size  
      ArrayResize(HHVX,countc);
      ArrayResize(LLVX,countd);

Hi all

Im using MT4

I have the out of range error because of the below coding

HHV[counta++]=iCustom(NULL,PERIOD_CURRENT,"Zigzag_with_line_at_lows_and_line_at_highs",Iperiod,4,3,3,i); // <<- out of range

LLV[countb++]=iCustom(NULL,PERIOD_CURRENT,"Zigzag_with_line_at_lows_and_line_at_highs",Iperiod,4,3,4,x); // <- out of range

But I dont know why this problem occur...

Please let me know how to fix it.


Thank you

Documentation on MQL5: MQL5 programs / Runtime Errors
Documentation on MQL5: MQL5 programs / Runtime Errors
  • www.mql5.com
Runtime Errors - MQL5 programs - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
HHV[counta++]

You are increasing counta, probably beyond the size of HHV[] which you set at 10.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford:

You are increasing counta, probably beyond the size of HHV[] which you set at 10.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

Thank you for ur help

Can you give me some coding to fix it??

I have no idea to fix it based on your answer

Is it just to increase to HHV[100]?

Thank you
 
if(counta+2 < ArraySize(HHV))
    HHV[counta++]=iCustom(NULL,PERIOD_CURRENT,"Zigzag_with_line_at_lows_and_line_at_highs",Iperiod,4,3,3,i)

Add this if before your line like i wrote

 
robbert:
Thank you for ur help

Can you give me some coding to fix it??

I have no idea to fix it based on your answer

Is it just to increase to HHV[100]?

Thank you

That should work as you are only checking back 100 bars.

Reason: