In MQL5, SYMBOL_FILLING_MODE is returned as a bitmask. You cannot use a simple equality check (==); you must use bitwise AND (&) operations to parse the supported modes.
Here is how to dynamically evaluate the broker's matching engine and apply the correct policy to your MqlTradeRequest.
1. The Dynamic Filling Mode Evaluator
Because you have already built an architecture capable of tracking Volume Weighted Average Price (VWAP) across partial fills, Immediate or Cancel (IOC) is your mathematically superior choice. It guarantees you sweep available liquidity without leaving passive orders on the book.
Fill or Kill (FOK) is "safer" from a math perspective (no slippage via partials), but when pushing high-volume lots, FOK will result in massive rejection rates because the book rarely has enough liquidity at a single price level to absorb the entire order instantly.
This helper function prioritizes IOC but safely falls back to whatever the broker allows.
Code: Select all
ENUM_ORDER_TYPE_FILLING GetOptimalFillingMode(const string symbol)
{
long fillModes = SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE);
// 1. Prioritize IOC for high-volume sweeping (Partials allowed, remainder killed)
if ((fillModes & SYMBOL_FILLING_IOC) != 0)
{
return ORDER_FILLING_IOC;
}
// 2. Fallback to FOK (No partials, entire order must fill instantly or be killed)
if ((fillModes & SYMBOL_FILLING_FOK) != 0)
{
return ORDER_FILLING_FOK;
}
// 3. Last resort: RETURN (Standard for Market Maker/B-Book accounts)
// Warning: This leaves unfilled remainder as a resting limit order.
return ORDER_FILLING_RETURN;
}