/install mt4-trader
MT4 智能交易桥 · 量化自动交易系统\r
\r MT4 智能交易桥。通过文件 I/O 与 MT4 EA 通信,无需 DLL 或额外依赖。支持 OpenClaw(小龙虾 AI Agent)通过微信 / 飞书 / Telegram 等渠道直接操作 MT4 交易。\r \r
关键词:MT4, MetaTrader 4, 外汇交易, Python交易, 算法交易, 自动交易, 网格策略, 支撑压力位, ATR止损, 移动止损, 黄金交易, 原油交易, 比特币交易, OpenClaw, 小龙虾, AI交易助手, 微信操作MT4, 飞书操作MT4\r \r ---\r \r
文件结构\r
\r
mt4-trader/\r
├── SKILL.md # 本使用说明\r
├── mql4/ # MT4 EA 编译文件(.ex4,由脚本生成)\r
│ [用户手动下载 .ex4 文件放到此目录]\r
├── scripts/ # Python 脚本\r
│ ├── mt4_client.py # Python 交易客户端(核心)\r
│ ├── deploy_ex4.py # EA 部署指引(显示下载链接和安装步骤)\r
│ ├── alert_commands.py # 价格预警命令行工具\r
│ ├── position_summary.py # 持仓汇总(命令行输出)\r
│ ├── position_summary_cron.py # 持仓汇总(定时推送)\r
│ ├── sr_strategy.py # 支撑压力位策略编排\r
│ └── summary_utils.py # 持仓汇总工具模块\r
└── references/\r
└── api_docs.md # 完整 API 参考文档\r
```\r
\r
---\r
\r
## 安装步骤(详细版)\r
\r
### 第一步:找到你的 MT4 数据目录\r
\r
每个 MT4 安装实例都有一个专属的数据目录,格式为:\r
\r
```\r
%APPDATA%\MetaQuotes\Terminal\\x3C32位随机ID>\r
```\r
\r
例如:`C:\Users\Administrator\AppData\Roaming\MetaQuotes\Terminal\ABC123...`\r
\r
> 怎么找?在 MT4 中按 `F7` 打开 MetaEditor(代码编辑器),点击菜单 `文件 → 打开数据文件夹`,弹出的路径就是你的 MT4 数据目录。\r
\r
### 第二步:确认 MT4 安装目录\r
\r
EA 文件需要部署到两个不同的目录:\r
\r
| EA 文件 | 目标目录 | 说明 |\r
|---------|---------|------|\r
| `mt4_bridge.ex4` | `MT4安装目录\MQL4\Experts\` | 主程序 EA(必须) |\r
| `芝麻网格V2.ex4` | `MT4安装目录\MQL4\Experts\` | 网格策略 EA(可选) |\r
| `tools2.3.ex4` | `MT4安装目录\MQL4\Libraries\` | **网格策略依赖库**(网格必须,不是 Experts!) |\r
\r
> ⚠️ `Libraries` 目录与 `Experts`、`Indicators` 同级,**不是** `Experts` 的子目录。\r
\r
典型路径结构:\r
```\r
C:\Program Files (x86)\EBC Financial Group Cayman MT4 Terminal\MQL4\\r
├── Experts\ ← mt4_bridge.ex4, 芝麻网格V2.ex4 放这里\r
│ ├── mt4_bridge.ex4\r
│ └── 芝麻网格V2.ex4\r
├── Libraries\ ← tools2.3.ex4 放这里(与 Experts 同级!)\r
│ └── tools2.3.ex4\r
├── Indicators\\r
└── Scripts\\r
```\r
\r
### 第三步:下载 .ex4 文件\r
\r
从 Gitee 仓库下载 3 个 .ex4 文件:\r
\r
https://gitee.com/3603317/skill-plugin/tree/master/mt4\r
\r
需要下载的文件:\r
\r
| 文件 | 说明 |\r
|------|------|\r
| `mt4_bridge.ex4` | 主程序 EA(**必选**) |\r
| `芝麻网格V2.ex4` | 网格策略 EA(可选) |\r
| `tools2.3.ex4` | 网格策略依赖库(选网格则必选) |\r
\r
> 点击文件 → 点右上角 **Raw** 按钮即可保存到本地。\r
\r
下载后放入 skills\mt4-trader\mql4\ 目录,然后运行以下命令一键部署到 MT4:\r
\r
```bash\r
cd scripts\\r
python deploy_ex4.py deploy\r
```\r
\r
### 第四步:在 MT4 中挂载 EA\r
\r
**挂载 mt4_bridge(核心,必须操作):**\r
1. 打开 MT4,按 `Ctrl+N` 打开左侧"导航器"面板\r
2. 展开"EA 交易"列表,找到 `mt4_bridge`\r
3. 用鼠标左键拖拽到任意品种图表上(推荐 XAUUSD.s 或主流品种)\r
4. 弹出 EA 属性对话框 → **选项卡"常用"**:\r
- **允许实时交易** → ✅ 勾选(必须!)\r
- **允许导入 DLL** → ✅ 勾选\r
- **确认取消"手动交易禁止"** 等限制\r
5. 点"确定"关闭对话框\r
6. 图表右上角显示一个 EA 图标:\r
- 😊 **绿色笑脸** → ✅ 正常工作中\r
- 😢 哭脸或灰脸 → 检查下面"第五步"的自动交易按钮\r
7. **右键图表 → 属性 → 常用** 中可修改 EA 输入参数(可选)\r
\r
**可选:挂载芝麻网格 EA:**\r
1. 将 `芝麻网格V2` EA 拖到需要跑网格的品种图表上(如 XAUUSD.s、XTIUSD.s)\r
2. 勾选"允许实时交易"\r
3. **确认 `tools2.3.ex4` 已放在 `Libraries\` 目录中**,否则网格 EA 无法运行\r
\r
**多图表挂载(重要):**\r
- mt4_bridge EA 可以挂载在**多个品种**的图表上(例如黄金一个图表、原油一个图表)\r
- 每个 EA 实例自动通过品种专属请求文件区分,不会互相干扰\r
- Python 客户端传了 `symbol` 参数后,会自动路由到对应的品种请求文件\r
\r
### 第五步:开启自动交易\r
\r
这是新手最容易忽略的一步!\r
\r
1. 在 MT4 工具栏上方找到 **"自动交易"按钮**(一个黄色播放 ▶️ 图标)\r
2. 如果它是 **灰色** 的 → 点击一下,变成 **绿色** ✅\r
3. 此时所有已挂载的 EA 图标都应变成 **绿色笑脸** 😊\r
4. 如果某个 EA 还是哭脸,右键该 EA 图标 → "属性" → 勾选"允许实时交易"\r
\r
> 💡 每次重启 MT4 后,自动交易按钮默认为关闭状态,需要手动开启。\r
> 建议在 MT4 设置中勾选"启动时启用自动交易"。\r
\r
### 第六步:验证部署是否成功\r
\r
**方法一:脚本检查**\r
```bash\r
cd scripts\\r
python mt4_client.py\r
```\r
如果看到类似下面的交互菜单,说明通信正常:\r
```\r
=== MT4 交易助手 ===\r
1. 获取报价 2. 查询持仓 3. 交易 4. 网格策略\r
请输入指令:\r
```\r
\r
**方法二:Python 代码验证**\r
```python\r
from mt4_client import MT4Client\r
client = MT4Client()\r
\r
# 获取账户信息(确认通信正常)\r
info = client.get_account_info()\r
print(info) # 应该看到余额、净值、可用保证金\r
\r
# 获取实时报价\r
price = client.get_price("XAUUSD.s")\r
print(price) # 应该看到 bid/ask 价格\r
```\r
\r
**如果返回 `"MT4 超时未响应"`:**\r
- MT4 在运行吗?→ 打开 MT4\r
- EA 挂载了吗?→ 图表上有没有 EA 图标\r
- 自动交易开了吗?→ 工具栏自动交易按钮是绿色吗\r
- EA 属性中"允许实时交易"勾了吗?→ 右键 EA 图标检查\r
\r
---\r
\r
## 核心 Python 方法\r
\r
```python\r
from mt4_client import MT4Client\r
client = MT4Client()\r
\r
# === 行情 ===\r
client.get_price("XAUUSD.s") # 获取实时报价(bid/ask)\r
client.get_positions() # 查询持仓列表\r
client.get_account_info() # 账户余额/净值/保证金\r
client.get_history(7) # 历史订单(最近 7 天)\r
\r
# === 交易 ===\r
client.buy(symbol="XAUUSD.s", lots=0.03) # 市价买入 0.03 手\r
client.sell(symbol="XAUUSD.s", lots=0.03) # 市价卖出 0.03 手\r
client.close(ticket=123456) # 平指定订单\r
client.close_all() # 一键全平\r
client.partial_close(ticket=123456, lots=0.02) # 部分平仓\r
\r
# === 止损止盈 ===\r
client.set_sl(ticket=123456, sl=75000) # 设置止损\r
client.set_tp(ticket=123456, tp=80000) # 设置止盈\r
client.modify_order(ticket=123456, sl=75000, tp=80000) # 同时修改\r
client.auto_sl(ticket=123456, risk_percent=2.0) # 按账户 2% 风险自动止损\r
client.atr_sl(ticket=123456, period=14, multiplier=2.0) # ATR 止损\r
client.trailing_stop(ticket=123456, distance=300) # 移动止损(300 点间距)\r
\r
# === 平所有多单/空单 ===\r
client.close_all_buy() # 平所有多单\r
client.close_all_sell() # 平所有空单\r
client.close_profit() # 平所有盈利单\r
client.close_loss() # 平所有亏损单\r
\r
# === 挂单 ===\r
client.buy_limit(symbol="XAUUSD.s", lots=0.03, price=4500.0) # 限价买入\r
client.sell_limit(symbol="XAUUSD.s", lots=0.03, price=4600.0) # 限价卖出\r
client.buy_stop(symbol="XAUUSD.s", lots=0.03, price=4700.0) # 买入止损(突破追涨)\r
client.sell_stop(symbol="XAUUSD.s", lots=0.03, price=4500.0) # 卖出止损(破位追空)\r
client.get_pending_orders() # 查询当前挂单\r
client.cancel_pending(ticket=123456) # 取消挂单\r
\r
# === OCO 订单(二选一挂单) ===\r
client.oco_order(symbol="XAUUSD.s", lots=0.03,\r
order1={"type": "buy_stop", "price": 77000, "sl": 76500},\r
order2={"type": "sell_stop", "price": 76000, "sl": 76500}\r
)\r
\r
# === 手数计算 ===\r
client.calc_lots(symbol="XAUUSD.s", risk_percent=1.0, sl_distance=5.0)\r
# 1% 风险,止损 5 美元 → 返回建议手数\r
\r
# === K 线数据(量化分析用) ===\r
client.get_klines(symbol="XAUUSD.s", timeframe="H1", count=20) # H1 最近 20 根\r
client.get_klines(symbol="XAUUSD.s", timeframe="M15", count=100) # M15 最近 100 根\r
client.get_klines(symbol="XAUUSD.s", timeframe="D1", count=30) # 最近 30 根日线\r
\r
# === 支撑压力位 ===\r
client.get_sr_levels(symbol="XAUUSD.s") # 获取支撑压力位\r
client.draw_sr_levels(symbol="XAUUSD.s") # 在图表上画出支撑压力位线\r
```\r
\r
> ⚠️ **重要:使用关键字参数!**\r
> 所有交易方法(buy/sell/close/set_sl 等)**必须使用关键字参数**传参:\r
> ```python\r
> # ✅ 正确\r
> client.buy(symbol="XAUUSD.s", lots=0.03)\r
> client.set_sl(ticket=123456, sl=75000)\r
>\r
> # ❌ 错误——按位置传参可能会导致 order 4106(交易被禁用)\r
> client.buy(0.03, "XAUUSD.s") # 顺序可能不对!\r
> ```\r
\r
---\r
\r
## 网格策略(芝麻网格 EA)\r
\r
| 命令 | 说明 |\r
|------|------|\r
| `client.grid_start(symbol="XAUUSD.s")` | 启动网格 |\r
| `client.grid_stop(symbol="XAUUSD.s")` | 停止网格(不再开新单) |\r
| `client.grid_close_all(symbol="XAUUSD.s")` | 平掉所有网格持仓单 |\r
| `client.grid_status(symbol="XAUUSD.s")` | 查询网格运行状态 |\r
| `client.grid_set_sl_tp(symbol="XAUUSD.s")` | 批量设置网格单的止损止盈 |\r
\r
> ⚠️ **平网格仓必须按以下顺序分两步执行:**\r
> ```python\r
> client.grid_stop(symbol="XAUUSD.s") # 第一步:停止网格\r
> client.grid_close_all(symbol="XAUUSD.s") # 第二步:平掉所有网格单\r
> ```\r
> **不可直接用 `close_all()` 平网格单**。`close_all` 命令会拒绝 magic=777777(网格单)。\r
> 网格单必须走芝麻网格 EA 自己的关闭通道。\r
\r
---\r
\r
## 价格预警(可选)\r
\r
```bash\r
cd scripts\\r
\r
python alert_commands.py profit 20 # 总盈利达到 $20 时提醒\r
python alert_commands.py above 77000 # BTC 突破 77000 时提醒\r
python alert_commands.py below 75000 # BTC 跌破 75000 时提醒\r
python alert_commands.py list # 查看当前所有预警\r
python alert_commands.py clear # 清除所有预警\r
python alert_commands.py cancel 3 # 取消第 3 号预警\r
```\r
\r
---\r
\r
## 品种代码\r
\r
| 品种 | 代码 | 说明 |\r
|------|------|------|\r
| 黄金 | `XAUUSD.s` | XAUUSD 后缀 .s 是部分经纪商标准 |\r
| 比特币 | `BTCUSD` | 部分平台为 BTCUSD.pro |\r
| 原油 | `XTIUSD.s` | 美国原油(WTI) |\r
| 白银 | `XAGUSD.s` | 现货白银 |\r
\r
> 品种代码精确格式因经纪商而异。如果 get_price 找不到品种,在 MT4 市场报价中右键 → "全部显示"确认准确的品种名。\r
\r
---\r
\r
## 通信原理\r
\r
```\r
┌──────────┐ JSON 文件 ┌──────────────┐\r
│ Python │ ───request────→ │ MT4 EA │\r
│ Client │ ←──response──── │ (on chart) │\r
└──────────┘ JSON 文件 └──────────────┘\r
```\r
\r
- **共享目录**:`%APPDATA%\MetaQuotes\Terminal\Common\Files\mt4_bridge\`\r
- 示例:`C:\Users\Administrator\AppData\Roaming\MetaQuotes\Terminal\Common\Files\mt4_bridge\`\r
- **请求文件**:`request_{品种}.json`(如 `request_XAUUSD.s.json`)\r
- **响应文件**:`response_{品种}.json`\r
- **协议**:JSON over 文件(零 DLL 依赖)\r
- **超时**:5 秒(Python 客户端默认配置)\r
- **多品种支持**:多个 EA 实例通过品种专属文件名自动区分\r
\r
---\r
\r
## 常见问题排查\r
\r
| 现象 | 可能原因 | 解决方法 |\r
|------|---------|---------|\r
| MT4 超时未响应 | EA 未挂载或自动交易未启动 | 确认图表右上角为绿色笑脸 😊 |\r
| error 4106(交易禁用) | EA 属性中"允许实时交易"未勾选 | 右键 EA → 属性 → 勾选"允许实时交易" |\r
| 找不到价格(空结果) | 品种代码不匹配 | 在 MT4 市场报价中确认精确名称 |\r
| tools2.3 编译报错 | 文件放错了目录 | 确认 tools2.3.ex4 在 `MQL4\Libraries\`,**不是** Experts\ |\r
| 重复下单 | 多个 EA 读同一个请求文件 | 使用 v1.84+ 版本,自动使用品种专属文件 |\r
| BTC 无法市价交易 | 部分经纪商禁用 BTC 市价单 | 改用 `buy_limit()`/`sell_limit()` 限价单 |\r
| 重启 MT4 后 EA 不跑 | 自动交易默认关闭 | 手动点绿色播放按钮,或在设置中勾选"启动时启用" |\r
| 芝麻网格周末不运行 | 经纪商周末休市 | 正常现象,周一开市自动恢复 |\r
\r
---\r
\r
## 版本信息\r
\r
| 文件 | 版本 | 最后更新 |\r
|------|------|---------|\r
| mt4_bridge.ex4 | v1.85 | 2026-05 |\r
| 芝麻网格V2.ex4 | v1.41 | 2026-03 |\r
| tools2.3.ex4 | v2.3 | 2025-12 |\r
| mt4_client.py | v1.85 | 2026-05-05 |\r
| deploy_ex4.py | v1.0.7 | 2026-05-05 |\r
---
# MT4 Trading Bridge · Automated Trading System
MT4 Trading Bridge communicates with MT4 EA via file I/O — zero DLLs, zero extra dependencies. Supports OpenClaw AI Agent to control MT4 trading through WeChat / Feishu / Telegram and other channels.
> **Keywords**: MT4, MetaTrader 4, Forex Trading, Python Trading, Algorithmic Trading, Automated Trading, Grid Strategy, Support & Resistance, ATR Stop Loss, Trailing Stop, Gold Trading, Crude Oil Trading, Bitcoin Trading, OpenClaw, AI Trading Assistant
---
## File Structure
mt4-trader/ ├── SKILL.md # This documentation ├── mql4/ # MT4 EA compiled files (.ex4, generated by script) │ [Manually download .ex4 files here] ├── scripts/ # Python scripts │ ├── mt4_client.py # Python trading client (core) │ ├── deploy_ex4.py # EA deployment guide (shows download links & steps) │ ├── alert_commands.py # Price alert CLI tool │ ├── position_summary.py # Position summary (CLI output) │ ├── position_summary_cron.py # Position summary (scheduled push) │ ├── sr_strategy.py # Support/Resistance strategy orchestrator │ └── summary_utils.py # Position summary utility module └── references/ └── api_docs.md # Full API reference
---
## Installation
### Step 1: Find Your MT4 Data Directory
Each MT4 installation has a unique data directory:
%APPDATA%\MetaQuotes\Terminal\x3C32-char-random-ID>
> How to find it? In MT4, press F7 to open MetaEditor, then click File -> Open Data Folder.
### Step 2: Confirm MT4 Directory
EA files go into two directories:
| EA File | Target Directory | Notes |
|---------|-----------------|-------|
| mt4_bridge.ex4 | MT4_Install_Dir\MQL4\Experts\ | Core EA (required) |
| SesameGridV2.ex4 | MT4_Install_Dir\MQL4\Experts\ | Grid strategy EA (optional) |
| tools2.3.ex4 | MT4_Install_Dir\MQL4\Libraries\ | Grid dependency (required if using grid) |
> Libraries is at the same level as Experts — NOT a subdirectory of Experts.
### Step 3: Download .ex4 Files
From Gitee: https://gitee.com/3603317/skill-plugin/tree/master/mt4
Files: mt4_bridge.ex4 (required), SesameGridV2.ex4 (optional), tools2.3.ex4 (grid dependency).
### Step 4: Attach EAs in MT4
Drag mt4_bridge onto any chart. In properties -> Common tab: check "Allow live trading" and "Allow DLL imports". Green smiley means working.
Optional: Attach SesameGridV2 on grid-trading charts.
### Step 5: Enable Auto Trading
Click the yellow play icon (unicode triangle) on MT4 toolbar to turn it green.
### Step 6: Verify
Run: python mt4_client.py
---
## Core Python Methods
```python
from mt4_client import MT4Client
client = MT4Client()
# Market Data
client.get_price("XAUUSD.s") # Real-time quote
client.get_positions() # Open positions
client.get_account_info() # Account info
client.get_history(7) # Order history (7 days)
# Trading
client.buy(symbol="XAUUSD.s", lots=0.03)
client.sell(symbol="XAUUSD.s", lots=0.03)
client.close(ticket=123456)
client.close_all() # Close all positions
# SL/TP
client.set_sl(ticket=123456, sl=75000)
client.set_tp(ticket=123456, tp=80000)
client.modify_order(ticket=123456, sl=75000, tp=80000)
client.trailing_stop(ticket=123456, distance=300)
# Pending Orders
client.buy_limit(symbol="XAUUSD.s", lots=0.03, price=4500.0)
client.sell_limit(symbol="XAUUSD.s", lots=0.03, price=4600.0)
client.buy_stop(symbol="XAUUSD.s", lots=0.03, price=4700.0)
client.sell_stop(symbol="XAUUSD.s", lots=0.03, price=4500.0)
client.get_pending_orders()
client.cancel_pending(ticket=123456)
# Kline Data
client.get_klines(symbol="XAUUSD.s", timeframe="H1", count=20)
# Support & Resistance
client.get_sr_levels(symbol="XAUUSD.s")
client.draw_sr_levels(symbol="XAUUSD.s")
Use keyword arguments for all trading methods!
Grid Strategy
| Command | Description |
|---|---|
| grid_start(symbol) | Start grid |
| grid_stop(symbol) | Stop grid |
| grid_close_all(symbol) | Close grid orders |
| grid_status(symbol) | Check status |
For closing grid: call grid_stop() first, then grid_close_all().
Symbol Codes
| Instrument | Code |
|---|---|
| Gold | XAUUSD.s |
| Bitcoin | BTCUSD |
| Crude Oil | XTIUSD.s |
| Silver | XAGUSD.s |
Troubleshooting
| Issue | Solution |
|---|---|
| MT4 Timeout | EA not attached or auto-trading off |
| error 4106 | "Allow live trading" unchecked |
| Empty price result | Wrong symbol code |
| Duplicate orders | Use v1.84+ for symbol-specific files |
| BTC market order fails | Some brokers disable BTC market orders |
| ---\r | |
| \r |
MT4 Trading Bridge · Automated Trading System\r
\r MT4 Trading Bridge communicates with MT4 EA via file I/O — zero DLLs, zero extra dependencies. Supports OpenClaw AI Agent to control MT4 trading through WeChat / Feishu / Telegram and other channels.\r \r
Keywords: MT4, MetaTrader 4, Forex Trading, Python Trading, Algorithmic Trading, Automated Trading, Grid Strategy, Support & Resistance, ATR Stop Loss, Trailing Stop, Gold Trading, Crude Oil Trading, Bitcoin Trading, OpenClaw, AI Trading Assistant\r \r ---\r \r
File Structure\r
\r
mt4-trader/\r
├── SKILL.md # This documentation\r
├── mql4/ # MT4 EA compiled files (.ex4, generated by script)\r
│ [Manually download .ex4 files here]\r
├── scripts/ # Python scripts\r
│ ├── mt4_client.py # Python trading client (core)\r
│ ├── deploy_ex4.py # EA deployment guide (shows download links & steps)\r
│ ├── alert_commands.py # Price alert CLI tool\r
│ ├── position_summary.py # Position summary (CLI output)\r
│ ├── position_summary_cron.py # Position summary (scheduled push)\r
│ ├── sr_strategy.py # Support/Resistance strategy orchestrator\r
│ └── summary_utils.py # Position summary utility module\r
└── references/\r
└── api_docs.md # Full API reference\r
```\r
\r
---\r
\r
## Installation\r
\r
### Step 1: Find Your MT4 Data Directory\r
\r
Each MT4 installation has a unique data directory:\r
\r
```\r
%APPDATA%\MetaQuotes\Terminal\\x3C32-char-random-ID>\r
```\r
\r
> How to find it? In MT4, press F7 to open MetaEditor, then click File -> Open Data Folder.\r
\r
### Step 2: Confirm MT4 Directory\r
\r
EA files go into two directories:\r
\r
| EA File | Target Directory | Notes |\r
|---------|-----------------|-------|\r
| mt4_bridge.ex4 | MT4_Install_Dir\MQL4\Experts\ | Core EA (required) |\r
| SesameGridV2.ex4 | MT4_Install_Dir\MQL4\Experts\ | Grid strategy EA (optional) |\r
| tools2.3.ex4 | MT4_Install_Dir\MQL4\Libraries\ | Grid dependency (required if using grid) |\r
\r
> Libraries is at the same level as Experts — NOT a subdirectory of Experts.\r
\r
### Step 3: Download .ex4 Files\r
\r
From Gitee: https://gitee.com/3603317/skill-plugin/tree/master/mt4\r
\r
Files: mt4_bridge.ex4 (required), SesameGridV2.ex4 (optional), tools2.3.ex4 (grid dependency).\r
\r
### Step 4: Attach EAs in MT4\r
\r
Drag mt4_bridge onto any chart. In properties -> Common tab: check "Allow live trading" and "Allow DLL imports". Green smiley means working.\r
\r
Optional: Attach SesameGridV2 on grid-trading charts.\r
\r
### Step 5: Enable Auto Trading\r
\r
Click the yellow play icon on MT4 toolbar to turn it green.\r
\r
### Step 6: Verify\r
\r
Run: python mt4_client.py\r
\r
---\r
\r
## Core Python Methods\r
\r
```python\r
from mt4_client import MT4Client\r
client = MT4Client()\r
\r
# Market Data\r
client.get_price("XAUUSD.s") # Real-time quote\r
client.get_positions() # Open positions\r
client.get_account_info() # Account info\r
client.get_history(7) # Order history (7 days)\r
\r
# Trading\r
client.buy(symbol="XAUUSD.s", lots=0.03)\r
client.sell(symbol="XAUUSD.s", lots=0.03)\r
client.close(ticket=123456)\r
client.close_all() # Close all positions\r
\r
# SL/TP\r
client.set_sl(ticket=123456, sl=75000)\r
client.set_tp(ticket=123456, tp=80000)\r
client.modify_order(ticket=123456, sl=75000, tp=80000)\r
client.trailing_stop(ticket=123456, distance=300)\r
\r
# Pending Orders\r
client.buy_limit(symbol="XAUUSD.s", lots=0.03, price=4500.0)\r
client.sell_limit(symbol="XAUUSD.s", lots=0.03, price=4600.0)\r
client.buy_stop(symbol="XAUUSD.s", lots=0.03, price=4700.0)\r
client.sell_stop(symbol="XAUUSD.s", lots=0.03, price=4500.0)\r
client.get_pending_orders()\r
client.cancel_pending(ticket=123456)\r
\r
# Kline Data\r
client.get_klines(symbol="XAUUSD.s", timeframe="H1", count=20)\r
\r
# Support & Resistance\r
client.get_sr_levels(symbol="XAUUSD.s")\r
client.draw_sr_levels(symbol="XAUUSD.s")\r
```\r
\r
> Use keyword arguments for all trading methods!\r
\r
---\r
\r
## Grid Strategy\r
\r
| Command | Description |\r
|---------|-------------|\r
| grid_start(symbol) | Start grid |\r
| grid_stop(symbol) | Stop grid |\r
| grid_close_all(symbol) | Close grid orders |\r
| grid_status(symbol) | Check status |\r
\r
For closing grid: call grid_stop() first, then grid_close_all().\r
\r
---\r
\r
## Symbol Codes\r
\r
| Instrument | Code |\r
|------------|------|\r
| Gold | XAUUSD.s |\r
| Bitcoin | BTCUSD |\r
| Crude Oil | XTIUSD.s |\r
| Silver | XAGUSD.s |\r
\r
---\r
\r
## Troubleshooting\r
\r
| Issue | Solution |\r
|-------|----------|\r
| MT4 Timeout | EA not attached or auto-trading off |\r
| error 4106 | "Allow live trading" unchecked |\r
| Empty price result | Wrong symbol code |\r
| Duplicate orders | Use v1.84+ for symbol-specific files |\r
| BTC market order fails | Some brokers disable BTC market orders |\r
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install mt4-trader - 安装完成后,直接呼叫该 Skill 的名称或使用
/mt4-trader触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
MT4 智能交易桥 · 量化自动交易系统 是什么?
MT4 Trader Bridge enables Python to MT4 EA communication via files for trading, order management, risk control, and grid strategies without extra dependencies. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 149 次。
如何安装 MT4 智能交易桥 · 量化自动交易系统?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install mt4-trader」即可一键安装,无需额外配置。
MT4 智能交易桥 · 量化自动交易系统 是免费的吗?
是的,MT4 智能交易桥 · 量化自动交易系统 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
MT4 智能交易桥 · 量化自动交易系统 支持哪些平台?
MT4 智能交易桥 · 量化自动交易系统 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 MT4 智能交易桥 · 量化自动交易系统?
由 apuba(@apuba)开发并维护,当前版本 v1.0.10。