error message in journals. array out of range in (214,36)?

 

What could be the issue?

    ZEROAM= FromHours-4;
    THREEAM= FromHours-1;
    threeAM=0; while( TimeHour(Time[threeAM]) != THREEAM ) threeAM++;
    EJHigh7To10 = iHigh(NULL,PERIOD_H1,iHighest(NULL,PERIOD_H1,MODE_HIGH, THREEAM-ZEROAM+1,threeAM));
    EJLow7To10 = iLow(NULL,PERIOD_H1,iLowest(NULL,PERIOD_H1,MODE_LOW, THREEAM-ZEROAM+1,threeAM));
    EJ_Diff=EJHigh7To10-EJLow7To10;
    EJ_Hval=EJHigh7To10;
    EJ_Lval=EJLow7To10;

 

Possibly either

FromHours is set to 0, meaning you are trying to access Time[-1]

FromHours is set to a very large number, which means you are trying to access an index > Bars

Without seeing your use of FromHours it is hard to tell. 

 
honest_knave:

Possibly either

FromHours is set to 0, meaning you are trying to access Time[-1]

FromHours is set to a very large number, which means you are trying to access an index > Bars

Without seeing your use of FromHours it is hard to tell. 

 

 

From Hours is 10:00
 

How have you declared it (show the code)

 
honest_knave:

How have you declared it (show the code)

 

extern int FromHours = 10;
extern int ToHours = 20;
int ZEROAM=0;
int THREEAM=0;
int threeAM=0;
double EJHigh7To10=0;
double EJLow7To10=0;
double EJ_Diff=0;
ZEROAM= FromHours-4;
THREEAM= FromHours-1;
threeAM=0; while( TimeHour(Time[threeAM]) != THREEAM ) threeAM++;
EJHigh7To10 = iHigh(NULL,PERIOD_H1,iHighest(NULL,PERIOD_H1,MODE_HIGH, THREEAM-ZEROAM+1,threeAM));
EJLow7To10 = iLow(NULL,PERIOD_H1,iLowest(NULL,PERIOD_H1,MODE_LOW, THREEAM-ZEROAM+1,threeAM));
EJ_Diff=EJHigh7To10-EJLow7To10;
EJ_Hval=EJHigh7To10;
EJ_Lval=EJLow7To10;
Comment("High: ",EJ_Hval," Low: ",EJ_Lval," Range: ",EJ_Diff);
 

Given that threeAM is set to 0:

threeAM=0; while( TimeHour(Time[threeAM]) != THREEAM ) threeAM++;

 

And the increment is positive

threeAM=0; while( TimeHour(Time[threeAM]) != THREEAM ) threeAM++;


I would surmize that your while loop is continuing until it exceeds Bars... are you running this on a backtest

 
honest_knave:

Given that threeAM is set to 0:

 

And the increment is positive


I would surmize that your while loop is continuing until it exceeds Bars... are you running this on a backtest? 

 

Forgot to mention that the code works fine, but when i use the code with 4H time frame i get the error as i mentioned on subject.

yes, i get the error while backtesting.

 

You set THREEAM as 10-1 = 9 

Unless you have a very strange broker, your H4 bars never start at 09:00.

So your loop will continue indefinitely 

threeAM keeps increasing until it exceeds Bars

Then you get an array out of range error. 

 
honest_knave:

You set THREEAM as 10-1 = 9 

Unless you have a very strange broker, your H4 bars never start at 09:00.

So your loop will evaluate as false indefinitely. 

threeAM keeps increasing until it exceeds Bars

Then you get an array out of range error. 

Thank you honest_knave. got my logic error.

i fixed it. Thanks honest_knave

 
If you had printed your values (threeAM, Time[threeAM], TimeHour(Time[threeAM]), THREEAM) inside your loop, you would have found the problem.
 
WHRoeder:
If you had printed your values (threeAM, Time[threeAM], TimeHour(Time[threeAM]), THREEAM) inside your loop, you would have found the problem.

Thanks WHRoeder. yes. same i did as you mentioned here. the issue is tf issue as honest_knave mentioned.

fixed it by filtering tf.

Reason: