How to find the time of the High and Low ???????

 

Hello,

I am trying to code an expert. If for example it is 15 o'clock and the daily price on GBPUSD has had a Low at 12:39 and a High at 7:23, how do I find these time values with mql4 ?????????

I have tried:

t1=TimeHour(iHigh(NULL,PERIOD_D1,0)); t2=TimeHour(iLow(NULL,PERIOD_D1,0));

and so on... but nothing seems to work, can someone please help me out ?????????????????

 

Well I have figured out how to locate the shift from the current bar to the low and high with this code:

datetime some_time=Time[0];

int shift=iBarShift(NULL,PERIOD_M1,some_time);

int ht=Highest(NULL,PERIOD_M1,MODE_HIGH,shift,0);

int lt=Lowest(NULL,PERIOD_M1,MODE_LOW,shift,0);

[/CODE]

The only problem is that I can only use this on a daily chart, does someone know how I can get it to check the shift on any chart.

I mean getting this to say midnight o'clock 00:00 ??

[CODE]

datetime some_time=Time[0];

Please make suggestions

 

Got it

I finally got it with some help on another forum

the code is:

datetime some_time=iTime(NULL,PERIOD_D1,0);

int shift=iBarShift(NULL,PERIOD_M1,some_time);

int ht=Highest(NULL,PERIOD_M1,MODE_HIGH,shift,0);

int lt=Lowest(NULL,PERIOD_M1,MODE_LOW,shift,0);

 

I have tested my code on a script. And with this code:

datetime some_time=iTime(NULL,PERIOD_D1,0);

int shift=iBarShift(NULL,PERIOD_M1,some_time);

int ht=Time;

int lt=Time[Lowest(NULL,PERIOD_M1,MODE_LOW,shift,0)];

string var1=TimeToStr(some_time,TIME_DATE|TIME_SECONDS);

string var2=TimeToStr(ht,TIME_SECONDS);

string var3=TimeToStr(lt,TIME_SECONDS);

Comment("high is",var2,"\n","low is",var3,"\n","time",var1);

[/CODE]

I only get the right time on the M1 chart.

But with this code:

[CODE]

datetime some_time=iTime(NULL,PERIOD_D1,0);

int shift=iBarShift(NULL,PERIOD_M1,some_time);

int ht=Highest(NULL,PERIOD_M1,MODE_HIGH,shift,0);

int lt=Lowest(NULL,PERIOD_M1,MODE_LOW,shift,0);

Comment("shift of bar with open time ",TimeToStr(some_time)," is ",shift,"\n","high is",ht,"\n","low is",lt);

I get the index value of the shift from the current bar to the high and to the low on all the charts from M1 to MN. Since my purpose is to determine which one the high or the low was first I can use the second code.

But when I use this code in an expert advisor, it won't trade. The only logic I changed was:

Before buy: if (lt>ht) it is ok to buy

before sell: if (ht>lt) it is ok to sell

Does any one know how to do this ??????

Reason: