SymbolInfoInteger(Symbol(),SYMBOL_TRADE_MODE)
Do not give any information about the trading session, but just if trading is enabled on a symbol, or that symbol is set to "Close only" or not allowed totally to trade.
You should use the command
SymbolInfoSessionTrade
I personally use this function inside my EA (it was adjusted code of a snippet found around the web).
bool IsMarketOpen(const string symbol, const bool debug = false) { datetime from = NULL; datetime to = NULL; datetime serverTime = TimeTradeServer(); // Get the day of the week MqlDateTime dt; TimeToStruct(serverTime,dt); const ENUM_DAY_OF_WEEK day_of_week = (ENUM_DAY_OF_WEEK) dt.day_of_week; // Get the time component of the current datetime const int time = (int) MathMod(serverTime,PeriodSeconds(PERIOD_D1)); if ( debug ) PrintFormat("%s(%s): Checking %s", __FUNCTION__, symbol, EnumToString(day_of_week)); // Brokers split some symbols between multiple sessions. // One broker splits forex between two sessions (Tues thru Thurs on different session). // 2 sessions (0,1,2) should cover most cases. int session=2; while(session > -1) { if(SymbolInfoSessionTrade(symbol,day_of_week,session,from,to )) { if ( debug ) PrintFormat( "%s(%s): Checking %d>=%d && %d<=%d", __FUNCTION__, symbol, time, from, time, to ); if(time >=from && time <= to ) { if ( debug ) PrintFormat("%s Market is open", __FUNCTION__); return true; } } session--; } if ( debug ) PrintFormat("%s Market not open", __FUNCTION__); return false; }
Thank you very much!
MT5 Code
I'm using the above code but I still have the following erros during trading session.
I seem market can be closed during trading sessions.
Is there a way to avoid sending orders or modify requests if [market closed] ?
I'm using the above code but I still have the following erros during trading session.
I seem market can be closed during trading sessions.
Is there a way to avoid sending orders or modify requests if [market closed] ?
I guess some brokers do not write correct data in those fields and you have no way to detect the market closed. My suggestion is adding a time filter... That also keeps you away from high spread overnight condition.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all, I have the following error when market is closed
I tried to fix placing the followng code at the beginning of the expert, but it doesn't work.
Could you help me?
Thank you!