Help with this code!

 

everyday I want to get high/low value for first candle.ie. 00.00AM

I tried with 4hr TF:

But shows different candle high/low.i valdiate date with nday!=Day();

Please help me to fix the issue.

 #define  ZEROAM 00
    int shift=iBarShift(NULL,0,ZEROAM);
    hval=iHigh(NULL,0,shift);
    lval=iLow(NULL,0,shift);
    Comment("High:",hval,"Low:",lval);
 

ZEROAM = 00, I don't think this is the time you want.

https://docs.mql4.com/series/iBarShift

Sample:
datetime some_time=D'2004.03.21 12:00';
int shift=iBarShift("EUROUSD",PERIOD_M1,some_time);
Print("shift of bar with open time ",TimeToStr(some_time)," is ",shift);

The Sample above uses datetime properly. Try reading more about Date Time.

 
I want to get high/low of day's first candle!. TF can be different.
 
sheriffonline:
I want to get high/low of day's first candle!. TF can be different.

You have already been given the answer, please pay attention to the help you are given.

https://www.mql5.com/en/forum/145982 midnight is the days first candle regardless of timeframe . . . except for Sunday bars . . .

 
Sample:
datetime some_time=D'2004.03.21 12:00';
int shift=iBarShift("EUROUSD",PERIOD_M1,some_time);


to get the current day's datetime change the sample above:

datetime some_time=iTime("EURUSD", PERIOD_D1, 0);
 
szgy74:



to get the current day's datetime change the sample above:


Thanks. its very simple and neat code.
Reason: