Live Overfitting Demonstrator
Every trader has heard "don't overfit your backtest" as advice, and almost every trader has done it anyway, because the mechanism is invisible in a static backtest report - you see the equity curve, not the search that produced it. This EA makes the search visible. On attach it tries every (fast, slow) moving-average period pair in a configurable grid against a fixed window of recent history, using a simple crossover strategy, and keeps the single best-performing pair - deliberately with no walk-forward split inside the sweep and no penalty for how many pairs were tried, because that is exactly what an eager backtester skips. It then applies that one "winning" pair to every bar that closes afterward, which the sweep never saw, and displays both numbers on the chart: the in-sample profit that justified picking those parameters, and the running out-of-sample profit they have actually produced since. The ratio between the two is the decay a trader would otherwise only notice months later, watching a live account. The forward walk is fully re-simulated from the fixed sweep boundary every tick rather than tracked incrementally, so there is no risk of a stale running total drifting away from what a fresh recomputation would show. No real order is ever sent by this tool. Every simulated trade is priced off real historical bars and valued using the symbol's live MODE_TICKVALUE/MODE_TICKSIZE, so the P&L numbers are honest about instrument economics, but nothing here touches the order pool. Notes and limitations This is a teaching tool, not a trading system - it never sends a real order and should not be judged as one. The underlying strategy (a plain MA crossover) is intentionally simple so the overfitting mechanism, not the strategy's own merit, is what the demonstration highlights. The sweep re-runs only on (re)attach, not continuously - it is a fixed snapshot of "what looked best at that moment," which is itself the honest framing: a trader would not re-optimise every tick either. Simulated P&L ignores spread, slippage and commission entirely, so both the in-sample and out-of-sample figures are optimistic versions of what a real account would show - the demonstration is about the GAP between the two numbers, not their absolute size.
Expert advisor · MT4 · v1.0 · Free
About Live Overfitting Demonstrator
Live Overfitting Demonstrator is a script for MetaTrader 4 based on Moving Average. It has 9 settings, such as In sample bars, Fast min and Fast max. MQL source code included.
Files in the download: LiveOverfittingDemo.ex4, LiveOverfittingDemo.mq4, LiveOverfittingDemo.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| In sample bars | 400 | Bars used for the parameter sweep (the "cheating" window) |
| Fast min | 3 | Fast MA period, sweep lower bound |
| Fast max | 15 | Fast MA period, sweep upper bound |
| Slow min | 20 | Slow MA period, sweep lower bound |
| Slow max | 60 | Slow MA period, sweep upper bound |
| Sweep step | 3 | Step size walked through both period ranges |
| Sim lots | 0.10 | Bookkeeping lot size used for the simulated P&L only |
| In sample color | clrDodgerBlue | Colour on the chart |
| Out sample color | clrOrangeRed | Colour on the chart |
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: Grid · Moving Average · MT4 Expert Advisor · MQL4 Source Code