English

## Function of "trading at certain hours" strategy

Back to topics list To post a new topic, please log in or register
 103 johnnybegoode 2016.09.15 23:29   Do you have a Function of "trading at certain hours" strategy?I would like to test if EA works better 24hrs or during certain hours.
 Moderator3517 GumRai 2016.09.15 23:36 #   There is no standard function in mql4 to do this.You will need to write your own function.If you have problems, post your code for your function and I  am sure that someone will help you.
 19 alexlearnmql 2016.09.18 15:31 #   Use hour function with if statement.
 1 fxreedom 2016.09.18 18:44 #   maybe something like this: input int StartHour=0;input int StartMinute=0;input int EndHour=2;input int EndMinute=0;  if IsTime(StartHour,EndHour,StartMinute,EndMinute) ... open trade here   bool IsTime (int startHour, int endHour, int startMinute, int endMinute){   if (startHour < 0 || startHour > 23 || endHour < 0 || endHour > 23 ||       startMinute < 0 || startMinute > 59 || endMinute < 0 || endMinute > 59)       return false;      int startTime = startHour*60 + startMinute;   int endTime = endHour*60 + endMinute;   int time = Hour()*60 + Minute();      if (startTime < endTime)      return (time >= startTime && time <= endTime);   else if (startTime > endTime)      return (time >= startTime || time <= endTime);   else      return (time == startTime);}
 19 alexlearnmql 2016.09.18 20:43 #   Something like this, you just need to offset the server time on depending where you live. The hour function does work as I have used it. ```bool tradetime; tradetime=false; if(Hour()>=12 && Hour()<24){ tradetime=true;}```

To add comments, please log in or register