Download MetaTrader 5

is market open/close - page 2

To add comments, please log in or register
Paolo Miocchi
20444
Paolo Miocchi  

A solution could be this one... though not so elegant :-) ....

 

bool IsMarketOpen() {
  datetime from,to,now;
  datetime servertime;
 
  // put here the GMT offset (in hours) of the server time zone
  const int servergmt=0;
  //  
  servertime=TimeLocal()+TimeGMTOffset()-servergmt*3600;
  if (TimeDayOfWeek(servertime)==6) return false;
  now=StringToTime(TimeToStr(servertime,TIME_DATE));
  if (SymbolInfoSessionTrade(Symbol(),TimeDayOfWeek(servertime),0,from,to)) {
    to = to+now;
    from = from+now;
    return (servertime<to && servertime>from); 
  } else {
    return false;
  }

}

 The drawback is that you have to insert manually the server location GMT offset (in hours) in the servergmt assignment.

Gustavo Hennemann
194
Gustavo Hennemann  
Tucu Titus Corneliu:

Ohhh, come ooonnn ... you are, too ... when you are present and responsive ! :D

Anyway, I looked over the suggested code in the links and the solution is far from elegant. I mean, I have to loop through the sessions of the day, pick the last one (I presume), check if I am between it's open and close time and get the answer. I wonder if I should test for connection as well. Ain't that too much ? Really, guyz, you are "heavy weight" in MQL and in this forum, maybe a little lobby towards MetaQuotes to introduce "MarketInfo(Symbol(), MODE_MARKETOPEN)" isn't such a bad ideea !

Thank you, both, very much indeed !

Titus 

I think I'm a litle late, but I agree. Is there not something better?

Also, theses solutions work for holidays and days off?

Thanks

Gustavo Hennemann
194
Gustavo Hennemann  
Paolo Miocchi:

A solution could be this one... though not so elegant :-) ....

 

 The drawback is that you have to insert manually the server location GMT offset (in hours) in the servergmt assignment.

Hi Paolo,

This solution works for holidays and days off too?

Marco vd Heijden
Moderator
5180
Marco vd Heijden  

Maybe when there's no tick's coming in ??

Or when servertime is frozen ?

12
To add comments, please log in or register