metatrader-mcp

metatrader-mcp

Enables users to capture real MetaTrader 5 chart snapshots with custom indicators and fetch market data through natural language in Claude Desktop.

Category
访问服务器

README

MetaTrader 5 MCP Server

A lightweight Model Context Protocol (MCP) server for MetaTrader 5 that provides real chart snapshots directly from your MT5 terminal - no browser automation needed!

🌟 Features

  • � Real MT5 Screenshots: Captures actual charts from your MetaTrader 5 terminal with ALL your custom indicators
  • 💹 Market Data: Fetch current prices, spreads, and symbol information
  • 🚀 Lightweight: Expert Advisor + file-based communication (no Selenium, no browser)
  • 🔧 Easy Integration: Works seamlessly with Claude Desktop
  • 🎨 What You See Is What You Get: Captures charts exactly as they appear in MT5
  • ⚡ Fast: Direct chart capture via MQL5's ChartScreenShot function
  • � Secure: File-based communication, no network ports required

🏗️ Architecture

This system uses an innovative approach:

  • MQL5 Expert Advisor: Runs inside MT5, captures real charts using ChartScreenShot()
  • File-Based Protocol: Commands/responses via shared text files (UTF-16 LE encoding)
  • Python MCP Server: Communicates with EA, serves charts to Claude Desktop
  • MetaTrader5 API: For market data and symbol information

Key Advantage: Captures REAL MT5 charts with all your custom indicators, drawings, and settings - exactly as you see them!

📋 Prerequisites

  • Windows OS (MetaTrader 5 requirement)
  • MetaTrader 5 installed (download here)
  • Python 3.10+

🚀 Quick Start

Step 1: Install Dependencies

cd d:\Desktop\metatrader-mcp
pip install -e .

Step 2: Install Expert Advisor

  1. Copy the EA:

    • Open MT5 → File → Open Data Folder
    • Navigate to MQL5\Experts\
    • Copy expert_advisor\MCPChartCapture.mq5 to this folder
  2. Compile the EA:

    • In MT5, press F4 to open MetaEditor
    • Open MCPChartCapture.mq5
    • Press F7 to compile (should show "0 errors")
  3. Attach to a chart:

    • Open any chart in MT5 (e.g., EURUSD H1)
    • In Navigator (Ctrl+N), expand Expert Advisors
    • Drag MCPChartCapture onto the chart
    • In the dialog, go to Common tab:
      • ✅ Allow automated trading
    • Click OK
  4. Enable AutoTrading:

    • Click the AutoTrading button in MT5 toolbar (or press Ctrl+E)
    • You should see a 😊 on the chart

Step 3: Test the Setup

python test_ea_connection.py

Expected output:

✅ Connected to MT5 v5370
✅ EA Response: EA is running
✅ Screenshot saved: output\EURUSD_H1_20251101_024101.png
All tests passed! ✅

Step 4: Configure Claude Desktop

  1. Locate config file:

    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  2. Add MCP server:

    {
      "mcpServers": {
        "metatrader5": {
          "command": "python",
          "args": ["-m", "metatrader_mcp.server"],
          "cwd": "d:\\Desktop\\metatrader-mcp"
        }
      }
    }
    
  3. Restart Claude Desktop

  4. Test it! Ask Claude:

    Show me a screenshot of EURUSD H1 chart
    

🛠️ Available Tools

1. capture_chart_screenshot

Capture a real screenshot from MT5 terminal with all your indicators.

Parameters:

  • symbol (string): Trading pair (e.g., "EURUSD", "XAUUSD", "BTCUSD")
  • timeframe (string): Chart timeframe - M1, M5, M15, M30, H1, H4, D1, W1, MN1

Returns: Path to the captured screenshot (PNG, 1920x1080)

Example:

Capture a screenshot of XAUUSD 15-minute chart

2. list_symbols

Get available trading symbols from MT5.

Parameters:

  • group (string, optional): Filter by group (e.g., "Forex", "Crypto")

Returns: List of symbols with descriptions

Example:

Show me all Forex symbols

3. get_current_price

Get real-time market data for a symbol.

Parameters:

  • symbol (string): Trading pair

Returns: Current bid, ask, spread, time

Example:

What's the current price of EURUSD?

4. get_timeframes

List all supported timeframes.

Returns: Available timeframe codes


📊 Supported Timeframes

Code Description
M1 1 minute
M5 5 minutes
M15 15 minutes
M30 30 minutes
H1 1 hour
H4 4 hours
D1 Daily
W1 Weekly
MN1 Monthly

🗂️ Project Structure

metatrader-mcp/
├── expert_advisor/
│   └── MCPChartCapture.mq5      # MQL5 Expert Advisor for chart capture
├── src/
│   └── metatrader_mcp/
│       ├── server.py             # Main MCP server
│       ├── mt5_handler.py        # MT5 connection & market data
│       └── chart_generator.py    # EA communication & screenshot handling
├── output/                       # Captured screenshots (auto-created)
├── test_ea_connection.py         # Test EA connectivity
├── pyproject.toml                # Python dependencies
└── README.md

🔧 Troubleshooting

❌ EA not responding / Timeout errors

Solutions:

  1. Check the EA is attached to a chart (you should see 😊)
  2. Enable AutoTrading in MT5 (Ctrl+E)
  3. Check Experts log in MT5 for errors
  4. Try removing and reattaching the EA

❌ "MT5 initialization failed"

Solutions:

  1. Verify MT5 is installed: C:\Program Files\MetaTrader 5\terminal64.exe
  2. Open MT5 at least once to initialize
  3. If custom install path, set MT5_PATH environment variable

❌ Screenshot file not found

Solutions:

  1. Ensure EA is running (check for 😊 on chart)
  2. Check Experts log for errors
  3. Verify AutoTrading is enabled
  4. Try capturing a chart that's already open

❌ "Could not fetch data for symbol"

Solutions:

  1. The symbol must exist in your MT5 (check Market Watch)
  2. Symbol names are case-sensitive
  3. Try with "EURUSD" first to test

❌ Encoding errors / Garbled text

Solution: This is fixed! The system uses UTF-16 LE encoding for EA communication.


💡 Usage Examples

Capture Chart with Custom Indicators

Claude, capture a screenshot of my XAUUSD M15 chart

→ Returns actual MT5 chart with all your custom indicators!

Get Multiple Charts

Show me charts for EURUSD H1, GBPUSD H4, and XAUUSD M15

Check Current Prices

What are the current prices for EURUSD, GBPUSD, and USDJPY?

Explore Symbols

List all available Gold symbols

🧪 Testing

Run the test suite:

# Test EA connection
python test_ea_connection.py

# Test chart capture
python take_screenshot.py

# Test specific symbol
python capture_xauusd.py

📝 Configuration (Optional)

Create a .env file for custom settings:

# Custom MT5 installation path
MT5_PATH=C:\Program Files\MetaTrader 5

# Custom output directory for screenshots
OUTPUT_DIR=./charts

🤝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest features
  • Submit pull requests
  • Improve documentation

📄 License

MIT License - see LICENSE file for details

🙏 Acknowledgments

  • MetaTrader 5 Python API - For market data access
  • MCP SDK - Model Context Protocol implementation
  • MQL5 Community - For Expert Advisor development resources

📞 Support

Having issues? Here's how to get help:

  1. Run diagnostics: python test_ea_connection.py
  2. Check MT5 Experts log: Look for error messages in MT5
  3. Verify setup: EA attached? AutoTrading enabled? 😊 visible?
  4. Open an issue: Include error messages and system info

Made with ❤️ for traders who want to integrate MT5 with Claude AI

No browser automation. No Selenium. Just pure, lightweight MT5 chart capture!

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选