High/low of first for bars of new day

 

Hi all, I was just wondering if anyone could let me know if i am on the right track. I am trying to make an
EA which measures the highest point and lowest point for the first 4 (1 hour) bars of each new day.

I know how to check for new day :

bool IsNewDay()
{
static datetime OldDay = 0;

if(OldDay < Day())
{ 
OldDay = Day();
return(true);
}
else
{
return(false);
}
}

And I know how to check for high/low :

double high = iHighest(Symbol(),PERIOD_H1,MODE_HIGH,4,0)
double low = iLowest(Symbol(),PERIOD_H1,MODE_LOW,4,0)

My problem is, how do I make the EA check only the bars after the new days has started, ie, once the EA confirms that
there is a new day, if I tell it to check the highest/lowest values for the last 4 (1 hour) bars, it will check bars that were in
the previous day. I need it to only count the bars of the new day.

Would I need to sleep the EA for 4 hours ?? :)

I hope my rambling makes sense haha. Any help would be appreciated...thanks.

 
JoBlo:

Hi all, I was just wondering if anyone could let me know if i am on the right track. I am trying to make an
EA which measures the highest point and lowest point for the first 4 (1 hour) bars of each new day.

I know how to check for new day :

bool IsNewDay()
{
static datetime OldDay = 0;

if(OldDay < Day())
{
OldDay = Day();
return(true);
}
else
{
return(false);
}
}

And I know how to check for high/low :

double high = iHighest(Symbol(),PERIOD_H1,MODE_HIGH,4,0)
double low = iLowest(Symbol(),PERIOD_H1,MODE_LOW,4,0)

My problem is, how do I make the EA check only the bars after the new days has started, ie, once the EA confirms that
there is a new day, if I tell it to check the highest/lowest values for the last 4 (1 hour) bars, it will check bars that were in
the previous day. I need it to only count the bars of the new day.

Would I need to sleep the EA for 4 hours ?? :)

I hope my rambling makes sense haha. Any help would be appreciated...thanks.


Use SRC button to display your code

The first H4 bar of the day is giving you also this value so when iTime 4hour bar is same as daily bar you can take the high and low of that bar

 
deVries:


Use SRC button to display your code

The first H4 bar of the day is giving you also this value so when iTime 4hour bar is same as daily bar you can take the high and low of that bar


Thats very true, never thought of that ....thanks very much for that deVries!
 
JoBlo:

My problem is, how do I make the EA check only the bars after the new days has started, ie, once the EA confirms that

there is a new day, if I tell it to check the highest/lowest values for the last 4 (1 hour) bars, it will check bars that were in
the previous day. I need it to only count the bars of the new day.

Would I need to sleep the EA for 4 hours ?? :)

If you must wait for the 4 hour period to expire before you can trade you might as well not do anything until Hour() is 4.

You don't need to use 1 hour bars. An H4 bar gives the same information. In fact any chart gives the same information since you only need the High and Low over the 4 hour period from the start of day.

I have seen lots of discussion of this type of thing over the last few months. There seem to be lots of exceptions that make simple code break (which I can't remember).

My opening shot is to take the high and low of the previous H4 bar when Hour() equals 4 for the first time.

 
dabbler:

If you must wait for the 4 hour period to expire before you can trade you might as well not do anything until Hour() is 4.

You don't need to use 1 hour bars. An H4 bar gives the same information. In fact any chart gives the same information since you only need the High and Low over the 4 hour period from the start of day.

I have seen lots of discussion of this type of thing over the last few months. There seem to be lots of exceptions that make simple code break (which I can't remember).

My opening shot is to take the high and low of the previous H4 bar when Hour() equals 4 for the first time.



That you very much dabbler....I really appreciate the help.. I will give your opening shot a go.
 

  1. must wait until there are 4 hours from the start of the day.
  2. On UTC+0 brokers, Sunday has only 2 hours. So the H4 bar is also a problem.
  3. If it's the first 4 hours do you want the current H/L (H4 bar zero) or the previous day's? and what about Sunday.
  4. https://www.mql5.com/en/forum/127483 reported that DayOfWeek() always returns 5 in the tester. So I never use those functions like Hour(). I only use TimeHour(Time[0]) etc.
datetime now  = Time[0],
         bod  = now - now % 86400; // Beginning of the day
int      iBod = iBarShift(NULL,0, bod),
         nH4  = 4 * 60 / Period(), // Number of bars for 4 hours
         iH4  = iBod - nH4 + 1;
if (iH4 <= 0) return;
double HH = iHighest(NULL,0, MODE_HIGH,nH4,iH4)
double LL =  iLowest(NULL,0, MODE_LOW, nH4,iH4) 
 
WHRoeder:

  1. must wait until there are 4 hours from the start of the day.
  2. On UTC+0 brokers, Sunday has only 2 hours. So the H4 bar is also a problem.
  3. If it's the first 4 hours do you want the current H/L (H4 bar zero) or the previous day's? and what about Sunday.
  4. https://www.mql5.com/en/forum/127483 reported that DayOfWeek() always returns 5 in the tester. So I never use those functions like Hour(). I only use TimeHour(Time[0]) etc.


Excellent stuff....thanks very much for that WHRoeder. The Broker I am using is GMT +3. It's strange how DayOfWeek() won't work as expected in tester ! I am glad
you let me know, it has saved me a lot of frustration! ALso, it is indeed the H/L of the current H4 bar. I want to establish a channel based on the highest point and lowest point
achieved in the first 4 hours of the day. Thank you for taking the time to respond, I will try what you have suggested :)

 
Dear WHroeder,
I have similar strategy but at 1st bar H1 tame frame,
Need your help please check that my script are correct?
Normally It can be replaced with existing indicator - attached below -, but I cannot use iCustom caused my limited  skill.
   datetime now  = Time[0],
            bod  = now - now % 86400; // Beginning of the day
        int iH1  = iBarShift(NULL,0,bod);// 1st bar of the day
        if (iH1 <= 0)return (iH1);
     double  HH1 = iHigh(NULL,0,iH1);
     double  LH1 = iLow(NULL,0,iH1);

if  i can ,i prefer to use iCustom thats isier to check during back test.
Files:
Reason: