swordfish Posted April 20, 2011 Report 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.
maven1713006117 Posted April 20, 2011 Report 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
swordfish Posted April 20, 2011 Author Report 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
maven1713006117 Posted April 20, 2011 Report 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now