How to check if market is open or closed using MQL5

Please, how I can check if market is open or closed in MT5, I cant find answer.

something similar to MT4 - MarketInfo(Symbol(),MODE_TRADEALLOWED) this command doesn’t exist in MT5 anymore.

Thank you

MarketInfo(Symbol(),MODE_TRADEALLOWED) in MT4 isn’t reliable.

If you want to check Opened/Closed market you should use these functions together (both in MT4 and MT5):

SymbolInfoSessionTrade() => to find the last session start/end time

SymbolInfoInteger(_Symbol,SYMBOL_TIME) => to find out the last known tick time for the symbol

TimeCurrent() and TerminalInfoInteger(TERMINAL_CONNECTED) => to find out if the server is "ON"

Thank you for answer,

I dont know if mentioned command isn’t reliable, but it was working

SymbolInfoSessionTrade() show nonsense times and counting back difference between last tick and current time seems to be not reliable to me, it doesn’t meen that market is closed.

Why it isnot reliable ?

who told you MT4

MarketInfo(Symbol(),MODE_TRADEALLOWED) in MT4 is not working,are you new to mt4 or just trying to do what you can’t do…

Below is a log from a script I created to show you the reliability of MarketInfo(Symbol(),MODE_TRADEALLOWED). Both was run (as you can see) at this weekend (Market is closed) but EURUSD looks like the market is opened (by MarketInfo(Symbol(),MODE_TRADEALLOWED)).


2018.03.11 15:15:41.555 Script DAX_ecn,M15: Symbol: DAX_ecn ; Trade allowed: false ; Session trade from: 09:00:00 ; Session trade to: 22:59:00 ; [Current time:](https://www.mql5.com/en/docs/dateandtime/timecurrent) 23:57:59 ; Last tick time: 22:59:59 ; Local time: 15:15:41
2018.03.11 15:16:58.792 Script EURUSD_ecn,M15: Symbol: EURUSD_ecn ; Trade allowed: true ; Session trade from: 00:06:00 ; Session trade to: 23:58:00 ; Current time: 23:57:59 ; Last tick time: 23:57:59 ; Local time: 15:16:58

SymbolInfoSessionTrade() show me correct data (what do you mean by nonsense times?) see the log above in my answer to Alain.

It’s up to you. If you discover easier and reliable way, let me know.

I didn’t want to answer but… Be sure I’m not new to mt4. With your mql knowledge I wouldn’t try anything.

Sorry, my fault, timezone offset confused me a bit

yes, SymbolInfoSessionTrade() should be fine if it shows all and correct data

Thank you for help

Yes it should return when the market is open/close but is the documentation reliable ?

I am using it in some EA with some brokers and CFDs symbols and it’s reliable while SymbolInfoSession() is not available.

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

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.

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 @edrydales 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.

Hy guys,

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 reliable information about the open and close time.

56

  • these information are incorrect, the market opens at 10:00h and closes at 17:00h.

So, is there another way?

Only way is to ask your broker to provide reliable data I am afraid.

Hello Mr Erek, can you help me, about Market is closed , Thx