Using a Specific Bars range.... Same time every day....

 

Hello,

I am trying to write a code so that i can work off the highs and lows of a specific bar per day.... The specific bar will be defined by time....

E.G. Just say i want to use the range of the 4 hour bar that starts at 4:00 and finishes at 8:00 every day.... obviously i wont be able to trade off it until after 8 as this is when the bar is closed...but i can work all that out myself later.

I think i have the code pretty much right below.... the purpose of this function is just to return either the high or low of the specified bar.....i just need help with how to specify the time.

I wish i could just write "some_time= 12:00" but in reading mt4 help files it seems i need to find a date aswell...... but it always need to be the current days date.....

Can anyone help please? Thanks in advance.... I cant find anything on the forum that makes sense to me.

double BLevel(int L)
{   
   datetime some_time=......................??
   int shift =iBarShift( NULL, PERIOD_H4,some_time); 
   int    iHiH4    = iHighest( NULL, PERIOD_H4, MODE_HIGH, 1, shift);
   double BHigh = iHigh(NULL, PERIOD_H4, iHiH4);
   int    iLoH4    = iLowest( NULL, PERIOD_H4, MODE_HIGH, 1, shift);
   double BLow  = iLow(NULL, PERIOD_H4, iLoH4);
   if (L == BarHigh) return (BHigh);
   if (L == BarLow)  return (BLow);
   return(0);  
}
 
marty087:

Hello,

I am trying to write a code so that i can work off the highs and lows of a specific bar per day.... The specific bar will be defined by time....

E.G. Just say i want to use the range of the 4 hour bar that starts at 4:00 and finishes at 8:00 every day.... obviously i wont be able to trade off it until after 8 as this is when the bar is closed...but i can work all that out myself later.

I think i have the code pretty much right below.... the purpose of this function is just to return either the high or low of the specified bar.....i just need help with how to specify the time.

Calculate it as a datetime type variable and make good use of % to give you the remainder of a division. All you need to do is calculate midnight and add on 4 * PERIOD_H1 * 60 (4hrs as seconds).

Midnight: Look here

 

Worked like a charm!

Thanks Raptor!

Reason: