mt5-robot-tester
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMT5 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 list (one
common.symbolsbacktest per symbol — MT5 build 6061 leaves theOptimization=0XML empty, so per-symbol backtests are used). Gate: ≥5 symbols profitable AND best symbol ≥3× deposit.Optimization=3 - 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
, one at a time, range ±50% step 5%; then a final backtest.
MagicNumber - 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),测试过程中会将机器人在不同文件夹间转移,且跨运行周期学习以优化每一轮的筛选结果。整个运行过程支持断点续跑。
- 第一轮——全品种筛选:在配置的列表中的每个品种上对EA进行回测(每个品种执行一次
common.symbols回测——MT5版本6061会使Optimization=0的XML为空,因此采用单品种回测)。准入条件:至少5个品种盈利,且表现最佳的品种收益≥初始资金的3倍。Optimization=3 - 第二轮——最优品种回测:在表现最佳的品种上执行单次回测;分析净利润率、最大回撤率、盈利月份占比、全年盈利占比、LR相关性、创新高所需月份数。
- 第三轮——顺序参数优化:对之后的5-6个输入参数逐一进行优化,参数范围为原值的±50%,步长5%;随后执行最终回测。
MagicNumber - 最终入选者:优化结果优于第二轮,且收益≥初始资金的4倍,同时最大回撤≤12%。
已测试的机器人会被转移至测试中文件夹;最终入选者会连同其优化后的文件一同复制到最终入选者文件夹。
.setWhen 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 : candidates, in-testing, finalists.
MQL5\Experts - set in the config — the pairs Round 1 backtests (your Market Watch symbols).
common.symbols - Optional per-bot files (config
.set) for the Round-2 baseline and Round-3 parameter optimization. Every input is fixed during optimization except the one parameter currently being searched; without asets_dir, Round 3 is skipped and the verdict comes from Round 2..set - 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 - 在下创建三个文件夹:candidates、in-testing、finalists。
MQL5\Experts - 在配置文件中设置****——第一轮回测涉及的品种(即您的市场观察列表中的品种)。
common.symbols - 可选:为第二轮基准测试和第三轮参数优化准备每个机器人对应的文件(配置
.set)。优化过程中,除当前正在搜索的参数外,所有其他输入参数均固定;若无sets_dir文件,则跳过第三轮,根据第二轮结果判定。.set - 运行前关闭MetaTrader 5——测试器需要独占数据文件夹的使用权。
- Python 3.9+(仅需标准库)。无需付费API。
Workflow
工作流程
Step 1 — Configure
步骤1——配置
Copy , fill in the three folder paths and
(optionally) . 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.jsonterminal_path复制,填写三个文件夹路径,(可选)填写。切勿提交真实个人路径——运行时传入配置文件即可。默认设置已包含约定参数(测试周期2020.01.01→2026.06.30,H1周期,,初始资金10000美元,杠杆1:100,准入条件及阈值)。
assets/pipeline_config.template.jsonterminal_pathModel=4Step 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-runStep 3 — Run the pipeline
步骤3——运行流程
bash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
--config my_config.json --output-dir reports/mt5_pipelineEach bot flows R1 → R2 → R3 → finalist decision. Progress is written to
and after every step.
state.jsonrun.logbash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
--config my_config.json --output-dir reports/mt5_pipeline每个机器人会依次经过第一轮→第二轮→第三轮→最终入选判定。每一步完成后,进度会写入和。
state.jsonrun.logStep 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.set.setbash
python3 skills/mt5-robot-tester/scripts/mt5_batch_tester.py \
--config my_config.json --output-dir reports/mt5_pipeline --resume--resume.set.setOptional — 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_pipelineIt serves (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 . Start/stop requests
are limited to the exact local origin and require the per-server CSRF token.
http://127.0.0.1:8765/run.log启动本地仪表盘,查看各文件夹中的机器人、每个机器人的测试阶段及判定结果,还有启动按钮——启动后无需再使用CLI:
bash
python3 skills/mt5-robot-tester/scripts/dashboard.py \
--config my_config.json --output-dir reports/mt5_pipeline仪表盘会在提供服务(自动打开,仅本地可访问)。页面每3秒自动刷新:显示文件夹内容、每个机器人的测试阶段(第一轮/第二轮/第三轮/完成)、通过/未通过判定、汇总统计数,以及实时的。启动/停止请求仅限本地源,并需要服务器专属的CSRF令牌。
http://127.0.0.1:8765/run.logStep 5 — Read the results
步骤5——查看结果
- /
leaderboard_<ts>.md— ranking with verdict and key metrics..json - /
learnings.json— what the skill learned this loop (parameter impact and symbol priors) under the configured output directory.learnings.md - and
mt5_reports/— raw MT5 reports and configs per bot/round.mt5_ini/
- /
leaderboard_<ts>.md——按收益排序的排名列表,包含判定结果及关键指标,最终入选者排在前面。.json - /
learnings.json——本轮运行中工具学到的内容(参数影响及品种优先级),位于配置的输出目录下。learnings.md - 和
mt5_reports/——每个机器人/测试轮次的原始MT5报告和配置文件。mt5_ini/
Round details
轮次细节
Round 1 gate (both required)
第一轮准入条件(需同时满足)
- (default 5).
count_positive_profit(passes) ≥ round1_min_positive - (default 3×).
best_symbol_profit ≥ round1_min_profit_multiple × deposit
Fail → bot rejected (moved to in-testing).
- (默认值为5)。
count_positive_profit(passes) ≥ round1_min_positive - (默认值为3倍初始资金)。
best_symbol_profit ≥ round1_min_profit_multiple × deposit
未通过→机器人被淘汰(转移至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 (learned order first), optimize
that single parameter over step ()
while fixing every other input, fix its best value, then continue. Run a
final backtest with the exact complete input set saved for a finalist.
MagicNumber[V×0.5, V×1.5]V×0.05Optimization=1.set针对之后的5-6个输入参数(按学习到的优先级排序),逐一优化单个参数,范围为,步长(),同时固定文件中的所有其他输入参数,确定该参数的最优值后继续下一个参数。最后使用完整的最优输入集执行一次最终回测,并保存结果供最终入选者使用。
MagicNumber[原值×0.5, 原值×1.5]原值×0.05Optimization=1.setFinalist
最终入选者判定
evaluate_finalist<bot>.setevaluate_finalist<bot>.setSelf-learning across loops
跨运行周期自学习
learnings.jsonlearnings.jsonOutput Format
输出格式
- — list of
leaderboard_<ts>.jsonsorted finalists-first by profit.{name, verdict, best_symbol, r2_profit, final_profit, final_dd_pct, lr, reason} - — same as a table.
leaderboard_<ts>.md - — resumable per-bot/per-round checkpoint.
state.json
- ——包含
leaderboard_<ts>.json的列表,按收益从高到低排序,最终入选者在前。{name, verdict, best_symbol, r2_profit, final_profit, final_dd_pct, lr, reason} - ——以表格形式呈现相同内容。
leaderboard_<ts>.md - ——支持断点续跑的每个机器人/每一轮测试的 checkpoint。
state.json
Resources
资源
- — pipeline orchestrator + INI builders (CLI).
scripts/mt5_batch_tester.py - — optimization report (XML/HTML) parser + Round-1 gate.
scripts/parse_mt5_optimization.py - — backtest report parser + balance-series metrics.
scripts/parse_mt5_report.py - — cross-run learning store.
scripts/mt5_learnings.py - — shared parsing helpers (EN/ES headers, numbers).
scripts/mt5_common.py - — MT5
references/mt5-cli-reference.md/[Tester]keys, enums, report formats and caveats.[TesterInputs] - — config template with placeholders.
assets/pipeline_config.template.json
- ——流程编排器 + INI文件生成器(CLI工具)。
scripts/mt5_batch_tester.py - ——优化报告(XML/HTML)解析器 + 第一轮准入条件判定。
scripts/parse_mt5_optimization.py - ——回测报告解析器 + 资金曲线指标计算。
scripts/parse_mt5_report.py - ——跨运行周期学习数据存储工具。
scripts/mt5_learnings.py - ——共享解析工具(支持英/西文表头、数字解析)。
scripts/mt5_common.py - ——MT5的
references/mt5-cli-reference.md/[Tester]参数、枚举值、报告格式及注意事项。[TesterInputs] - ——带占位符的配置模板。
assets/pipeline_config.template.json
Key Principles
核心原则
- Never commit personal paths — folders/terminal come from config/ENV/args.
- Relative names because build 6061 ignores absolute report paths; collect completed reports from the terminal data directory.
Report= - Real ticks () need broker tick data; it is slow — expect long runs.
Model=4 - Resumable: every round checkpoints; reuses only fingerprint- matching work and retries execution errors.
--resume - Fail closed: incomplete, timed-out, stale, or unparsable reports never reject, promote, or move a candidate. Every unique Round-1 symbol must finish.
- 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 marker; verify the recorded PID/process tree has exited before removing that marker manually.
.blocked - Full-period metrics: months without deals at the start, end, or across a full year remain part of the configured test period.
- Learn each loop: parameter/symbol statistics bias future runs toward wins.
- Verify against your build: report layout (esp. the deals table) and the 32 ms delay mapping can differ — see the reference's (verify) notes.
- 切勿提交个人路径——文件夹/终端路径来自配置文件/环境变量/命令行参数。
- 使用相对路径——因为版本6061会忽略绝对报告路径;需从终端数据目录收集已完成的报告。
Report= - **真实tick数据()**需要经纪商tick数据;测试速度较慢——预计运行时间较长。
Model=4 - 支持断点续跑:每一轮测试都会生成checkpoint;仅复用指纹匹配的已完成工作,并重试执行错误。
--resume - 默认拒绝:不完整、超时、过期或无法解析的报告不会淘汰、晋级或移动候选机器人。第一轮的每个品种测试必须全部完成。
- MT5独占使用:每个共享MT5数据文件夹在进程运行期间会持有系统锁。若无法确认子进程已终止,整个运行会停止并写入标记;手动移除该标记前,请确认记录的PID/进程树已退出。
.blocked - 全周期指标:测试周期内开头、结尾或全年无交易的月份仍会纳入统计。
- 每轮学习:参数/品种统计数据会使后续运行更倾向于选出优秀结果。
- 适配您的MT5版本:报告布局(尤其是交易表格)和32毫秒延迟映射可能因版本而异——请参考文档中的*(verify)*说明。