Slippage Control in MQL4: Precision Order Execution
The Logic of the Tolerance: What is the Slippage Parameter?
In the OrderSend() function of MQL4, one of the most important arguments is the Slippage. This integer value (measured in 'Points') tells the broker's server how much price deviation you are willing to accept from your requested price.
Because the Forex market moves in milliseconds, the price you see on your screen might be slightly different from the price the broker's server has at the moment your order arrives. The slippage parameter is your 'Safety Margin'. If the price has moved more than your limit, the order is rejected (Requoted). If it is within the limit, the order is filled at the best available price.
Points vs. Pips: The 5-Digit Broker Trap
A common mistake for new developers is confusing 'Points' with 'Pips'. On a standard 5-digit broker, a 'Point' is 1/10th of a 'Pip'. If you want to allow 3 pips of slippage, you must set the slippage parameter to 30. If you set it to 3, you are only allowing 0.3 pips—which is so small that your EA will face constant 'Error 136' (Off Quotes) rejections during even minor market volatility.
{ Slippage Control Checklist }
Primary: Set slippage in Points (30 points = 3 pips on 5-digit brokers)
Constraint: Use a higher slippage for 'Market Execution' placeholders
Threshold: 3-5 pips is the industry standard for retail EAs
Sequence: RefreshRates() before calling OrderSend()
Verified: Check the 'Experts' tab for Error 136/138 (Requotes)
Risk: Be aware that high slippage can reduce your Risk-Reward ratio
Strategy: Slippage in Instant vs. Market Execution
Instant Execution: The slippage parameter is strictly enforced. If the price is 1 point outside your limit, you get a requote. This gives you control over the price but can lead to missed trades.
Market Execution (ECN): The slippage parameter is often ignored by the broker. You are filled at the 'Next available price' regardless of what you put in the OrderSend() function. On ECN accounts, the slippage parameter is usually set to a large value (like 100) as a placeholder, as the actual market fill logic happens at the liquidity provider level.
Coding Best Practice: The Dynamic Slippage Filter
For advanced EAs, you can code a Dynamic Slippage Filter. During quiet market times, the EA uses a tight slippage (e.g., 2 pips). During high-volatility events (measured by ATR or a news filter), the EA automatically widens the slippage to 10 pips to ensure the trade is filled. This 'Adaptive' execution style ensures you capture the fast-moving breakouts that a fixed-slippage EA would miss.