Download MetaTrader 5
To add comments, please log in or register
Having troubles understanding the code? Articles can help you!
Gordon Gekko
649
Gordon Gekko 2014.12.01 11:53 

Aloha Gurus!


I'd like my EA to do something every day between let's say 09:45 and 11:15, i.e. the EA runs continuously and when the time is within that interval then EA do make its job.

I know my friends are TimeHour and TimeMinute, but have no exact idea.

Have you any solution for it?

Thanx in advance

whroeder1
13602
whroeder1 2014.12.01 13:22  
You could use TimeHour and minute but it's easier to just to keep it a unit.
#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when % HR2400 );            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
//datetime Tomorrow( datetime when=0){      if(when == 0)  when = TimeCurrent();
//                                          return(DateOfDay(when) + HR2400);   }
//datetime Yesterday(datetime when=0){      if(when == 0)  when = TimeCurrent();
//   int iD1 = iBarShift(NULL, PERIOD_D1, DateOfDay(when) - 1);
//                                       return( iTime(NULL, PERIOD_D1, iD1) ); }

const int AM0945 = 35100; // ( 9 * 60 + 45) * 60
const int AM1145 = 42300; // (11 * 60 + 45) * 60

int now = TimeOfDay();
if(AM0945 <= now && now < AM1145) ...
Gordon Gekko
649
Gordon Gekko 2014.12.01 15:01  
WHRoeder:
You could use TimeHour and minute but it's easier to just to keep it a unit.

That's a fine solution, thank you WHRoeder!
/
To add comments, please log in or register