Lowest & highest

 

Hi

How could I return the lowest low or the highest high, starting from the beginning of the opened order ?

Thank you.

 
ammar:
Hi

How could I return the lowest low or the highest high, starting from the beginning of the opened order ?

Thank you.

Hi ammar,

This is a real puzzle.

We can get the order open time by the function: OrderOpenTime.

But how can we convert this time to bar??

well, if we know the timeframe of the chart we can consider every bar is walk in the history for this time.

For example: if the TF is 30M then every bar is current time - 30 minutes.

So, if we know the opened time of the order and the timeframe then we can know what the bar number of the opened order.

Let me to work around this solution.

 

Thank you Mohammed for your helping,

You gave me an idea .

We can use this code :

double Lo=Low [Lowest (NULL,0,MODE_LOW,( CurTime( )-OrderOpenTime( ))/(60*Period( )),0)];

double Hi=High ;

What do you think ?

Bye.

 
ammar:
Thank you Mohammed for your helping,

You gave me an idea .

We can use this code :

double Lo=Low [Lowest (NULL,0,MODE_LOW,( CurTime( )-OrderOpenTime( ))/(60*Period( )),0)];

double Hi=High ;

What do you think ?

Bye.

ammar,

It seems logical!

But I'm not sure CurTime( )-OrderOpenTime( ) will return an integer.

The second thing, if the above code is right it must be like that:

double Lo=Low [Lowest (NULL,0,MODE_LOW,The_Period_You_Want,( CurTime( )-OrderOpenTime( ))/(60*Period( )))];

double Hi=High ;

Well, we have to test the above code!

 

ammber,

Please try this code!

Files:
ea_demo.mq4  2 kb
 

Thank you Mohammed For your help.

But I'm sorry, the code didnt work for me, because I don't want to define a certain period which I want the highest or lowest value for it.

The code I wrote before worked for me, but I don't know maybe I'm wrong.

Thank you again , you are very kind.

Ammar

 
ammar:
Thank you Mohammed For your help.

But I'm sorry, the code didnt work for me, because I don't want to define a certain period which I want the highest or lowest value for it.

The code I wrote before worked for me, but I don't know maybe I'm wrong.

Thank you again , you are very kind.

Ammar

Ammar,

I'm happy it worked .

 

Ammar, you could also use iBarShift() function :

int iBarShift( string symbol, int timeframe, datetime time, bool exact=false)

Search for bar by open time. The function returns bar shift with the open time specified. If the bar having the specified open time is absent the function will return, depending on the exact parameter, -1 or the nearest bar shift.

Parameters:

symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.

timeframe - Time frame. It can be any of Time frame enumeration values.

time - value to find (bar's open time).

exact - Return mode when bar not found. false - iBarShift returns nearest. true - iBarShift returns -1.

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);

 

Thank you Michel,

But how could I use this function to return the highest and lowest from the opening of the orders.

Good luck.

Reason: