And therefore the most reliable way I know is using the all functions I mentioned in my first answer.
In MT5 yes, in MT4 no.
Do you try to be a little bit mysterious? Could you, please, share your opinion about the most reliable way in MT4?
UPDATE: Except catching errors by sending an order.
Not at all.
Why do you want to know when market is closed ? On Forex the open/close hours are well known, you can just check broker time, session time (I mean asian, europa, us sessions) and you will know if the market is open/close.
For metals or CFDS, you have sometimes a market close for 15 minutes or 1 hour, to know that the most reliable way is MarketInfo(symbol,MODE_TRADEALLOWED) (MT4).
For MT5 you can always use SymbolInfoSessionTrade().
Using last tick time is not really useful, as you can't make the difference between a closed market and a "slow" market.
I am working with a lot of customers and a lot of brokers, so I am talking in general, but of course I didn't check all brokers. Also it's probably always possible to find a broker who will provide data that contradicts the above.
I agree with you partially. But there could be a problem at weekends. Usually the broker time (CurrentTime()) stops one second before friday's session end. It causes in my opinion that the MarketInfo() isn't reliable at weekends. I don't know how MarketInfo() works exactly but I think it compares CurrentTime() with the session start/end. In this case you can't recognize a weekend by MarketInfo(). You should find out if the broker time is still running (with checking connection) if isn't running then a weekend is (and you should stop working).
You are right I can't recognize by the last tick time if the market is closed or slow. But for some CFDs at holidays isn't also reliable SymbolSessionTrade() and I don't know (I haven't tried it and I can try it at the next holiday) if the MarketInfo() provides true info. And the clue (not evidence) could be the last tick time.
What market info ? TRADE_ALLOWED? Yes it works at the week-end, if it works in general.
2018.03.11 19:36:21.388 SymbolInfoSessionTrade ...,M5: EURUSD: Trading session 0 start 00:00 to 23:00 TRADEALLOWED: 0
On this broker/symbol, it's correct. And SymbolInfoSessionTrade() is not. As this broker server stopped at 23:59:58
The only conclusion for everyone is try it yourself according to your needs, there is no universal solution by using a single function call.
Thank you Alain for your example. As far as your example is concerned I suppose that there isn't a session Nr. 1 (23:00-00:00)
I absolutely agree with your conclusion and thank you for nice chatting.
You are welcome. Code used was published in the below topic.
I'm also trying to check if the market is opened to trade stocks, I already tryed SymbolInfoSessionQuote() and SymbolInfoSessionTrade() but my broker doesn't supply realiable information about the open and close time.
* these information are incorrect, the market opens at 10:00h and closes at 17:00h.
So, is there another way?
Please enable the necessary setting in your browser, otherwise you will not be able to log in.