# Backtesting toolkit and MQL5 Expert Advisor workflow

> A Python toolkit for testing rule-based strategies and a workflow that checks the results in MetaTrader 5. Software development only: a simulation, not a forecast.

- Service: Trading software (development only)
- Stack: Python, numpy, pandas, Optuna, MQL5, MetaTrader 5
- Canonical: https://jamm-automation.com/cases/backtest-toolkit/
- Updated: 2026-11-29

## Manual

Testing a strategy idea by hand in the MetaTrader Strategy Tester is slow.

- **Trust:** a fast Python test that cannot be compared with the terminal is easy to over-trust.
- **Tuning:** parameter search without robustness checks finds settings that fit only the past.

## System

A Python engine runs the tests, Optuna searches, robustness modules filter the candidates.

- **Engine:** bar-by-bar on numpy and pandas; four sub-ticks per M1 bar with the adverse extreme first, explicit bid, ask and spread; when SL and TP are both hit in one bar, SL wins.
- **Search:** Optuna (TPE) under constraints.
- **Robustness:** walk-forward with purge, Monte-Carlo, Deflated Sharpe, stability plateau, sensitivity.

## Autopilot

A pipeline checks the Python run against the terminal.

- **Pipeline:** Python writes `.ini` and `.set` files, runs the compiled Expert Advisor in the MetaTrader 5 Strategy Tester, parses the HTML report and builds a comparison table; MetaTrader is the reference.
- **Expert Advisors:** shared MQL5 include libraries, compiled from the command line with MetaEditor.
- **Scope:** software development only; every result is a simulation, not a forecast.
