← Back to Skills Marketplace
apuba

MT4 智能交易桥 · 量化自动交易系统

by apuba · GitHub ↗ · v1.0.10 · MIT-0
cross-platform ⚠ suspicious
149
Downloads
1
Stars
0
Active Installs
11
Versions
Install in OpenClaw
/install mt4-trader
Description
MT4 Trader Bridge enables Python to MT4 EA communication via files for trading, order management, risk control, and grid strategies without extra dependencies.
README (SKILL.md)

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
Usage Guidance
Treat this as a powerful live-trading integration, not a simple information tool. Test on a demo account, verify the external .ex4 files and their source, avoid enabling DLL import or startup auto-trading unless you fully trust the components, and require explicit confirmation for every trade or strategy change.
Capability Analysis
Type: OpenClaw Skill Name: mt4-trader Version: 1.0.10 The skill bundle provides a comprehensive bridge for MetaTrader 4 (MT4) trading, enabling an AI agent to execute trades, manage strategies, and receive notifications. It is classified as suspicious due to high-risk capabilities: the `deploy_ex4.py` script directs users to download and install binary `.ex4` files from an external Gitee repository (gitee.com/3603317/skill-plugin), and `mt4_client.py` uses low-level Windows APIs (`ctypes.windll.user32`) to manipulate windows and simulate keystrokes (`SendInput`) to toggle trading states. Additionally, `position_summary_cron.py` is designed to exfiltrate account and position data to a configurable Webhook endpoint. While these features are consistent with the stated purpose of automated trading, they provide a significant attack surface for financial loss and data exposure.
Capability Tags
crypto
Capability Assessment
Purpose & Capability
The stated purpose is automated MT4 trading, and the artifacts support that purpose, but the capability includes high-impact financial actions such as opening positions, closing all positions, grid trading, and reading account/position data.
Instruction Scope
Trading actions are exposed as direct client methods and documented commands, including bulk close and grid controls, without artifact-level limits such as per-trade confirmation, lot-size caps, account scoping, dry-run defaults, or rollback guidance.
Install Mechanism
The skill instructs users to manually download .ex4 MT4 executables from an external Gitee repository and deploy them into MT4 Experts/Libraries without hashes, signatures, pinned versions, or included source for those binaries.
Credentials
The file bridge and account/position access are coherent for MT4 automation, but they operate against the user's active MT4 session and can affect real funds; optional webhook summaries can also transmit position information.
Persistence & Privilege
The setup encourages enabling MT4 automated trading, including startup auto-trading, and includes persistent strategy/config files that can keep influencing future trading behavior.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install mt4-trader
  3. After installation, invoke the skill by name or use /mt4-trader
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.10
搜索展示名称改为中文为主
v1.0.9
SKILL.md 新增完整英文说明(下半段),中英双语版本
v1.0.8
mt4_bridge.ex4 v1.85: 新增 get_klines 命令,支持通过 CopyRates 实时获取 H1/M15 等周期 K 线数据
v1.0.7
**重大变更:移除自动脚本下载,.ex4 文件需手动下载并部署。** - 用户现在需手动从 Gitee 仓库下载 mt4_bridge.ex4、芝麻网格V2.ex4、tools2.3.ex4 文件,放入 mql4 目录。 - deploy_ex4.py 脚本不再自动下载 .ex4,改为显示下载指引和手动安装步骤。 - 安装文档(SKILL.md)已全面更新,明确说明手动下载与部署流程,降低自动化依赖。 - 其它功能和用法保持不变,Python 客户端接口未调整。
v1.0.6
**重大变更:.ex4 EA 文件从本地内嵌改为自动从 Gitee 下载,优化升级网格策略支持。** - EA 安装方式变更,`deploy_ex4.py` 现在自动从 Gitee 下载 .ex4 文件,无需解压内嵌压缩包。 - 支持新版网格策略 EA,芝麻网格 EA 升级为 V2,说明文档同步更新。 - 文件结构和部署流程优化,更清晰区分 .ex4 目的目录和下载说明。 - SKILL.md 安装说明全面调整,删除“内嵌 EX4/ZIP”,新增 Gitee 下载指引。 - 提升未来维护和更新便捷性,便于后续版本通过 Gitee 定向升级 EA。
v1.0.5
ex4文件因ClawHub安全过滤改为内嵌在deploy_ex4.py中,运行脚本自动解压部署
v1.0.4
ex4文件因ClawHub安全过滤改为zip打包,SKILL.md更新解压部署说明
v1.0.3
大幅补充 SKILL.md 部署说明和 api_docs.md 完整文档(57+ 方法)
v1.0.2
标题改为中文,便于中文用户搜索
v1.0.1
新增SEO关键词标签,提升搜索曝光
v1.0.0
初始发布:MT4交易桥,支持通用交易/网格策略/辅助工具,含Python客户端
Metadata
Slug mt4-trader
Version 1.0.10
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 11
Frequently Asked Questions

What is MT4 智能交易桥 · 量化自动交易系统?

MT4 Trader Bridge enables Python to MT4 EA communication via files for trading, order management, risk control, and grid strategies without extra dependencies. It is an AI Agent Skill for Claude Code / OpenClaw, with 149 downloads so far.

How do I install MT4 智能交易桥 · 量化自动交易系统?

Run "/install mt4-trader" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is MT4 智能交易桥 · 量化自动交易系统 free?

Yes, MT4 智能交易桥 · 量化自动交易系统 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does MT4 智能交易桥 · 量化自动交易系统 support?

MT4 智能交易桥 · 量化自动交易系统 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created MT4 智能交易桥 · 量化自动交易系统?

It is built and maintained by apuba (@apuba); the current version is v1.0.10.

💬 Comments