Trading and automation
Case: backtesting a strategy and the overfitting trap
7 min
This case designs a simple rule-based strategy, backtests it, and then weighs turning it into an automated robot — and the trap that ruins most attempts. It connects the Technical Analysis and Automation/Robots tracks. All results below are hypothetical.
Step 1 — Define the strategy as unambiguous rules
A strategy you can backtest must be fully mechanical — no judgment calls. A classic example:
Entry: buy when the 50-period moving average
crosses above the 200-period moving average
Exit: sell when it crosses back below
Size: fixed risk per trade
If a rule needs interpretation, it cannot be backtested honestly.
Step 2 — Backtest on historical data
Run the rules over past data and record the metrics that actually matter:
Total return (vs simply buying and holding)
Maximum drawdown (the worst peak-to-trough fall)
Win rate (% of trades that profited)
Number of trades (is the sample big enough to trust?)
A high return with a brutal drawdown is often not tradeable in real life — you would abandon it mid-pain.
Step 3 — Beware the overfitting trap
Here is the central danger. If you keep tweaking parameters (try 47 and 210 instead of 50 and 200, add a filter, then another) until the past looks perfect, you have overfitted: the strategy is now memorizing history, not capturing a real edge. It will look brilliant in the backtest and fail the moment real money meets new data.
Defenses:
- Out-of-sample testing — tune on one slice of history, then test untouched on a later slice you never looked at.
- Keep it simple — fewer parameters are far harder to overfit than many.
- Demand a logical reason — a rule should make economic sense, not just fit the curve.
Step 4 — From strategy to robot (EA)
A fully mechanical strategy can become an Expert Advisor (EA) — code that executes it automatically, as the Robots track covers. Automation removes emotion and never sleeps, but it removes nothing about a flawed strategy: a robot runs a bad edge faster and more faithfully than you would by hand.
Step 5 — Go live like a professional
Before risking capital: forward-test on a demo account in real time (paper trading), start with the smallest possible size, and monitor for the gap between backtested and live results that always appears. The honest conclusion of this track: a backtest is a hypothesis, not a promise.
This content is for educational and informational purposes only and is not investment, financial, tax or legal advice. Trading and investing carry risk, including the possible loss of capital. Any performance shown by third-party tools is hypothetical and not a promise of future results. Do your own research and consider professional advice before making any decision.