Adaptive Slippage Tolerance
A single fixed slippage figure in an EA's inputs is always wrong somewhere: too tight during a volatile hour, where it causes otherwise good orders to be rejected, and too loose during a quiet one, where it lets a genuinely bad fill through that a tighter figure would have refused. Neither MQL4 nor MQL5 exposes an API that reveals another program's requested-versus-filled price, so the only slippage this EA can honestly measure is its own - which is exactly what it does. It records the quote taken immediately before every order it sends, reads the actual fill price back once the order opens, and folds the absolute difference (in points) into a running mean and variance for that symbol and that hour-of-day, smoothed with exponential weighting so recent conditions matter more than old ones. The recommended slippage for a given hour is the mean plus a configurable number of standard deviations (InpSafetyMultiplier), clamped between a floor and a ceiling - a distribution-aware figure rather than either a fixed number or an unclamped one that could recommend something absurd after a single bad sample. Two ways to use it, via InpStandaloneMode. Off, it sends no orders of its own; it exists purely to publish AST_Recommended_<symbol> for another EA's order-send call to read before it trades. On, it periodically sends a tiny probe order (InpDemoLots, default 0.01) using its own current recommendation, measures the resulting slippage, feeds that measurement back into the same distribution, and - if InpCloseDemoImmediately is left on, the default - closes the probe again right away so the self-calibration loop does not leave real market exposure sitting on the account. Notes and limitations - Standalone mode genuinely sends real market orders (tiny ones, by default) purely to measure slippage - understand InpDemoLots and InpDemoIntervalMinutes before enabling it on a live account. - A freshly attached chart has no history for any hour, so every hour uses the fallback figure until enough real samples accumulate; this can take hours or days depending on trading frequency (publish-only mode) or the configured probe interval (standalone mode). - It measures slippage on THIS EA's own orders only - there is no mechanism on either platform to observe another program's requested-versus-filled price, so a recommendation built here is an estimate of broker/symbol/hour behaviour in general, not a guarantee for any other program's specific trade. - Statistics are stored in terminal global variables keyed by symbol; they persist across restarts but are shared across every chart of that symbol on this terminal, on both platforms. - On a netting-account MQL5 probe that merges into existing exposure, the close step only ever removes the probe's own volume; it does not touch volume that was already open before the probe fired.
Expert advisor · MT4 · v1.0 · Free
About Adaptive Slippage Tolerance
Adaptive Slippage Tolerance is an expert advisor (trading robot) for MetaTrader 4. It increases the lot size after a losing trade (martingale). It has 15 settings, such as Standalone mode, Safety multiplier and Min slippage points. MQL source code included.
Files in the download: AdaptiveSlippageTolerance.ex4, AdaptiveSlippageTolerance.mq4, AdaptiveSlippageTolerance.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Standalone mode | false | true = sends its own small demo orders and self-calibrates; false = publish-only |
| Safety multiplier | 2.0 | Recommended slippage = mean + this many standard deviations of recorded slippage |
| Min slippage points | 3.0 | Floor applied to the recommendation |
| Max slippage points | 100.0 | Ceiling applied to the recommendation |
| Fallback slippage points | 10.0 | Used until an hour bucket has enough samples |
| Min samples before trust | 8 | Samples needed in an hour bucket before trusting it over the fallback |
| Ema alpha | 0.2 | Smoothing weight for each new sample, 0 < alpha <= 1 |
| Demo lots | 0.01 | Lots for the standalone self-calibration order (kept tiny on purpose) |
| Magic number | 24800 | Magic number that tells this EA's orders apart |
| Demo interval minutes | 60 | Minutes between self-calibration probes in standalone mode |
| Close demo immediately | true | true = close the probe order right after it fills, to avoid taking real market risk |
| Max retries | 5 | |
| Retry wait ms | 500 | |
| Publish global variables | true | |
| Timer interval sec | 15 |
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 → Experts.
- 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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Martingale · MT4 Expert Advisor · MQL4 Source Code