AlgoPro UniversityCourse home
Part 9 · Lesson

Backtesting, optimising & going live

The MT5 Strategy Tester — modelling quality, spread and tick data — optimising inputs without fooling yourself (a callback to Part 6), and the real checklist for deploying an EA: AutoTrading, .set files and a VPS.

You have a complete EA. The temptation is to attach it to a live chart and watch. Do not. MT5 ships one of the best retail backtesting engines in existence — the Strategy Tester — and running your EA through it properly is the whole difference between a hunch and a tested strategy.

The Strategy Tester

Open it with Ctrl+R (or View → Strategy Tester). You pick your EA, a symbol, a timeframe, a date range and a modelling mode, press Start, and MT5 replays history bar by bar — calling your OnInit, OnTick and OnDeinit exactly as a live terminal would, then hands you a full report: net profit, drawdown, profit factor, win rate, an equity curve and every trade.

Modelling quality is not a detail

Reading the report honestly

The headline number is net profit, but seasoned developers read the report from the *risk* end first:

  1. Maximal drawdown — the worst peak-to-trough equity fall. This is the pain you must survive to earn the profit. A curve that doubles the account but draws down 60% is untradeable for most people.
  2. Profit factor — gross profit ÷ gross loss. Above 1.0 is profitable; a robust system usually sits comfortably above, not on a knife-edge at 1.02.
  3. Number of trades — 12 trades prove nothing. You want a sample large enough that the result is not luck.
  4. The equity curve shape — a smooth rising line beats a jagged one with the same endpoint. Lumpiness is fragility.

Optimisation — and the trap under it

The tester's optimisation mode is where those input parameters earn their keep. Tick "Optimisation", give each input a start/step/stop range (say FastPeriod from 5 to 20 step 1, SlowPeriod from 20 to 60 step 5), and MT5 runs *every combination*, then ranks them by whatever metric you choose. It will hand you the "best" fast and slow periods on a silver platter.

A peak you can trust vs one you cannot
Score across a swept parameter. The broad plateau (blue) is a robust region — neighbouring values also work. The lone spike (violet) is over-optimisation: one lucky setting surrounded by losers. Choose the plateau.

The workflow is the same one from Part 1, just in MetaTrader's tools: idea → backtest on real ticks → optimise on in-sample data → validate on out-of-sample/forward data → *then* paper-trade live. Most parameter sets die at the forward step. That is the tester doing its job.

Going live

Once an EA has survived real-tick backtesting and forward validation and a stint on demo, deploying it is mechanical. There is exactly one switch that matters most:

  1. Enable AutoTrading — the "AutoTrading" button in the MT5 toolbar must be green, *and* the EA's own "Allow Algo Trading" checkbox (in its settings dialog and in Tools → Options → Expert Advisors) must be ticked. If either is off, your EA reads data but silently places no orders — the number-one "why isn't my EA trading?" question.
  2. Attach to the chart — drag the EA onto the exact symbol and timeframe you tested. An EA is bound to one chart; for five symbols you attach five instances.
  3. Load your settings — save the validated inputs as a .set file from the settings dialog, and load it on the live chart so live matches exactly what you tested. Version these files; they are your strategy's DNA.
  4. Run it on a VPS — an EA only trades while MT5 is open and online. A VPS (many brokers offer one, or use a low-latency cloud instance near the broker's server) keeps the terminal running 24/5 with a stable connection, so a closed laptop lid never means a missed exit.

What you can now do

You can navigate MetaTrader and MetaEditor, write MQL5 with correct types and the OnInit/OnTick/OnDeinit lifecycle, create indicator handles and read them with CopyBuffer, detect a moving-average cross once per bar, place guarded orders with stop-losses and take-profits through CTrade, and put the whole EA through the Strategy Tester without fooling yourself. That is a complete, real Expert Advisor — the same five-component system from Part 1, now living inside the terminal.

Next, Part 10 takes both of your engines — the Python bot and this EA — the final step: monitoring, risk controls and the operational discipline of running automated strategies live.