How to check if trading is enabled using MQL5

Hi,

I wonder if it’s possible to do a check from mql5 code if trading of certain instrument at a given time is possible. The reason I’m asking this is, because my EA, opens multiple orders of different instruments, it is some kind of “hedging” strategy. So the problem I’ve faced when testing it on demo account is, that my EA opened position of EURUSD but couldn’t USDJPY, because broker temporarly disabled opening new positions with this instrument on some heavy news events. So before I open any position I would like to check if all insturments I need are “allowed to trade”, if not, I don’t trade.

I’ve found this thread https://www.mql5.com/en/forum/153486, but looks similar to what I need, but if I try to use this comand, compiler doesn’t recognize it, so it looks it is not availabe anymore in newer builds of MT5. Any other idea maybe?

Much thanks for your input.

In the mean time, I’ve checked the MQL5 docs and have found SYMBOL_ORDER_MARKET, which means “Market orders are allowed (Buy and Sell)”

//+------------------------------------------------------------------+
//| The function prints out order types allowed for a symbol         |
//+------------------------------------------------------------------+
void Check_SYMBOL_ORDER_MODE(string symbol)
  {
//--- receive the value of the property describing allowed order types
   int symbol_order_mode=(int)SymbolInfoInteger(symbol,SYMBOL_ORDER_MODE);
//--- check for market orders (Market Execution)
   if((SYMBOL_ORDER_MARKET&symbol_order_mode)==SYMBOL_ORDER_MARKET)
      Print(symbol+": Market orders are allowed (Buy and Sell)");
//--- check for Limit orders
   if((SYMBOL_ORDER_LIMIT&symbol_order_mode)==SYMBOL_ORDER_LIMIT)
      Print(symbol+": Buy Limit and Sell Limit orders are allowed");
//--- check for Stop orders
   if((SYMBOL_ORDER_STOP&symbol_order_mode)==SYMBOL_ORDER_STOP)
      Print(symbol+": Buy Stop and Sell Stop orders are allowed");
//--- check for Stop Limit orders
   if((SYMBOL_ORDER_STOP_LIMIT&symbol_order_mode)==SYMBOL_ORDER_STOP_LIMIT)
      Print(symbol+": Buy Stop Limit and Sell Stop Limit orders are allowed");
//--- check if placing a Stop Loss orders is allowed
   if((SYMBOL_ORDER_SL&symbol_order_mode)==SYMBOL_ORDER_SL)
      Print(symbol+": Stop Loss orders are allowed");
//--- check if placing a Take Profit orders is allowed
   if((SYMBOL_ORDER_TP&symbol_order_mode)==SYMBOL_ORDER_TP)
      Print(symbol+": Take Profit orders are allowed");
//---
  }

Would this tell me if opening positions is allowed for that symbol? Thanks for you help.

Your link is about MT4, this function is not available with MT5.
The start of this article explain how to use the SymbolInfoSession API, with code example.

Here is what I get for EURUSD on Metaquotes-Demo server :

And I do have data until 23:59.

Probably, but have found it on “mql5.com” so thought it’s MT5…

Anyway great suggestion. I guess I should use SymbolInfoSessionTrade and not SymbolInfoSessionQuote, because quotes my still be available but opening orders not. In my case the broker blocked opening positions of NZDUSD, but still let closing them, to those, who already have opened them before this session. So big question no. 1 now is:

Would there be a trade session or not in this case? I hope not, but this is hard to test.

The second thougt is: SymbolInfoSessionTrade looks like retrieving “general info” about when trading enabled for certain security, I susspect that because there is no date retrieved, just time of day? But ok, let suppose this relates to the week following. But do brokers really adjust this sessions on some “heavy news”? I mean, suppose a news is to come out at 15:00 PM will I get info like this:

(EURUSD,M1) Monday: session index=0 start=00:05 finish=13:59:59

(EURUSD,M1) Monday: session index=1 start=17:05 finish=23:59:59

I mean do brokers really give info like these, what are your experiences? Besides, is the time I get Server Time?

Much thanks again.

1)Wrong assumption. If you see some candles forming and price moving, that doesn’t yet mean the market is open to accept your order…In my case broker allowed only closue of position of NZD related securities in that few hours. Here is part of their response to my ticket:

"Please note that as the news release was scheduled to take place during the daily bank rollover , there was a high possibility of increased volatility which was very likely to affect NZD-based instruments .

In light of the above, all the NZD-based instruments were switched into “Close-only” mode from 21/06/2017 23:30:00 until 22/06/2017 00:30:00 (MT4 Server Time)."

  1. Good.

  2. Won’t repeat it again, that was the case and my question was how could I detect such limitations programatically from MQL5. SymbolInfoSessionTrade was good suggestion, but if the broker doesn’t adjust that when necessary, it’s more or less useless. Well it gives you some “general” trading session periods, but that’s not enough for my needs. Please reread from begining.

Anyway I’m still trying to figure out how to do this, but as much as I’ve back tested with EA, trade sessions remain as they are, they don’t change :frowning: