Loading…

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

SettingDefaultWhat it does
In sample bars400Bars used for the parameter sweep (the "cheating" window)
Fast min3Fast MA period, sweep lower bound
Fast max15Fast MA period, sweep upper bound
Slow min20Slow MA period, sweep lower bound
Slow max60Slow MA period, sweep upper bound
Sweep step3Step size walked through both period ranges
Sim lots0.10Bookkeeping lot size used for the simulated P&L only
In sample colorclrDodgerBlueColour on the chart
Out sample colorclrOrangeRedColour on the chart

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Grid · Moving Average · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria