Download MetaTrader 5
To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
Sherif Hasan
7222
Sherif Hasan 2015.09.30 15:37 

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;

honest_knave
951
honest_knave 2015.09.30 15:52  

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. 

Sherif Hasan
7222
Sherif Hasan 2015.09.30 16:17  
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
honest_knave
951
honest_knave 2015.09.30 16:28  

How have you declared it (show the code)

Sherif Hasan
7222
Sherif Hasan 2015.09.30 16:53  
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);
honest_knave
951
honest_knave 2015.09.30 17:17  

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? 

Sherif Hasan
7222
Sherif Hasan 2015.09.30 17:20  
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.

honest_knave
951
honest_knave 2015.09.30 17:31  

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. 

Sherif Hasan
7222
Sherif Hasan 2015.09.30 17:41  
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

whroeder1
13596
whroeder1 2015.09.30 19:19  
If you had printed your values (threeAM, Time[threeAM], TimeHour(Time[threeAM]), THREEAM) inside your loop, you would have found the problem.
Sherif Hasan
7222
Sherif Hasan 2015.09.30 20:13  
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.

/
To add comments, please log in or register