mt5-robot-tester

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

MT5 Robot Tester

MT5 机器人测试工具

Overview

概述

Select the best MetaTrader 5 robots (Expert Advisors) from a candidates folder by driving the Strategy Tester from the command line through a 3-round pipeline, moving each bot between folders as it advances, and learning across runs to improve selection each loop. The whole run is checkpointed and resumable.
  • Round 1 — screening (all pairs): backtest the EA on each symbol in the configured
    common.symbols
    list (one
    Optimization=0
    backtest per symbol — MT5 build 6061 leaves the
    Optimization=3
    XML empty, so per-symbol backtests are used). Gate: ≥5 symbols profitable AND best symbol ≥3× deposit.
  • Round 2 — best-pair backtest: single backtest on the best symbol; analyze net profit %, worst drawdown %, % positive months, all-years-positive, LR Correlation, months-to-new-high.
  • Round 3 — sequential parameter optimization: optimize the 5–6 inputs after
    MagicNumber
    , one at a time, range ±50% step 5%; then a final backtest.
  • Finalist: optimized result improves on Round 2 and profit ≥4× deposit and worst drawdown ≤12%.
Tested bots move to in-testing; finalists are also copied to finalists with their optimized
.set
.
通过命令行驱动策略测试器执行三轮流程,从候选者文件夹中筛选出最佳MetaTrader 5机器人(Expert Advisors),测试过程中会将机器人在不同文件夹间转移,且跨运行周期学习以优化每一轮的筛选结果。整个运行过程支持断点续跑。
  • 第一轮——全品种筛选:在配置的
    common.symbols
    列表中的每个品种上对EA进行回测(每个品种执行一次
    Optimization=0
    回测——MT5版本6061会使
    Optimization=3
    的XML为空,因此采用单品种回测)。准入条件:至少5个品种盈利,且表现最佳的品种收益≥初始资金的3倍
  • 第二轮——最优品种回测:在表现最佳的品种上执行单次回测;分析净利润率、最大回撤率、盈利月份占比、全年盈利占比、LR相关性、创新高所需月份数。
  • 第三轮——顺序参数优化:对
    MagicNumber
    之后的5-6个输入参数逐一进行优化,参数范围为原值的±50%,步长5%;随后执行最终回测。
  • 最终入选者:优化结果优于第二轮,且收益≥初始资金的4倍,同时最大回撤≤12%
已测试的机器人会被转移至测试中文件夹;最终入选者会连同其优化后的
.set
文件一同复制到最终入选者文件夹。

When to Use

适用场景

  • "Prueba robots / bots / EAs en MetaTrader 5."
  • Screen a folder of MT5 Expert Advisors and pick the best across all pairs.
  • Optimize EA parameters and decide finalists by profit/drawdown/consistency.
  • Resume an interrupted testing run.
  • 在MetaTrader 5中测试机器人/EA。
  • 筛选文件夹中的MT5 Expert Advisors,选出全品种中的最佳者。
  • 优化EA参数,并根据收益/回撤/稳定性确定最终入选者。
  • 恢复中断的测试运行。

Prerequisites

前置条件

  • Windows + MetaTrader 5 installed (the tester runs
    terminal64.exe
    ).
  • Broker tick data downloaded (default modeling is real ticks,
    Model=4
    ).
  • The three folders under
    MQL5\Experts
    : candidates, in-testing, finalists.
  • common.symbols
    set in the config — the pairs Round 1 backtests (your Market Watch symbols).
  • Optional per-bot
    .set
    files (config
    sets_dir
    ) for the Round-2 baseline and Round-3 parameter optimization. Every input is fixed during optimization except the one parameter currently being searched; without a
    .set
    , Round 3 is skipped and the verdict comes from Round 2.
  • Close MetaTrader 5 before running — the tester needs exclusive use of the data folder.
  • Python 3.9+ (standard library only). No paid API.
  • 已安装Windows系统 + MetaTrader 5(测试器运行
    terminal64.exe
    )。
  • 已下载经纪商tick数据(默认采用真实tick数据建模,
    Model=4
    )。
  • MQL5\Experts
    下创建三个文件夹:candidatesin-testingfinalists
  • 在配置文件中设置**
    common.symbols
    **——第一轮回测涉及的品种(即您的市场观察列表中的品种)。
  • 可选:为第二轮基准测试和第三轮参数优化准备每个机器人对应的
    .set
    文件(配置
    sets_dir
    )。优化过程中,除当前正在搜索的参数外,所有其他输入参数均固定;若无
    .set
    文件,则跳过第三轮,根据第二轮结果判定。
  • 运行前关闭MetaTrader 5——测试器需要独占数据文件夹的使用权。
  • Python 3.9+(仅需标准库)。无需付费API。

Workflow

工作流程

Step 1 — Configure

步骤1——配置

Copy
assets/pipeline_config.template.json
, fill in the three folder paths and (optionally)
terminal_path
. Never commit real personal paths — pass the config at run time. Defaults already encode the agreed settings (2020.01.01→2026.06.30, H1, Model=4, 10000 USD, 1:100, gates and thresholds).
复制
assets/pipeline_config.template.json
,填写三个文件夹路径,(可选)填写
terminal_path
。切勿提交真实个人路径——运行时传入配置文件即可。默认设置已包含约定参数(测试周期2020.01.01→2026.06.30,H1周期,
Model=4
,初始资金10000美元,杠杆1:100,准入条件及阈值)。

Step 2 — Dry-run (optional)

步骤2——试运行(可选)

Verify the generated Round-1 INIs without launching MT5:
bash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
  --config my_config.json --output-dir reports/mt5_pipeline --dry-run
无需启动MT5,验证生成的第一轮INI文件:
bash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
  --config my_config.json --output-dir reports/mt5_pipeline --dry-run

Step 3 — Run the pipeline

步骤3——运行流程

bash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
  --config my_config.json --output-dir reports/mt5_pipeline
Each bot flows R1 → R2 → R3 → finalist decision. Progress is written to
state.json
and
run.log
after every step.
bash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
  --config my_config.json --output-dir reports/mt5_pipeline
每个机器人会依次经过第一轮→第二轮→第三轮→最终入选判定。每一步完成后,进度会写入
state.json
run.log

Step 4 — Resume if interrupted

步骤4——恢复中断的运行

bash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
  --config my_config.json --output-dir reports/mt5_pipeline --resume
--resume
skips completed bots and reuses finished rounds only while the execution config, EA binary, and input
.set
fingerprints still match. A changed period, symbol list, binary, or
.set
restarts that bot safely.
bash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
  --config my_config.json --output-dir reports/mt5_pipeline --resume
--resume
参数会跳过已完成测试的机器人,仅在执行配置、EA二进制文件和输入
.set
文件的指纹匹配时,复用已完成的测试轮次。若测试周期、品种列表、二进制文件或
.set
文件发生变化,会安全地重新启动该机器人的测试。

Optional — HTML control panel

可选——HTML控制面板

Launch a local dashboard to see the bots in each folder, each bot's phase and verdict, and a Launch button — no CLI needed after starting it:
bash
python3 skills/mt5-robot-tester/scripts/dashboard.py \
  --config my_config.json --output-dir reports/mt5_pipeline
It serves
http://127.0.0.1:8765/
(opens automatically, localhost only). The page auto-refreshes every 3 s: folder contents, per-bot phase (R1/R2/R3/done), pass/fail verdicts, summary counts, and the live
run.log
. Start/stop requests are limited to the exact local origin and require the per-server CSRF token.
启动本地仪表盘,查看各文件夹中的机器人、每个机器人的测试阶段及判定结果,还有启动按钮——启动后无需再使用CLI:
bash
python3 skills/mt5-robot-tester/scripts/dashboard.py \
  --config my_config.json --output-dir reports/mt5_pipeline
仪表盘会在
http://127.0.0.1:8765/
提供服务(自动打开,仅本地可访问)。页面每3秒自动刷新:显示文件夹内容、每个机器人的测试阶段(第一轮/第二轮/第三轮/完成)、通过/未通过判定、汇总统计数,以及实时的
run.log
。启动/停止请求仅限本地源,并需要服务器专属的CSRF令牌。

Step 5 — Read the results

步骤5——查看结果

  • leaderboard_<ts>.md
    /
    .json
    — ranking with verdict and key metrics.
  • learnings.json
    /
    learnings.md
    — what the skill learned this loop (parameter impact and symbol priors) under the configured output directory.
  • mt5_reports/
    and
    mt5_ini/
    — raw MT5 reports and configs per bot/round.
  • leaderboard_<ts>.md
    /
    .json
    ——按收益排序的排名列表,包含判定结果及关键指标,最终入选者排在前面。
  • learnings.json
    /
    learnings.md
    ——本轮运行中工具学到的内容(参数影响及品种优先级),位于配置的输出目录下。
  • mt5_reports/
    mt5_ini/
    ——每个机器人/测试轮次的原始MT5报告和配置文件。

Round details

轮次细节

Round 1 gate (both required)

第一轮准入条件(需同时满足)

  1. count_positive_profit(passes) ≥ round1_min_positive
    (default 5).
  2. best_symbol_profit ≥ round1_min_profit_multiple × deposit
    (default 3×).
Fail → bot rejected (moved to in-testing).
  1. count_positive_profit(passes) ≥ round1_min_positive
    (默认值为5)。
  2. best_symbol_profit ≥ round1_min_profit_multiple × deposit
    (默认值为3倍初始资金)。
未通过→机器人被淘汰(转移至in-testing文件夹)。

Round 2 quality profile (reference thresholds)

第二轮质量指标(参考阈值)

Net profit ≥300%, worst DD <15% (larger of balance/equity %), positive months
70%, all years positive, LR Correlation ≥0.80, months-to-new-high ≤3. Reported per bot; the hard finalist gate is Round 3.
净利润≥300%,最大回撤<15%(余额/权益回撤率的较大值),盈利月份占比>70%,全年盈利,LR相关性≥0.80,创新高所需月份数≤3。每个机器人都会报告这些指标;最终入选者的硬性准入条件由第三轮决定。

Round 3 sequential optimization

第三轮顺序参数优化

For each of the 5–6 inputs after
MagicNumber
(learned order first), optimize that single parameter over
[V×0.5, V×1.5]
step
V×0.05
(
Optimization=1
) while fixing every other
.set
input, fix its best value, then continue. Run a final backtest with the exact complete input set saved for a finalist.
针对
MagicNumber
之后的5-6个输入参数(按学习到的优先级排序),逐一优化单个参数,范围为
[原值×0.5, 原值×1.5]
,步长
原值×0.05
Optimization=1
),同时固定
.set
文件中的所有其他输入参数,确定该参数的最优值后继续下一个参数。最后使用完整的最优输入集执行一次最终回测,并保存结果供最终入选者使用。

Finalist

最终入选者判定

evaluate_finalist
: improved on Round 2 and profit ≥4× deposit and worst DD ≤12%. → copied to finalists with
<bot>.set
.
evaluate_finalist
:优化结果优于第二轮收益≥初始资金的4倍最大回撤≤12%。→ 复制到finalists文件夹,同时保存
<bot>.set
文件。

Self-learning across loops

跨运行周期自学习

learnings.json
accumulates, per run: parameter average profit improvement (reorders Round-3 optimization so the most impactful parameters are tried first), symbol priors (how often each is a best pair), and per-bot verdicts. This makes selection converge faster each loop. Deterministic — plain aggregate statistics.
learnings.json
会在每次运行时累积数据:参数平均收益提升(重新排序第三轮优化顺序,优先测试影响最大的参数)、品种优先级(每个品种成为最优品种的频率),以及每个机器人的判定结果。这使得每一轮筛选的收敛速度更快。整个过程是确定性的——仅使用聚合统计数据。

Output Format

输出格式

  • leaderboard_<ts>.json
    — list of
    {name, verdict, best_symbol, r2_profit, final_profit, final_dd_pct, lr, reason}
    sorted finalists-first by profit.
  • leaderboard_<ts>.md
    — same as a table.
  • state.json
    — resumable per-bot/per-round checkpoint.
  • leaderboard_<ts>.json
    ——包含
    {name, verdict, best_symbol, r2_profit, final_profit, final_dd_pct, lr, reason}
    的列表,按收益从高到低排序,最终入选者在前。
  • leaderboard_<ts>.md
    ——以表格形式呈现相同内容。
  • state.json
    ——支持断点续跑的每个机器人/每一轮测试的 checkpoint。

Resources

资源

  • scripts/mt5_batch_tester.py
    — pipeline orchestrator + INI builders (CLI).
  • scripts/parse_mt5_optimization.py
    — optimization report (XML/HTML) parser + Round-1 gate.
  • scripts/parse_mt5_report.py
    — backtest report parser + balance-series metrics.
  • scripts/mt5_learnings.py
    — cross-run learning store.
  • scripts/mt5_common.py
    — shared parsing helpers (EN/ES headers, numbers).
  • references/mt5-cli-reference.md
    — MT5
    [Tester]
    /
    [TesterInputs]
    keys, enums, report formats and caveats.
  • assets/pipeline_config.template.json
    — config template with placeholders.
  • scripts/mt5_batch_tester.py
    ——流程编排器 + INI文件生成器(CLI工具)。
  • scripts/parse_mt5_optimization.py
    ——优化报告(XML/HTML)解析器 + 第一轮准入条件判定。
  • scripts/parse_mt5_report.py
    ——回测报告解析器 + 资金曲线指标计算。
  • scripts/mt5_learnings.py
    ——跨运行周期学习数据存储工具。
  • scripts/mt5_common.py
    ——共享解析工具(支持英/西文表头、数字解析)。
  • references/mt5-cli-reference.md
    ——MT5的
    [Tester]
    /
    [TesterInputs]
    参数、枚举值、报告格式及注意事项。
  • assets/pipeline_config.template.json
    ——带占位符的配置模板。

Key Principles

核心原则

  1. Never commit personal paths — folders/terminal come from config/ENV/args.
  2. Relative
    Report=
    names
    because build 6061 ignores absolute report paths; collect completed reports from the terminal data directory.
  3. Real ticks (
    Model=4
    )
    need broker tick data; it is slow — expect long runs.
  4. Resumable: every round checkpoints;
    --resume
    reuses only fingerprint- matching work and retries execution errors.
  5. Fail closed: incomplete, timed-out, stale, or unparsable reports never reject, promote, or move a candidate. Every unique Round-1 symbol must finish.
  6. Single MT5 owner: an OS lock is held for the process lifetime for each shared MT5 data folder. If child termination cannot be confirmed, the whole run stops and writes a
    .blocked
    marker; verify the recorded PID/process tree has exited before removing that marker manually.
  7. Full-period metrics: months without deals at the start, end, or across a full year remain part of the configured test period.
  8. Learn each loop: parameter/symbol statistics bias future runs toward wins.
  9. Verify against your build: report layout (esp. the deals table) and the 32 ms delay mapping can differ — see the reference's (verify) notes.
  1. 切勿提交个人路径——文件夹/终端路径来自配置文件/环境变量/命令行参数。
  2. 使用相对路径
    Report=
    ——因为版本6061会忽略绝对报告路径;需从终端数据目录收集已完成的报告。
  3. **真实tick数据(
    Model=4
    )**需要经纪商tick数据;测试速度较慢——预计运行时间较长。
  4. 支持断点续跑:每一轮测试都会生成checkpoint;
    --resume
    仅复用指纹匹配的已完成工作,并重试执行错误。
  5. 默认拒绝:不完整、超时、过期或无法解析的报告不会淘汰、晋级或移动候选机器人。第一轮的每个品种测试必须全部完成。
  6. MT5独占使用:每个共享MT5数据文件夹在进程运行期间会持有系统锁。若无法确认子进程已终止,整个运行会停止并写入
    .blocked
    标记;手动移除该标记前,请确认记录的PID/进程树已退出。
  7. 全周期指标:测试周期内开头、结尾或全年无交易的月份仍会纳入统计。
  8. 每轮学习:参数/品种统计数据会使后续运行更倾向于选出优秀结果。
  9. 适配您的MT5版本:报告布局(尤其是交易表格)和32毫秒延迟映射可能因版本而异——请参考文档中的*(verify)*说明。