swordfish Posted April 20, 2011 Report Share Posted April 20, 2011 I want to start the EA at GMT 21 for a broker that is +3 GMT. You see, MT4 gets confused when GMT21 and +3 = 24 or zero. extern int GMTOffset = 3; extern int GMTStartHour = 21; GMTStartHour = GMTStartHour + GMTOffset; if (GMTStartHour >= 24) { GMTStartHour = GMTStartHour - 24; } GMTEndHour = GMTEndHour + GMTOffset; if (GMTEndHour >= 24) { GMTEndHour = GMTEndHour - 24; } As a result, the EA won't start. I apprecite it very much if you could give me a hint. Quote Link to comment Share on other sites More sharing options...
maven1713006117 Posted April 20, 2011 Report Share Posted April 20, 2011 (edited) The code below with your gmt offset incorporated into the start & stop hour will work. And you don't have a problem with start time being greater than the end time. //e.g. the ea will for run 4 hours between 10pm at night to 2am the next morning //use 0 for midnight extern int Hour_Start_Trade = 22; extern int Hour_Stop_Trade = 2; int gi_96 = 50; if (IsTradeTime()) {your code to be run} bool IsTradeTime() { if (Hour_Start_Trade < Hour_Stop_Trade && TimeHour(TimeCurrent()) < Hour_Start_Trade || TimeHour(TimeCurrent()) >= Hour_Stop_Trade) return (FALSE); if (Hour_Start_Trade > Hour_Stop_Trade && (TimeHour(TimeCurrent()) < Hour_Start_Trade && TimeHour(TimeCurrent()) >= Hour_Stop_Trade)) return (FALSE); if (Hour_Stop_Trade == 0) Hour_Stop_Trade = 24; if (Hour() == Hour_Stop_Trade - 1 && Minute() >= gi_96) return (FALSE); return (TRUE); } Edited April 20, 2011 by maven swordfish 1 Quote Link to comment Share on other sites More sharing options...
swordfish Posted April 20, 2011 Author Report Share Posted April 20, 2011 (edited) //e.g. the ea will for run 4 hours between 10pm at night to 2am the next morning //use 0 for midnight extern int Hour_Start_Trade = 22; extern int Hour_Stop_Trade = 2; int gi_96 = 50; } Maven, I assume the exmaple hours "22" and "2" are broker server time, not GMT time? So in order to run GMT21-7 for server GMT+3, the server time should be 24 to 10 or 0 to 10? Thank you so much. Edited April 20, 2011 by swordfish Quote Link to comment Share on other sites More sharing options...
maven1713006117 Posted April 20, 2011 Report Share Posted April 20, 2011 Maven, I assume the exmaple hours "22" and "2" are broker server time, not GMT time? So in order to run GMT21-7 for server GMT+3, the server time should be 24 to 10 or 0 to 10? Thank you so much. Yes your assumptions are right. I would use 0 to 10 in your example. When backtesting with the code using 0 for midnight (instead of 24) definitely works. Maven Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.