Download MetaTrader 5

How can I let EA run from 23:00 to 09:00 (GMT time)?

To add comments, please log in or register
HongDi s& t development co.,ltd.
1605
hongbin fei 2016.02.16 03:40 
any code to share?
Abdul Rahman
1370
Abdul Rahman 2016.02.16 04:19  
void OnTick()  {


//call the function

if(TimeAllow(23,9)>0) {
   //your code here...

}


}


int TimeAllow(int s, int e) {

   int start_time, end_time;
   int gmt_hour=TimeHour(TimeGMT());
   if(s>e) {
      if(gmt_hour>=s) {
         start_time=s;
         end_time=24+e;
      } else {
         start_time=0;
         end_time=e;
      }
   } else { start_time=s; end_time=e; }
   if(gmt_hour>=start_time && gmt_hour<=end_time) return(1);
return(0);
}


HongDi s& t development co.,ltd.
1605
hongbin fei 2016.02.16 04:48  
Abdul Rahman:
void OnTick()  {


//call the function

if(TimeAllow(23,9)>0) {
   //your code here...

}


}


int TimeAllow(int s, int e) {

   int start_time, end_time;
   int gmt_hour=TimeHour(TimeGMT());
   if(s>e) {
      if(gmt_hour>=s) {
         start_time=s;
         end_time=24+e;
      } else {
         start_time=0;
         end_time=e;
      }
   } else { start_time=s; end_time=e; }
   if(gmt_hour>=start_time && gmt_hour<=end_time) return(1);
return(0);
}


many thanks
Osama Shaban
1463
Osama Shaban 2016.02.16 18:14  

I use something like this ...

It works fine ... 

input bool         UseTimeFilter = true;                //**Use Time Filter For Trading Hours
input int              StartHour = 18;                  //**Starting Hour 
input int                EndHour = 6;                   //**Ending Hour

bool EAActivated;

...
...
...

int start(){

   if((Hour()>=StartHour && Hour()<EndHour && StartHour<EndHour) || ((Hour()>=StartHour || Hour()<EndHour) && StartHour>EndHour))
      EAActivated=true; 
   else
       EAActivated=false; 

   if(EAActivated && ... && ... && ...)
      OpenBuy();

   if(EAActivated && ... && ... && ...)
      OpenSell();

   ...
   ...
   ...
}
To add comments, please log in or register