04. Slippage Mitigation & Order Logic
Slippage is the difference between the price at which your EA requests an order and the price at which the trade is executed by the liquidity provider (LP). Mathematically, slippage cost per trade is expressed as:
Cost_Slippage = (Fill_Price - Executed_Price) * Lot_Size * Contract_Size
While MT4 primarily supports basic Instant and Market execution types, MT5 introduces granular execution modes and order filling policies that actively prevent slippage drag:
- Fill or Kill (FOK): The order is executed strictly at the requested price or better. If the full volume is unavailable at the designated price, the order is completely canceled, preventing adverse partial fills.
- Immediate or Cancel (IOC): The trade fills as much volume as available at the requested price; any unfilled residual volume is instantly canceled rather than slipped into worse liquidity tiers.
- Limit Or Touch Execution: Using Buy Limit or Sell Limit orders guarantees price improvement or exact price fills, converting negative slippage into neutral or positive slippage.
Dynamic ATR Slippage Filter Rule: In MQL5 code, calculate current 1-minute ATR (Average True Range). If current spread + dynamic slippage buffer exceeds 20% of M1 ATR, suppress trading commands until liquidity stabilizes.