MT5-Quant

io.github.masdevid由 GitHub 帳號 masdevid 發布v1.34.3更新於 Oct 24, 2026

MT5 strategy development with 87 tools. Backtest, optimize, debug MQL5 EAs on macOS/Linux.

概覽

AI 產生的概覽

本機 MCP 伺服器,讓助手在 macOS 或 Linux 上編譯、回測、最佳化並分析 MetaTrader 5 的 MQL5 智慧交易系統。

可以做什麼
  • 編譯、列出並搜尋 MQL5 專家顧問、指標與腳本,並產生新專案範本
  • 執行回測與基因最佳化,查詢工作狀態並與基準結果比較
  • 分析報告與逐筆交易:每月損益、回撤、連勝連虧、持倉時間、成本、手數與加碼層表現
  • 搜尋、歸檔、標註並匯出回測報告與歷史紀錄,清理舊報告目錄
  • 讀取、寫入、修改、比對並產生 .set 參數檔
  • 診斷 Wine、MT5 日誌、行程與系統資源,並管理測試器快取
適用情境
適合在 macOS 或 Linux 上開發或調校 MetaTrader 5 智慧交易系統,希望助手自動完成編譯—回測—分析流程並深入檢視逐筆交易結果的情境。
執行需求
以本機執行檔形式在 macOS 或 Linux 上執行,可透過 Cargo 或預先編譯的發行檔安裝並放入 PATH;安裝腳本會自動偵測 Wine 與 MT5 路徑。需要以 Wine 執行的 MetaTrader 5 安裝(含 MetaEditor 與終端機資料)。可選環境變數 MT5_MCP_HOME 指定設定目錄。
安裝前請注意
多個工具會寫入、修改或刪除資料:寫入 .set 檔、刪除報告目錄與測試器快取、歸檔歷史紀錄,並可終止 MT5 行程。它會讀取 MT5 帳戶工作階段資訊,並與 MetaTrader 5、Wine 等第三方軟體互動,須遵守其授權條款。回測結果為歷史模擬,不構成投資建議,交易具有虧損風險。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 MT5-Quant,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

MT5-Quant

[OpenSSF Scorecard] [CII Best Practices] [Rust CI] [crates.io] [License: MIT] [CodeQL]

MCP server for MT5 strategy development on macOS/Linux. 89 tools to compile, backtest, analyze, optimize, debug crashes, and manage MQL5 Expert Advisors — no Windows required.

You: "Backtest MyEA Jan-Mar, what caused the February drawdown?"
Claude: [compile → clean → backtest → analyze 1,847 deals]        → Feb 14: BUY grid at L6, locking lot 1.75× base        → Cutloss fired 17 points later        → Recommendation: cap locking multiplier to ≤1.2×

Why MT5-Quant

Focus: Backtest organization, reporting, and analytics — capabilities MT5 itself doesn't provide.

MT5-QuantOthers
PlatformmacOS/Linux nativeWindows only
Backtest pipeline✅ Full (compile → run → analyze)✅ Via MT5 Python package
Deal-level analytics✅ 19 dimensions, DB-backed❌
Report organization✅ SQLite (reports + deals) + search + history❌
MQL5 compilation✅ Headless (MetaEditor via Wine, no GUI)⚠️ Via GUI or terminal
Optimization✅ Background + results parsing + .set generation⚠️ Terminal only, no parsing
Crash debugging✅ Wine/MT5 diagnostics❌

Others typically run on Windows using the MetaTrader5 Python package, providing full terminal operations. MT5-Quant fills the gap: organizing backtest reports, extracting deal-level insights, and managing optimization workflows — none of which MT5 or its Python API expose natively.

Quick Start

Install MT5-Quant

Option A — Cargo (recommended, needs Rust toolchain)
bash
cargo install mt5-quant --locked
Option B — Pre-built binaries (no toolchain)
bash
# macOS Apple Siliconcurl -LO https://github.com/masdevid/mt5-quant/releases/latest/download/mcp-mt5-quant-macos-arm64.tar.gztar xzf mcp-mt5-quant-macos-arm64.tar.gz   # → mcp-mt5-quant-macos/mt5-quant
# Linux x64curl -LO https://github.com/masdevid/mt5-quant/releases/latest/download/mcp-mt5-quant-linux-x64.tar.gztar xzf mcp-mt5-quant-linux-x64.tar.gz     # → mcp-mt5-quant-linux/mt5-quant

Move the binary somewhere on your PATH (e.g. /usr/local/bin or ~/.local/bin) so clients can launch it as mt5-quant.

Option C — Register with your LLM client (copy-paste)

Claude Code

bash
claude mcp add mt5-quant -- mt5-quant --stdio

Claude Desktop — ~/Library/Application Support/Claude/claude_desktop_config.json

json
{ "mcpServers": { "mt5-quant": { "command": "mt5-quant", "args": ["--stdio"] } } }

Cursor — .cursor/mcp.json (same JSON shape as Claude Desktop)

json
{ "mcpServers": { "mt5-quant": { "command": "mt5-quant", "args": ["--stdio"] } } }

opencode — .opencode/opencode.jsonc

jsonc
{ "mcp": { "mt5-quant": { "type": "local", "command": ["mt5-quant", "--stdio"], "enabled": true } } }

Codex CLI — ~/.codex/config.toml

toml
[mcp_servers.mt5-quant]command = "mt5-quant"args = ["--stdio"]

Then finish setup (auto-detects Wine + MT5 paths):

bash
bash scripts/setup.sh

Tip: you can also just ask your LLM coding agent to do all of the above: "Please install mt5-quant from https://github.com/masdevid/mt5-quant — download or build it, run its scripts/setup.sh to auto-detect Wine and MT5 paths, and register it as an MCP server."

First Backtest

Run a backtest on MyEA from 2025.01.01 to 2025.03.31

The AI runs the full pipeline: compile → clean cache → backtest → extract → analyze.

MCP Tools (89)

Core workflow

ToolDescription
run_backtestFull pipeline: compile → clean → backtest → extract → analyze
run_backtest_quickQuick backtest using pre-compiled EA (skip compile)
run_backtest_onlyBacktest only - just extract raw trades, no analysis
launch_backtestFire-and-forget: launch MT5 backtest, poll for completion
get_backtest_statusPoll running backtest status (MT5 running, report found, elapsed time)
run_optimizationGenetic optimization (background, returns immediately)
get_optimization_resultsParse optimization results after MT5 finishes
list_jobsList all optimization jobs with status
analyze_reportRead analysis.json from any report directory
compare_baselineCompare report vs baseline, return winner/loser verdict
compile_eaCompile MQL5 EA via MetaEditor
list_expertsList all EAs in MQL5/Experts directory
list_indicatorsList all indicators in MQL5/Indicators directory
list_scriptsList all scripts in MQL5/Scripts directory
healthcheckQuick server health check
list_symbolsList all available symbols in MT5 terminal

Granular Analytics (individual analysis)

ToolDescription
analyze_monthly_pnlMonthly P/L breakdown only
analyze_drawdown_eventsDrawdown events and causes only
analyze_top_lossesWorst losing deals only
analyze_loss_sequencesConsecutive loss patterns only
analyze_position_pairsPosition hold time and P/L pairs
analyze_direction_biasBuy vs Sell performance
analyze_streaksWin/loss streak analysis
analyze_concurrent_peakPeak simultaneous positions

Use these for targeted analysis, or analyze_report to run all at once.

Deal-Level Analytics (New)

ToolDescription
list_dealsList individual deals with filters (type, profit range, volume, dates)
search_deals_by_commentFull-text search in deal comments (e.g., "Layer #3")
search_deals_by_magicFilter deals by EA magic number
analyze_profit_distributionProfit histogram: small/medium/large wins and losses
analyze_time_performancePerformance by hour of day and day of week
analyze_hold_time_distributionHold time buckets + correlation with profit
analyze_layer_performanceGrid/martingale layer analysis from comments
analyze_volume_vs_profitVolume correlation + performance by lot size
analyze_costsCommission and swap impact on profitability
analyze_efficiencyProfit per hour/day, annualized return, trade frequency

Monitoring

ToolDescription
verify_setupCheck Wine/MT5 paths, Wine version, and EA/set file counts
get_optimization_statusCheck live state of a background optimization job
list_jobsAll optimization jobs with compact status in one call

Reports & logs

ToolDescription
list_reportsCompact table of all runs with key metrics — no full analysis needed
get_latest_reportGet most recent report with optional equity chart
search_reportsFind reports by EA, symbol, date range, or profit criteria
get_report_by_idGet specific report by ID with equity chart
get_reports_summaryAggregate stats: counts, averages, pass rates
get_best_reportsTop N reports sorted by any metric (profit factor, drawdown, etc.)
search_reports_by_tagsFind reports by tags
search_reports_by_date_rangeQuery by backtest date range
search_reports_by_notesFull-text search in report notes
get_reports_by_set_fileFind all reports using a specific .set file
get_comparable_reportsFind comparable reports (same EA/symbol/timeframe)
tail_logRead last N lines of any log; filter=errors to see only failures
prune_reportsDelete old report directories, keep last N (skips _opt dirs)
promote_to_baselineWrite a history entry or report to baseline.json for compare_baseline

History & baseline

ToolDescription
archive_reportConvert one report dir → compact JSON entry in backtest_history.json, optionally delete source
archive_all_reportsBulk-archive all report dirs then optionally delete them; keeps N newest safe
get_historyQuery history with filters (EA, symbol, verdict, profit, DD) and sort options
annotate_historyAttach verdict / notes / tags to any history entry

Cache management

ToolDescription
cache_statusMT5 tester cache size breakdown by symbol — check before cleaning
clean_cacheDelete tester cache files; supports per-symbol and dry_run

Pre-flight & Validation

ToolDescription
get_active_accountGet current MT5 account session (login, server, available symbols)
check_symbol_data_statusValidate symbol has sufficient history data for date range
check_mt5_statusCheck if MT5 terminal is installed and ready
validate_ea_syntaxPre-compile syntax check without running full compilation

Debugging & Diagnostics (New)

ToolDescription
diagnose_wineCheck Wine installation, version, and prefix health
get_mt5_logsGet MT5 terminal, tester, or MetaEditor logs with filtering
search_mt5_errorsSearch logs for error patterns (crash, exception, access violation)
check_mt5_processCheck if MT5 processes are running, get PID, CPU, memory usage
kill_mt5_processKill stuck MT5 processes (force=true for wineserver)
check_system_resourcesCheck disk space, memory, CPU availability
validate_mt5_configValidate terminal.ini and tester configuration files
get_wine_prefix_infoGet Wine prefix details: Windows version, installed programs, registry
get_backtest_crash_infoInvestigate backtest failures: incomplete markers, missing deals.csv, errors
check_updateCheck if a newer version of MT5-Quant is available
updateUpdate MT5-Quant to latest release

Project Management

ToolDescription
init_projectScaffold new MQL5 project with templates (scalper/swing/grid/basic)
create_set_templateGenerate .set parameter file from EA input variables
export_reportExport backtest report to CSV, JSON, or Markdown

History & Comparison

ToolDescription
get_backtest_historyList all backtests for EA/symbol with summary metrics
compare_backtestsCompare 2+ backtest results side-by-side with analysis

.set file — read / write

ToolDescription
list_set_filesAll .set files in tester profiles dir with sweep stats and combination counts
read_set_fileParse UTF-16LE .set file → structured JSON params
write_set_fileWrite full params dict → UTF-16LE .set with chmod 444
patch_set_fileUpdate specific params in-place, return diff — replaces read→edit→write
clone_set_fileCopy .set to new path with optional overrides in one call

.set file — analysis & generation

ToolDescription
describe_sweepSwept params, value counts, and total optimization combinations
diff_set_filesSide-by-side diff of two .set files — only changed params returned
set_from_optimizationGenerate a clean backtest .set from get_optimization_results params; optionally narrow sweep

Search & Discovery

ToolDescription
search_expertsSearch EAs by name pattern across all directories
search_indicatorsSearch indicators by name pattern
search_scriptsSearch scripts by name pattern
copy_indicator_to_projectCopy indicator to project directory
copy_script_to_projectCopy script to project directory

Full schema: docs/MCP_TOOLS.md

Troubleshooting

Run verify_setup from your LLM first — it checks all paths and returns actionable hints.

For crashes or unexplained failures during backtest/compile/optimization:

  • diagnose_wine — Check Wine installation and prefix health
  • search_mt5_errors — Find crash causes in logs
  • check_mt5_process + kill_mt5_process — Detect and kill stuck processes
  • get_backtest_crash_info — Investigate failed backtest reports

Full Troubleshooting Guide →

Documentation

DocDescription
QUICKSTARTStep-by-step install, setup, and first backtest
MCP_TOOLSFull input/output schemas for all 90 tools
CONFIGConfiguration reference (config/mt5-quant.yaml)
ARCHITECTUREDesign principles and internal module layout
REMOTE_AGENTSDistribute optimization across Linux agents via Wine
TROUBLESHOOTINGPlatform-specific fixes for Wine, MT5, and backtests

Full index with reading order: docs/INDEX.md


Acknowledgements

MT5-Quant stands on the shoulders of exceptional open-source projects:

  • Rust — The language that makes zero-cost abstractions, memory safety, and fearless concurrency practical
  • Tokio — The async runtime powering all concurrent operations
  • Wine — Making MT5 execution possible on macOS and Linux without Windows licensing
  • MetaTrader 5 — MetaQuotes' trading platform (trademark of MetaQuotes Software Corp.)
  • rusqlite — Ergonomic SQLite bindings for Rust
  • serde — The serialization framework making config and report handling painless
  • scraper — HTML parsing for MT5 report extraction
  • tempfile — Secure temporary file handling

Special thanks to the Model Context Protocol (MCP) team at Anthropic for defining the standard that makes AI-powered development workflows possible.

Disclaimer

Not Financial Advice. MT5-Quant is a development and analysis tool for algorithmic trading strategies. It does not provide investment advice, trading recommendations, or guarantee profitability. All backtest results are historical simulations and do not guarantee future performance.

Use at Your Own Risk. Trading financial instruments carries substantial risk of loss. The authors and contributors of MT5-Quant accept no liability for:

  • Trading losses incurred using strategies developed or tested with this tool
  • Data loss or corruption from backtest operations
  • Bugs, errors, or incorrect analysis results
  • System crashes, Wine compatibility issues, or MT5 failures

Software Warranty. This software is provided "as-is" without warranty of any kind, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, or non-infringement. See LICENSE for full terms.

Third-Party Software. MT5-Quant interacts with MetaTrader 5, Wine, and other third-party software. Users are responsible for complying with all applicable licenses and terms of service for these dependencies. MetaTrader is a trademark of MetaQuotes Software Corp. MT5-Quant is not affiliated with, endorsed by, or sponsored by MetaQuotes.

Regulatory Compliance. Users are responsible for ensuring their trading activities comply with applicable financial regulations in their jurisdiction. Automated trading may be restricted or require licensing in some regions.

License

MIT


來源:README.md,提交 62987f0

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.34.3最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分