简介
OpenClaw 机构级贵金属交易操作系统,基于 ICT/SMC 方法论实现 XAU/USD 与 XAG/USD 的全自动量化交易,内置 8 引擎风控体系与实时绩效追踪。
原始描述
Institutional Desk-Level Fully Automated Trading OS for XAU/USD and XAG/USD. Event-driven, risk-first, multi-engine architecture that runs as a continuous analysis and execution pipeline inside OpenClaw's trader agent.
中文使用说明 来自收录源
核心用法
Metals Desk OS 是一套事件驱动、风险优先的多引擎交易操作系统,专为黄金(XAU/USD)和白银(XAG/USD)的自动化交易设计。系统通过 8 个核心引擎(结构、流动性、偏差、宏观、波动率、风险、执行、绩效)构成连续分析管道,从价格输入到订单执行实现全链路自动化。用户可通过 4 种模式灵活控制自动化程度:模式 1(顾问模式)仅生成信号不执行;模式 2(半自动)自动管理止盈止损;模式 3(全自动)完全自主交易;模式 4(风险关闭)仅监控不生成信号。
显著优点
机构级风控体系:内置 10 条不可覆盖的硬规则,包括单笔 2% 风险上限、日度 5% 敞口上限、3 连亏自动暂停、8% 回撤强制停机等,形成多层防护网。多维度信号验证:交易信号需同时满足偏差置信度≥65、对齐分数≥0.6、流动性清扫确认、结构突破确认、宏观风险可控等 10 项条件,显著降低假信号。实时透明监控:WebSocket 仪表板(端口 3078)实时广播价格、偏差、持仓、宏观面板、绩效指标等全量状态,支持 Telegram/WhatsApp 多渠道警报。模块化可扩展:事件总线架构允许外部系统订阅关键事件(价格更新、结构转变、风险暂停等),便于二次开发。
潜在缺点与局限性
外部依赖风险:核心交易执行依赖 MetaAPI.cloud 和 MT5 经纪商连接,API 中断或经纪商故障将直接影响交易连续性。新闻数据局限:虽内置新闻屏蔽机制(高影响新闻前 20 分钟阻止入场),但未集成实时新闻流解析,依赖外部经济日历数据质量。策略单一性:当前仅针对 XAU/USD 和 XAG/USD 优化,未覆盖其他贵金属或外汇品种;策略基于 ICT/SMC 方法论,对趋势行情表现较好,震荡市可能频繁止损。学习曲线陡峭:8 引擎协同工作机制、多时间框架偏差计算、流动性地图等概念对非专业交易者理解门槛较高。
适合的目标群体
专业交易员与自营交易团队:具备 ICT/SMC 技术分析基础,需要自动化执行以克服情绪干扰。量化策略开发者:寻求事件驱动架构作为策略回测与实盘部署的基础框架。风控优先的资产管理人:重视硬性止损规则与实时风险监控,而非追求极致收益。贵金属专项交易者:专注黄金、白银市场,需要多时间框架结构分析与宏观联动监控。
使用风险
资金风险:全自动模式下系统直接操作真实账户,尽管有多重风控,极端行情(如闪崩、流动性枯竭)仍可能导致超预期亏损。技术故障风险:MetaAPI 或 MT5 连接异常时,"API 错误不重试"和"断开即平仓"规则可能造成非计划离场或错失行情。配置错误风险:环境变量配置失误(如错误账户 ID、Token 泄露)可能导致交易异常或安全漏洞。性能瓶颈:8 引擎实时计算在 tick 级高频数据下可能产生延迟,建议配合 VPS 部署以降低网络抖动影响。
技能正文
name: metals-desk-os description: Institutional Desk-Level Fully Automated Trading OS for XAU/USD and XAG/USD. Event-driven, risk-first, multi-engine architecture that runs as a continuous analysis and execution pipeline inside OpenClaw's trader agent.
Metals Desk OS
An institutional-grade metals trading operating system for gold (XAU/USD) and silver (XAG/USD). This skill transforms the OpenClaw trader agent into a full prop-desk assistant with real-time analysis, automated execution, risk management, and performance tracking.
When to Use This Skill
Use this skill when:
- Analyzing gold or silver market structure (ICT/SMC methodology)
- Generating trade signals with full entry/SL/TP plans
- Running automated or semi-automated trade execution via MT5
- Monitoring real-time risk, drawdown, and position management
- Tracking trading performance (win rate, expectancy, Sharpe, drawdown)
- Getting session-aware, macro-aware trading intelligence
Architecture Overview
The system runs as a continuous event-driven pipeline:
PRICE FEED → SESSION ENGINE → STRUCTURE ENGINE → LIQUIDITY ENGINE →
MACRO ENGINE → BIAS ENGINE → VOLATILITY ENGINE → RISK ENGINE →
EXECUTION ENGINE → BROKER → PERFORMANCE ENGINE → DASHBOARD → ALERTS
All engines communicate through a central Event Bus (EventEmitter pattern). Every event is logged and can be monitored in real-time via WebSocket.
Core Engines
| Engine | Purpose | Key Outputs |
|---|---|---|
| Structure Engine | Detects HH/HL/LH/LL, BOS, CHoCH, FVG, Order Blocks | Market structure, trend direction, structural shifts |
| Liquidity Engine | Finds equal highs/lows, stop clusters, session levels, sweeps | Liquidity pools, sweep confirmations |
| Bias Engine | Multi-timeframe directional bias with conviction scoring | HTF bias, intraday bias, conviction 0-100, alignment score |
| Macro Engine | Tracks DXY, US10Y yields, risk sentiment, news proximity | macro_bias (bullish/bearish/neutral gold), macro_risk level |
| Volatility Engine | ATR calculation, spike detection, regime classification | ATR, volatility regime (low/normal/high/extreme) |
| Risk Engine | Position sizing, drawdown monitoring, halt triggers | Lot size, risk %, pass/fail gate for every trade |
| Execution Engine | Combines all engines to generate trade signals | Full trade plan: entry, SL, TP1/TP2/TP3, position size |
| Performance Engine | Win rate, expectancy, Sharpe, monthly breakdown | Comprehensive performance metrics and trade log |
System Modes
| Mode | Name | Behavior |
|---|---|---|
| 1 | Advisory | Full analysis pipeline runs, signals logged, no execution |
| 2 | Semi-Automated | Signals generated + automatic TP/SL/trailing management |
| 3 | Fully-Automated | Autonomous execution: signal → order → manage → close |
| 4 | Risk-Off | Monitoring only, no signals generated |
Set the mode in data/state.json or via WebSocket command. Always start in Mode 1 for validation.
Risk Rules (Non-Negotiable)
These hard rules are enforced by the Risk Engine and cannot be overridden:
- Max 2% risk per trade — Position sized via
(Balance × Risk%) / StopDistance - Max 5% daily exposure — Cumulative open risk capped
- 3 consecutive losses → halt trading for the session
- Volatility spike → reduce size 50% (extreme = 75% reduction)
- Spread widening → block entry (symbol-specific thresholds)
- High-impact news < 20 minutes → block all entries
- Equity drawdown > 8% → halt trading until manual resume
- API error on order → cancel, do NOT retry
- Broker disconnect → close all positions immediately
Trade Management Protocol
- TP1 at 1.5R → Partial close 40% → Move SL to break-even
- TP2 at 2.5R → Partial close 30% → Trail SL under structure
- TP3 at 4.0R → Close remaining 30% → Log trade to performance
Entry Conditions (All Must Pass)
For the Execution Engine to generate a signal, every condition must be true:
- Bias conviction ≥ 65/100
- Alignment score ≥ 0.6
- Liquidity sweep confirmed (aligned with direction)
- BOS or CHoCH confirmed in trade direction
- Session = London or New York (kill zones preferred)
- Macro risk = low or medium
- Spread within threshold
- No news block active
- Daily loss below 80% of limit
- Consecutive losses < 3
File Structure
metals-desk-os/
├── SKILL.md # This file
├── index.js # Main orchestrator & entry point
├── package.json # npm dependencies
├── skill.json # OpenClaw registration manifest
├── manifest.json # Runtime configuration
├── core/ # 8 trading engines
│ ├── structure-engine.js # HH/HL/LH/LL, BOS, CHoCH, FVG, OB
│ ├── liquidity-engine.js # Pools, sweeps, equal levels
│ ├── bias-engine.js # MTF bias, conviction scoring
│ ├── macro-engine.js # DXY, yields, sentiment, news
│ ├── volatility-engine.js # ATR, regime, spikes
│ ├── risk-engine.js # Position sizing, halts
│ ├── execution-engine.js # Signal generation
│ └── performance-engine.js # Metrics tracking
├── automation/ # System automation layer
│ ├── event-bus.js # Central event system
│ ├── price-feed.js # MT5/MetaAPI price data
│ ├── session-engine.js # London/NY/Asian sessions
│ ├── scheduler.js # Cron tasks
│ └── news-monitor.js # Economic calendar
├── broker/ # MT5 broker integration
│ ├── mt5-connector.js # Order execution via MetaAPI
│ ├── risk-guard.js # Position monitoring & trailing
│ └── order-manager.js # Order lifecycle management
├── dashboard/ # Real-time monitoring
│ ├── websocket-feed.js # WebSocket broadcaster (port 3078)
│ ├── desk-dashboard.json # Widget layout config
│ └── metrics.json # Metrics template
├── alerts/ # Notification channels
│ ├── whatsapp-alert.js # WhatsApp Business API
│ ├── telegram-alert.js # Telegram Bot
│ └── risk-alert.js # Centralized dispatcher
├── data/ # Persistent state files
│ ├── state.json # System mode & connections
│ ├── trade-log.json # Trade history
│ ├── performance.json # Performance metrics
│ └── bias-memory.json # Bias state persistence
└── prompts/ # AI agent prompts
├── system.txt # Main system prompt
├── intraday.txt # Intraday trading protocol
├── swing.txt # Swing trading protocol
└── execution.txt # Execution protocol
Installation
Step 1: Deploy to OpenClaw
cp -r metals-desk-os/ ~/.openclaw/agents/trader/agent/metals-desk-os/
cd ~/.openclaw/agents/trader/agent/metals-desk-os/
Step 2: Install Dependencies
npm install
Step 3: Configure Environment
Create a .env file in the skill root with the following variables:
# MetaAPI / MT5 Connection
METAAPI_TOKEN=your_metaapi_token_here
MT5_ACCOUNT_ID=your_mt5_account_id_here
# WhatsApp Business API (optional)
WHATSAPP_API_URL=https://graph.facebook.com/v18.0/YOUR_PHONE_NUMBER_ID/messages
WHATSAPP_TOKEN=your_whatsapp_token_here
WHATSAPP_PHONE=your_phone_number_with_country_code
# Telegram Bot (optional)
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
TELEGRAM_CHAT_ID=your_telegram_chat_id_here
# News API (optional)
NEWS_API_KEY=
# AI Keys (optional, for enhanced analysis)
OPENROUTER_API_KEY=
ANTHROPIC_API_KEY=
MetaAPI: Sign up at https://metaapi.cloud and connect your Fusion Markets MT5 account. Telegram: Create a bot via @BotFather, get chat ID from @userinfobot. WhatsApp: Configure via Meta Business API dashboard.
Step 4: Set Initial Mode
Edit data/state.json and set "mode": 1 (Advisory) to start safely.
Step 5: Start
# Direct
node index.js
# Or with PM2 for production
pm2 start index.js --name metals-desk-os
pm2 save
pm2 startup
Dashboard
Connect any WebSocket client to ws://localhost:3078 to receive real-time JSON payloads containing:
- Live prices and spread statistics
- HTF and intraday bias with conviction scores
- Active positions with live P&L and R:R
- Liquidity map (equal highs/lows, sweep markers)
- Macro panel (DXY, yields, news countdown)
- Performance metrics (win rate, expectancy, drawdown, Sharpe)
- Risk status (halt state, daily P&L, exposure)
- Event log (all system events)
Alert Formats
Trade opened:
TRADE OPENED
Pair: XAUUSD
Direction: Long
Entry: 5024.50
SL: 5010.00
TP1: 5046.25
Risk: 1.5%
Session: London
Conviction: 82/100
Risk halt:
RISK HALT ACTIVATED
Reason: 3 consecutive losses
Trading paused for session
Key Events
The Event Bus broadcasts these events that external systems can subscribe to:
price.update— New price tick with candle datastructure.shift— BOS or CHoCH detectedliquidity.sweep— Liquidity pool sweptbias.update— Bias recalculatedbias.flip— HTF bias direction changedexecution.signal— Valid trade signal generatedrisk.halt/risk.resume— Trading halted or resumedorder.filled/order.closed— Order lifecycle eventsperformance.update— New trade recorded to performancemacro.news.block— News event blocking execution
Validation Checklist
Before moving beyond Mode 1:
- Price feed produces ticks (live or simulated)
- Structure engine detects swing points and BOS/CHoCH
- Liquidity engine identifies pools and sweeps
- Bias engine produces conviction scores > 0
- Session engine correctly identifies current session
- Risk engine validates and rejects test scenarios
- Execution engine generates signals with full entry plans
- Alerts arrive on configured channels
- WebSocket feed broadcasts state updates
Once all pass, move to Mode 2 (Semi-Auto) to test position management, then Mode 3 (Full-Auto) for live execution.
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。