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 zoneconstint servergmt=0;
//
servertime=TimeLocal()+TimeGMTOffset()-servergmt*3600;
if (TimeDayOfWeek(servertime)==6) returnfalse;
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 {
returnfalse;
}
}
The drawback is that you have to insert manually the server location GMT offset (in hours) in the servergmt assignment.
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?
Same issue, different approach: since there is a trade server error "ERR_MARKET_CLOSED", why not try to use it? Idea: try to create a pending order with correct values, so that if it fails, we get this error as a return code. Tried, seems to work fine:
bool isMarketClosed() {
// try to create a pending order far enough from the current price
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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.
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
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?
Maybe when there's no tick's coming in ??
Or when servertime is frozen ?
Hi everyone, my first contribution :-D
Same issue, different approach: since there is a trade server error "ERR_MARKET_CLOSED", why not try to use it? Idea: try to create a pending order with correct values, so that if it fails, we get this error as a return code. Tried, seems to work fine:
}
I personally find it elegant, but I may be a bit biased :-D
Feedback welcome.
Own feedback:
Found this in another thread: MarketInfo(Symbol(), MODE_TRADEALLOWED)
0 if closed, 1 if open
Seems to work, but compiled literally 1 minute too late to check on my market of choice :-D
Hi all
I would like to check in the expert advisor if the markt is open/close. What's the easiest way to do that?
I don't want do check that over time. I also need to know when the market open again after the short close every day at 11pm.
Thanks
FX_TA