Edgoro
Trade server return code 10030 · MQL5

MT5 error 10030 Unsupported filling mode: fix

Fix MetaTrader 5 retcode 10030 (invalid filling type, "unsupported filling mode"): read the symbol's filling flags and pick FOK, IOC or Return in MQL5.

Trade server return code · MqlTradeResult.retcode
10030 TRADE_RETCODE_INVALID_FILL
“Invalid order filling type”

What it means

The request asks for a filling policy that the symbol doesn't accept. The policy (type_filling) says what happens when the full volume isn't available at once: Fill or Kill (FOK), Immediate or Cancel (IOC) or Return. MetaQuotes' description is "Invalid order filling type"; traders and many EAs report it as "unsupported filling mode". The order isn't executed.

Usual causes

  • A request built by hand keeps the default. MqlTradeRequest req = {} leaves type_filling at 0, which is ORDER_FILLING_FOK. On a symbol that only allows IOC, every order fails.
  • Return on a Market Execution symbol. ORDER_FILLING_RETURN is never allowed in Market Execution mode, whatever the symbol's settings.
  • A policy copied from another broker. Code tested where FOK was allowed fails where only IOC is (or the reverse). That's why the same EA works on one account and not on another.
  • CTrade with a forced policy. For Market Execution symbols, recent versions of the standard library's CTrade pick FOK or IOC from the symbol's flags before sending. For Exchange Execution symbols they use the policy you set with SetTypeFilling(), and return 10030 without sending when the symbol doesn't allow it.
  • Pending orders. MetaQuotes' reference says to use ORDER_FILLING_RETURN for pending orders, whatever the execution mode.

How to detect it

  • result.retcode (or trade.ResultRetcode()) is 10030, and GetLastError() returns 4756.
  • Print what the symbol allows: SymbolInfoInteger(_Symbol, SYMBOL_FILLING_MODE) is a set of flags (SYMBOL_FILLING_FOK = 1, SYMBOL_FILLING_IOC = 2, SYMBOL_FILLING_BOC = 4), and SYMBOL_TRADE_EXEMODE gives the execution mode. Compare them with the type_filling your request used.

Broken code

This script compiles, and opens a minimum-volume buy when run. On a symbol that doesn't allow Fill or Kill, it fails with 10030.

MQL5
void OnStart()
  {
   MqlTradeRequest req = {};
   MqlTradeResult  res = {};
   req.action    = TRADE_ACTION_DEAL;
   req.symbol    = _Symbol;
   req.volume    = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   req.type      = ORDER_TYPE_BUY;
   req.price     = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   req.deviation = 10;
   // type_filling is never set: it stays at 0, ORDER_FILLING_FOK
   if(!OrderSend(req, res))
      PrintFormat("OrderSend failed: retcode %u", res.retcode);
  }

Fixed code

The same program with the check that prevents the error. It compiles in MetaEditor with 0 errors and 0 warnings.

MQL5
// Picks a filling policy the symbol accepts for a market order; false if none fits
bool PickFilling(const string symbol, ENUM_ORDER_TYPE_FILLING &filling)
  {
   ENUM_SYMBOL_TRADE_EXECUTION exec = (ENUM_SYMBOL_TRADE_EXECUTION)SymbolInfoInteger(symbol, SYMBOL_TRADE_EXEMODE);
   long flags = SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE);
   // Instant and Request execution accept FOK whatever the symbol's flags
   if(exec == SYMBOL_TRADE_EXECUTION_INSTANT || exec == SYMBOL_TRADE_EXECUTION_REQUEST)
     {
      filling = ORDER_FILLING_FOK;
      return true;
     }
   if((flags & SYMBOL_FILLING_FOK) == SYMBOL_FILLING_FOK)
     {
      filling = ORDER_FILLING_FOK;
      return true;
     }
   if((flags & SYMBOL_FILLING_IOC) == SYMBOL_FILLING_IOC)
     {
      filling = ORDER_FILLING_IOC;
      return true;
     }
   // Return is allowed in Exchange Execution, never in Market Execution
   if(exec == SYMBOL_TRADE_EXECUTION_EXCHANGE)
     {
      filling = ORDER_FILLING_RETURN;
      return true;
     }
   return false;
  }

void OnStart()
  {
   ENUM_ORDER_TYPE_FILLING filling;
   if(!PickFilling(_Symbol, filling))
     {
      Print("No filling policy fits this symbol: check its specification");
      return;
     }
   MqlTradeRequest req = {};
   MqlTradeResult  res = {};
   req.action       = TRADE_ACTION_DEAL;
   req.symbol       = _Symbol;
   req.volume       = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   req.type         = ORDER_TYPE_BUY;
   req.price        = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   req.deviation    = 10;
   req.type_filling = filling;
   if(!OrderSend(req, res))
      PrintFormat("OrderSend failed: retcode %u (%s)", res.retcode, res.comment);
   else
      PrintFormat("Sent with %s: retcode %u", EnumToString(filling), res.retcode);
  }

Why the fix works

PickFilling() follows the rules of MetaQuotes' reference. In Instant and Request execution, FOK and IOC are accepted whatever the flags say. In Market and Exchange execution, FOK and IOC are allowed only when the symbol's flags include them. Return is always allowed in Exchange execution and never in Market execution. The request then carries a policy the server accepts, on any broker.

If you use CTrade, call trade.SetTypeFillingBySymbol(_Symbol) in OnInit and check its result: it sets FOK when the flag is there, otherwise IOC, and returns false when neither flag is set.

Filling policies by execution mode

Execution mode (SYMBOL_TRADE_EXEMODE)FOKIOCReturn
InstantAlwaysAlwaysAlways
RequestAlwaysAlwaysAlways
MarketIf the symbol's flag is setIf the symbol's flag is setNever
ExchangeIf the symbol's flag is setIf the symbol's flag is setAlways

A Market Execution symbol with neither the FOK nor the IOC flag has no policy that works for market orders; the symbol's specification in the terminal, or the broker, is then the place to look.

Questions

Which filling mode should my MT5 EA use?

The one the symbol allows, read at run time. There's no single answer across brokers: read SYMBOL_FILLING_MODE and SYMBOL_TRADE_EXEMODE, then choose FOK, IOC or Return accordingly, or let CTrade's SetTypeFillingBySymbol() choose between FOK and IOC.

Does SetTypeFillingBySymbol() fix error 10030?

Usually. It sets FOK when the symbol's flags allow it, otherwise IOC, and returns false when neither flag is set. It never chooses Return, which an Exchange Execution symbol without FOK or IOC needs, so check its return value.

Why does the same EA work on one broker and fail with 10030 on another?

Filling flags and execution modes are set per broker, account type and symbol. An EA that hard-codes one policy works only where that policy is allowed. Reading the flags at run time makes it portable.

Which filling policy do pending orders use?

MetaQuotes' reference says to use ORDER_FILLING_RETURN for pending orders regardless of the execution mode, since they aren't executed when you send them.

The programs on this page are minimal examples written to show the error and its fix, not trading systems. Some of them send orders when they run: try them on a demo account. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.

Working code that avoids it

All MQL5 examples

Rather not write the error handling yourself?

Edgoro's MT5 EA generator writes complete MQL5 Expert Advisors from plain English and compiles each one in MetaEditor before you get it. A clean build proves the code compiles, not that a strategy works: test it on a demo account.