Slippage Injection Simulator
A backtest that fills every order at the exact requested price is measuring a strategy that does not exist. Real execution rejects orders during volatility, and even accepted orders fill worse than requested more often than better. Students of strategy design usually have to learn this the expensive way, on a live account, because nothing in a standard backtest shows them the gap while it still costs nothing to see. This EA runs one placeholder signal through two accounts at once. The NAIVE track fills every signal instantly at the exact price requested, with zero cost - this is what a naive backtest implicitly assumes. The REALISTIC track rolls a random chance of outright rejection for every signal (a missed trade, not a losing one - its cost only shows up when the missed trade would have won), and for every fill it does get, adds a randomised amount of adverse slippage against the trade direction, on both entry and, optionally, the exit. The chart Comment reports both tracks' equity side by side and the exact gap between them, in money and in percentage points. The one deliberate realism touch is that rejection probability and slippage magnitude both scale up together when the current spread is wide (InpStressAtHighSpread). Execution gets worse exactly when liquidity is thin - during news, at rollover, in a fast market - which is also when a fragile, over-optimised strategy is most likely to be leaning hard on a signal. Constant, spread-blind slippage misses that correlation entirely and understates how much a real strategy actually loses to it. Notes and limitations - This tool is paper simulation only. No OrderSend call exists in this file, and no real position is ever opened. - A rejected signal is a missed trade, not a simulated loss - it costs the realistic track nothing directly, but denies it any gain the naive track banked from that same trade, which is itself the point. - The injected slippage and rejection numbers are illustrative defaults, not a calibrated model of any specific broker's real execution quality; use BrokerFillQualityComparator from this same catalogue if you want numbers measured from an actual account instead of assumed. - The placeholder MA-cross signal exists only to drive both tracks with something; it is not a strategy recommendation.
Expert advisor · MT4 · v1.0 · Free
About Slippage Injection Simulator
Slippage Injection Simulator is a script for MetaTrader 4 based on Moving Average. It can alert you with a pop-up, sound, email or push message. It has 13 settings, such as Fast ma period, Slow ma period and Hold bars. MQL source code included.
Files in the download: SlippageInjectionSimulator.ex4, SlippageInjectionSimulator.mq4, SlippageInjectionSimulator.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Fast ma period | 10 | Fast MA period for the placeholder signal |
| Slow ma period | 30 | Slow MA period for the placeholder signal |
| Hold bars | 10 | Bars every paper trade is held before closing |
| Starting balance | 10000.0 | Simulated starting balance for both tracks |
| Lots | 0.10 | Fixed lot size used by both tracks |
| Base rejection percent | 8.0 | Base chance a signal is rejected outright, percent |
| Min slippage pips | 0.3 | Minimum injected adverse slippage per fill, pips |
| Max slippage pips | 2.5 | Maximum injected adverse slippage per fill, pips |
| Apply slippage on exit | true | Also inject slippage on the closing fill, not just entry |
| Stress at high spread | true | Scale up rejection and slippage when spread is wide |
| Spread stress pips | 3.0 | Spread at/above this is treated as a stressed market |
| Stress multiplier | 3.0 | Multiplier applied to rejection% and slippage while stressed |
| Random seed | 0 | 0 = seed from GetTickCount(); any other value = fixed seed |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Buy/Sell Arrows · Alerts · Moving Average · MT4 Expert Advisor · MQL4 Source Code