- Add MIT LICENSE - Anonymize broker path in config.example.yaml; add slippage_points + risk_per_trade - Fix encoding ansi→cp1252 in signals.py (cross-platform safe) - Fix install.py silently ignoring pip errors - Cap get_ohlcv at 2000 bars; add ping tool; clarify HTML report UX in descriptions - Escape symbol/timeframe in HTML report to prevent malformed output - Move run_*.py to scripts/; move example CSVs to examples/ - Update .gitignore to block accidental CSV commits from root - README: Python 3.9+ requirement, Chart.js internet note, new sections for examples/ and scripts/ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
MBT — MT5 Backtest Toolkit
Backtest any MetaTrader 5 indicator by talking to Claude.
Requirements: Python 3.9+ · MetaTrader 5 (Windows) · Claude Code
Drop one include into your indicator, and MBT lets you fetch live data, read your indicator's signals, and run a full backtest with an HTML report — all through Claude, no scripting.
The core principle: MBT never recalculates your indicator in Python. Your indicator logs the signals it generated; MBT reads those real signals and replays real broker price bars forward to see whether each trade hit its stop or its target. What you backtest is exactly what your indicator drew.
How it works
Your MT5 indicator MBT (this toolkit)
┌──────────────────┐ ┌────────────────────────────┐
│ #include │ writes │ reads signals.csv │
│ <SignalLogger> ├─ signals.csv ┤ │
│ LogSignal(...) │ │ replays real MT5 bars │
└──────────────────┘ │ forward → WIN / LOSS / OPEN │
│ │
│ tools exposed to Claude: │
│ get_ohlcv │
│ get_signals │
│ backtest (+ HTML report) │
│ validate_signals │
└────────────────────────────┘
Install
cd MBT
python install.py
This installs dependencies, creates config.yaml, copies SignalLogger.mqh
into your MT5 Include folder, and prints the command to register the MCP
server with Claude Code.
Then edit config.yaml:
mt5_path: "C:/.../terminal64.exe" # the terminal your indicator runs on
signal_file: "signals.csv" # must match SignalLogFile in your indicator
default_symbol: "EURUSD"
default_timeframe: "1h"
ambiguous_bar: "loss" # conservative
Register the server (printed by the installer):
claude mcp add mbt python "/abs/path/to/MBT/mcp_server.py"
Add logging to your indicator
#include <SignalLogger.mqh>
// In OnInit (or on full recalculation) so the log matches the chart:
ResetSignalLog();
// When your buy/sell condition is true on bar `shift`:
LogSignal(shift, true, entry, sl, tp, "TRENDING"); // BUY
LogSignal(shift, false, entry, sl, tp, "TRENDING"); // SELL
regime is optional — pass "" if you don't use it. When present, the backtest
report breaks results down per regime.
Compile, attach to the chart. The indicator writes signals.csv to
<terminal>\MQL5\Files\.
Use it
In Claude Code, inside this project:
"backtest my signals" "fetch the last 300 EURUSD 1h bars" "validate my signal file" "backtest signals since 2026-01-01 and give me the report"
The backtest tool returns full metrics and writes an HTML report (with an
equity curve) to reports/.
What the report contains
- Total trades · wins · losses · open
- Win rate · profit factor · expectancy (avg R)
- Net result · max drawdown (in R)
- Average win / loss · max win/loss streaks
- Per-regime breakdown
- Equity curve (cumulative R)
Everything is in R units (1R = the risk on each trade, entry→SL), so results compare cleanly across symbols, timeframes, and account sizes.
Signal CSV format
SignalLogger.mqh writes this standard header:
time,symbol,timeframe,direction,entry,sl,tp,regime
Any file matching this format works — MBT is indicator-agnostic. Extra columns are ignored, and a header-less legacy file is still read if its first column is a timestamp.
Tools (MCP)
| Tool | Purpose |
|---|---|
ping |
check MT5 is running and reachable |
get_ohlcv |
live OHLCV bars for any symbol/timeframe (max 2000) |
get_signals |
read your indicator's logged signals |
backtest |
replay + full metrics + HTML report (requires internet for chart) |
validate_signals |
check SL/TP geometry of every signal |
get_config |
show the active terminal + signal file |
Note: the HTML report is written to
reports/on your machine and opened in a browser. Claude cannot open it directly — it will give you the file path.
Examples
examples/ contains sample signal CSVs you can use to try MBT without attaching
an indicator. Point signal_file in config.yaml to any of them:
signal_file: "C:/abs/path/to/MBT/examples/test_signals.csv"
Research scripts
scripts/ contains one-off analysis scripts used during strategy development.
They are not part of the core toolkit and have no documentation — treat them as
reference material, not user tools.