Skip to content

EA Doctor rule · Trade requests

Filling mode not taken from the symbol

Raw trade requests go out with a fixed filling type, or the default Fill or Kill, instead of one the symbol allows, which brokers refuse with 10030.

Why it matters

Every symbol allows only some filling types, listed in SYMBOL_FILLING_MODE: Fill or Kill, Immediate or Cancel, or Return. A request with a type the symbol does not allow is refused with 10030 (invalid filling type).

ORDER_FILLING_FOK is the value 0, so a MqlTradeRequest whose type_filling is never set asks for Fill or Kill. An EA that works on a broker allowing it then fails on one that allows Immediate or Cancel only. The standard library's CTrade corrects the type for market execution itself (its FillingCheck() in Trade.mqh), so this rule looks at raw requests.

When the rule fires

A MqlTradeRequest gets a fixed type_filling = ORDER_FILLING_…, or the file sends OrderSend() requests and never sets type_filling; and the file never reads SYMBOL_FILLING_MODE.

When it stays quiet

The code reads SYMBOL_FILLING_MODE (or its flags SYMBOL_FILLING_FOK / SYMBOL_FILLING_IOC), or trades through CTrade only.

How to fix it

  1. Read (int)SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE) once per symbol.
  2. Use ORDER_FILLING_FOK when the SYMBOL_FILLING_FOK flag is set, ORDER_FILLING_IOC when SYMBOL_FILLING_IOC is set, and ORDER_FILLING_RETURN otherwise.
  3. Or send the order with CTrade, which does this for market execution.

Code that fires it

MQL5 · fires this rule
bool OpenBuy()
  {
   MqlTradeRequest req = {};
   MqlTradeResult  res = {};
   req.action       = TRADE_ACTION_DEAL;
   req.symbol       = _Symbol;
   req.volume       = InpLots;
   req.type         = ORDER_TYPE_BUY;
   req.price        = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   req.type_filling = ORDER_FILLING_FOK;
   req.magic        = InpMagic;
   return(OrderSend(req, res) && res.retcode == TRADE_RETCODE_DONE);
  }

Fixed code

MQL5 · fixed
ENUM_ORDER_TYPE_FILLING FillingFor(const string symbol)
  {
   const int modes = (int)SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE);
   if((modes & SYMBOL_FILLING_FOK) != 0)
      return(ORDER_FILLING_FOK);
   if((modes & SYMBOL_FILLING_IOC) != 0)
      return(ORDER_FILLING_IOC);
   return(ORDER_FILLING_RETURN);
  }

bool OpenBuy()
  {
   MqlTradeRequest req = {};
   MqlTradeResult  res = {};
   req.action       = TRADE_ACTION_DEAL;
   req.symbol       = _Symbol;
   req.volume       = InpLots;
   req.type         = ORDER_TYPE_BUY;
   req.price        = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   req.type_filling = FillingFor(_Symbol);
   req.magic        = InpMagic;
   return(OrderSend(req, res) && res.retcode == TRADE_RETCODE_DONE);
  }

The fixed code shows this rule’s fix and compiles in MetaEditor for MetaTrader 5 (with CTrade trade, InpLots and InpMagic declared, as in a typical EA). Other rules may still apply to it as a fragment: check your whole EA.

More rules on trade requests

Sources

Get your EA fixed

Check a whole EA for this and 29 other mistakes with EA Doctor, free and in your browser. Or send it to us: we confirm the price in writing, then fix it.