Skip to main content
Glama
TradeLab-MCP

TradeLab-MCP

by CaioAllgayer

TradeLab-MCP

MCP server for quantitative research. The AI defines the strategy. MetaTrader 5 Strategy Tester runs the backtest.

IA (Codex / GPT / Grok / Gemini / Claude)
        │ MCP
        ▼
Trading Research MCP
        │
        ▼
terminal64.exe  →  Strategy Tester oficial  →  runs/<run_id>/

Fork of PHUICMT/mcp-mt5 (MIT). It does not reimplement the tester in Python.

Principle

MT5 is the authority for orders, fills, ticks, spread, SL/TP, margin, commissions, and P&L.

Python only organizes experiments (run_id, manifest, hashes, parser, derived statistics).

Each backtest generates a unique identifier. Nothing is retrieved by the “most recent file”.

runs/20260817_073412_a8f231/
  tester.ini
  strategy.mq5
  strategy.ex5
  report.htm
  tester.log
  trades.csv
  metrics.json
  manifest.json

Related MCP server: OpenFinClaw CLI

MCP Tools (V1)

Tool

Function

health

MT5, MetaEditor, terminal, data dir, Experts, Tester, build

compile

Compiles .mq5 and returns hashes

run_backtest

Official tester → run_id + metrics + artifacts

run_batch

Same strategy, multiple assets, sequential

get_run

Retrieves an experiment by run_id

get_trades

Normalized trades from that run_id

compare_runs

Metrics diff between runs

walk_forward

IS/OOS windows, each an official backtest

smoke_test

Compile + short tester (configurable symbol/period/model/date)

Installation

Windows + MetaTrader 5 + Python 3.10+.

cd C:\Users\caioa\TradeLab-MCP
python -m pip install -e ".[dev]"

MCP Client:

{
  "mcpServers": {
    "tradelab": {
      "command": "tradelab-mcp",
      "env": {
        "MT5_INSTALL": "C:\\Program Files\\MetaTrader 5",
        "TRADE_LAB_ROOT": "C:\\Users\\caioa\\TradeLab-MCP\\research"
      }
    }
  }
}

Variables: MT5_INSTALL, MT5_DATA, MT5_TERMINAL_HASH, TRADE_LAB_ROOT.

Example

Compile este EA e faça um backtest de PETR4 D1,
entre 2015 e 2025, usando real ticks.

The agent calls run_backtest(strategy="experts/RSI2.mq5", symbol="PETR4", timeframe="D1", from_date="2015.01.01", to_date="2025.08.01", model=4) and receives:

{
  "run_id": "20260817_073412_a8f231",
  "status": "completed",
  "symbol": "PETR4",
  "period": "D1",
  "model": "real_ticks",
  "metrics": {
    "total_trades": 134,
    "net_profit": 18342.21,
    "profit_factor": 1.48
  }
}

get_run("20260817_073412_a8f231") returns exactly that experiment.

Where EAs live in MT5

Every automated test EA is published to:

<MQL5>\Experts\TradeLab MCP\

On this PC this resolves to:

C:\Users\caioa\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeLab MCP

In the Strategy Tester the expert appears as TradeLab MCP\RSI2. The folder is always relative to the active terminal (layout.experts_dir), not a fixed hash.

The source in git remains in experts/. The MCP copies source + .ex5 + local includes to the terminal folder.

The lab's base EA (CTrade, ArraySetAsSeries, one position) has not been standardized yet — it will come later, without rushing.

Acceptance EA

experts/RSI2.mq5

  • RSI(2)

  • buys if RSI < 10

  • exits if RSI > 70

  • one position

  • no optimization

Acceptance test #1 is: the same EA / asset / dates / inputs / capital / model in manual Strategy Tester and via MCP must produce the same metrics and the same trades.

Tests

pytest

Integration tests (Windows + real MT5):

$env:TRADE_LAB_INTEGRATION = "1"
$env:TRADE_LAB_SYMBOL = "EURUSD"
pytest tests/test_integration_mt5.py -v

Priority

reproducibility > reliability > simplicity > speed > features

V1 is sequential (lock mt5.lock on the data directory). No parallel Python backtester. No .opt parser as official source.

Available Tools

18 tools
compare_runsA

Diff stored metrics of two or more runs. Never looks up the latest HTML report.

Inputs: run_ids (required).

compileB

Compile a .mq5/.mq4 source via MetaEditor and publish it to Experts/TradeLab MCP.

Inputs: source (required), include, publish, log_file, +1 more.

ea_capabilitiesA

Show TradeLab EA capabilities, defaults, and the mandatory pre-generation workflow.

Inputs: no named parameters.

ea_registryB

Query the compact EA catalog without loading every .mq5 source into the AI context.

Inputs: query, refresh_if_stale.

get_runA

Load manifest, config, metrics, files, and errors for an existing run_id.

Inputs: run_id (required).

get_tradesB

Return normalized trades for a run_id.

Inputs: run_id (required).

healthA

Verify MT5 install, MetaEditor, terminal, data dir, Experts, Tester, and build.

Inputs: no named parameters.

kill_terminalA

Force-kill terminal processes for the configured edition.

Inputs: no named parameters.

list_terminalsA

Enumerate MetaTrader terminal data folders under %APPDATA%\MetaQuotes\Terminal.

Inputs: no named parameters.

plan_ea_creationC

Mandatory registry lookup and decision record before generating or modifying an EA.

Inputs: setup (required), filters, exit_rule, time_stop, +7 more.

refresh_ea_registryA

Rebuild experts/registry.json and REGISTRY.md after an EA source changes.

Inputs: no named parameters.

run_backtestC

Run one official MT5 Strategy Tester backtest and store it under a unique run_id.

Inputs: symbol (required), to_date (required), strategy (required), from_date (required), +7 more.

run_batchB

Run the same strategy sequentially on each symbol. Each asset gets its own run_id.

Inputs: period (required), symbols (required), to_date (required), strategy (required), +7 more.

select_terminalC

Switch the active terminal data folder for this session.

Inputs: hash, origin, edition, install.

smoke_testC

Compile, deploy, run a short official tester pass, and scan the journal.

Inputs: source (required), days, model, period, +7 more.

validate_ea_standardC

Check that an EA uses the guarded TradeLab stop, sizing, metadata, and bar helpers.

Inputs: source (required).

validate_tester_iniC

Sanity-check a tester.ini against official MT5 formats (including Leverage=1:100).

Inputs: config (required), source.

walk_forwardC

Walk-forward as a sequence of official tester runs (IS/OOS windows).

Inputs: symbol (required), is_days (required), to_date (required), oos_days (required), +10 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 18 tools

    Disambiguation5/5

    Each tool targets a distinct resource and action: terminal management, compilation, single/batch/walk-forward backtests, result retrieval/comparison, and EA registry operations. The run-related tools are differentiated by scope and description, so an agent is unlikely to confuse them.

    Naming Consistency4/5

    Most tools follow a clear verb_noun pattern such as list_terminals, run_backtest, get_trades, and refresh_ea_registry. A few exceptions like health, compile, ea_capabilities, and walk_forward are readable but break the otherwise consistent convention.

    Tool Count4/5

    At 18 tools, this is slightly above the typical 3-15 tool sweet spot, but the count is justified by the distinct environment, backtest, results, and EA-registry concerns. Each tool has a clear role and none feel redundant.

    Completeness3/5

    Core workflows are well covered: environment health, compilation, backtests, walk-forward, smoke tests, and result inspection/comparison. However, there is no run listing/deletion tool and no direct EA generation/modification tool, which leaves notable gaps in lifecycle management.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      MCP server that provides AI agents with financial tools including real-time quotes, backtesting, technical analysis, and multi-exchange data via a simple CLI interface.
      2
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      MCP server that exposes the Backtest360 backtesting engine API as tools, enabling AI agents to conversationally discover indicators, build and validate strategies, run backtests, and read results.
      14
      43 PyPI
      MIT
    • F
      license
      Not graded
      quality
      C
      maintenance
      A 34-tool MCP server that bridges LLMs to MetaTrader 5, enabling EA development, backtesting, optimization, advanced analytics, live trading, and portfolio management.
      4
      -