Jump to content

(Request) How to code this simple command


swordfish

Recommended Posts

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.

Link to comment
Share on other sites

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 by maven
Link to comment
Share on other sites

//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 by swordfish
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...