Check if trades are allowed for specific symbol

 

Hi to all

I built an EA for the strategy that I'm used to use.
This EA always open two orders for two different symbols.

In normal conditions all works fine, but, if for some reason due to the broker the second symbol is not tradable, the EA open succesfully the first order but not the second one and this is not acceptable by my strategy.

Is there a way in MQL4 to check if trades are allowed by the broker?

Thanks and regards

Diego

 
diego.pianarosa: the EA open succesfully the first order but not the second one
  1. It is likely your code. Remember that all Predefined variables (Ask, Bars, Bid, Close[], High[], Low[], Open[], Point, Time[], Volume[]) are for the current chart symbol.

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

    The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

 
William Roeder:
  1. It is likely your code. Remember that all Predefined variables (Ask, Bars, Bid, Close[], High[], Low[], Open[], Point, Time[], Volume[]) are for the current chart symbol.

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

    The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

Thanks William, 

I'm not sure if your solution will be useful for my case.
I went in deep about the problem and, for example, what happened today is:

1. I try to open a order on CAC index
2. The market was open but short selling was proibited by the broker
3. The EA returned the error #133

So my question is, Is there the possibility to check and avoid problems in situation like this?
BR

Diego

 
diego.pianarosa:

Thanks William, 

I'm not sure if your solution will be useful for my case.
I went in deep about the problem and, for example, what happened today is:

1. I try to open a order on CAC index
2. The market was open but short selling was proibited by the broker
3. The EA returned the error #133

So my question is, Is there the possibility to check and avoid problems in situation like this?
BR

Diego

Try this reference.

For more information about symbols properties https://docs.mql4.com/constants/environment_state/marketinfoconstants#enum_symbol_info_string

if(SymbolInfoString(Symbol(),ENUM_SYMBOL_TRADE_MODE) == SYMBOL_TRADE_MODE_FULL)
   {
    ...................................
   }
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
A zero value of MODE_STOPLEVEL means either absence of any restrictions on the minimal distance for Stop Loss/Take Profit or the fact that a trade server utilizes some external mechanisms for dynamic level control, which cannot be translated in the client terminal. In the second case, GetLastError() can return error 130, because MODE_STOPLEVEL...
 
Nikolaos Pantzos:

Try this reference.

For more information about symbols properties https://docs.mql4.com/constants/environment_state/marketinfoconstants#enum_symbol_info_string

Hi Nikolaos and thanks for the answer.

I had to modify your code because on MQL4 the syntax you wrote isn't working, I created a function like the one below but unfortunatly the problem is not solved, the function returns true, but the order fails again with error #133


bool CheckIfTradeIsAllowed(string s1, string s2)
{
   if (SymbolInfoInteger(s1, SYMBOL_TRADE_MODE) != SYMBOL_TRADE_MODE_FULL)
   {
      Alert("Trade for symbol " + s1 + " is not allowed");
      return false;
   }
   if (SymbolInfoInteger(s2, SYMBOL_TRADE_MODE) != SYMBOL_TRADE_MODE_FULL)
   {
      Alert("Trade for symbol " + s2 + " is not allowed");
      return false;
   }
   return true;
}
Reason: