highs and lows in a time period

 

hi,

i'm new to mql and want to create a simple code which recognizes the highs and lows in a time period (2:00 a.m. to 2:59 a.m.) for a currency pair. i hope an expert can help me with my little problem.;)

thx

 
nighthawk:

hi,

i'm new to mql and want to create a simple code which recognizes the highs and lows in a time period (2:00 a.m. to 2:59 a.m.) for a currency pair. i hope an expert can help me with my little problem.;)

thx


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

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 missing, the function will return -1 or the nearest bar shift depending on the exact.

 
init()
{ 
        int Start = iBarShift( NULL, 0, D'02:00:00' );
        int End = iBarShift( NULL, 0, D'02:59:59' );
        int Range = 1 + Start - End;
        int High = iHighest( NULL, 0, MODE_HIGH, Range, End );
        int Low = iLowest( NULL, 0, MODE_LOW, Range, End ); 

        Print( "Period High: ", High, " Period Low: ", Low );

        return( 0 );
} 
I think it is something like this that you're after. If you drop this in the init function for an EA, it should print the high and low for the period into the journal. This assumes that it is already past 2:59 am.
I haven't used a function like this before, maybe it won't work it all. Let us know how it goes...
You may find this to be helpful.
 

I don't get it :)

What does your code do that iHigh(null, period_h1, iBarShift(null, period_h1, time_2am, false)) ; wouldn't do with less cpu usage?

o/

EDIT: and nearly same with iLow.

EDIT2: actually i'm not really sure that it takes less cpu time, because i don't know how data is saved. I just assume that it saves data in different format for different periods, that's why it needs to load more data again from metaquotes server if you go to M1 chart and start paging up really fast.

 
iHigh will return the high of the "time_2am" bar. iHighest will return the high of the highest bar between 2am and 2:59am.
 
Err yes, true :) but since iHigh is set to period_h1, the result should be the same, should it not? :)
 

Ah, I suddenly see your point. I'm providing a more general solution, but since we're only interested in the high and low during a single given hour then your solution should be easier.

Mine has the flexibility to just be dropped onto a chart, and to calculate the high and low for any range of bars and any time frame. So there! ;)

Reason: