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
- Read
(int)SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE)once per symbol. - Use
ORDER_FILLING_FOKwhen theSYMBOL_FILLING_FOKflag is set,ORDER_FILLING_IOCwhenSYMBOL_FILLING_IOCis set, andORDER_FILLING_RETURNotherwise. - Or send the order with
CTrade, which does this for market execution.
Code that fires it
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
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.
Related MQL5 errors
More rules on trade requests
- HighOrderSend() result not checkedOrderSend() is called as a plain statement, so a refused or requoted order goes unnoticed and the EA carries on as if it traded.
- HighCTrade call result not checkedA CTrade method such as Buy(), Sell() or PositionClose() is called as a plain statement, so its failure is never seen.
- MediumPending orders judged by TRADE_RETCODE_DONE onlyThe EA places pending orders but treats every answer except TRADE_RETCODE_DONE as a failure, and an accepted pending order answers TRADE_RETCODE_PLACED.
- MediumTrade request not cleared before useA local MqlTradeRequest is declared without an initializer and never cleared, so the fields the code does not set hold leftover values.
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.