AI Multi-Agent Trading System
An 11-agent algorithmic trading system that uses the Claude API to analyze XAU/USD and 40+ instruments, with a Python/Flask bridge to MetaTrader 5 for prop-firm-compliant order execution.
// AI capabilities
- 11 autonomous Claude agents (Sonnet + Haiku) organized in tiers: Authority (Risk, Orchestrator), Analysis (Chart & TA, News & Macro), Market specialists (Metals/Forex/Crypto/Equities), and Ops (Execution, Portfolio, Backtest, Reporting)
- Two-tier command structure where a Risk Agent holds absolute veto power over every trade proposal
- Weighted signal fusion (Chart & TA 40%, Specialist 35%, News & Macro 25%) synthesized by an Orchestrator agent into a single trade decision
- Reporting agent that reviews each session's signals, grades agent accuracy (A-F), and surfaces patterns and recommendations
- ICT-style technical framework (market structure shifts, fair value gaps, order blocks, liquidity sweeps) applied by the Chart & TA agent
// Architecture flow
Overview
This is an algorithmic trading system built around a Claude-powered multi-agent pipeline that analyzes XAU/USD and 40+ other instruments (forex, metals, crypto, equities) and proposes trades on a 60-second tick cycle. The React front end (src/TradingSystem.jsx, ~1,500 lines) runs 11 named agents backed by Anthropic's Sonnet and Haiku models, with a dedicated Risk Agent holding veto power over everything the other agents propose. A separate Python/Flask bridge (mt5-bridge/) connects the system to a MetaTrader 5 terminal so that cleared signals can become real broker orders, with a second, independent rule-enforcement layer (risk_gate.py) sitting between the UI and the broker.
Problem
Discretionary trading against a funded prop-firm account is bound by a specific, unforgiving rulebook: daily loss caps, static or trailing max-drawdown floors, a "consistency" rule capping any single day's profit, a ban on high-frequency trading, and a strict daily reset time (16:15 Chicago Time, not UTC midnight). A human or a naive bot can blow the account by getting any one of these wrong, sizing a position incorrectly, or trading through a rule the model "forgot." The project's own planning document flags the original prototype's hard-coded default equity and risk limits as account-blowing bugs relative to the real, much smaller funded account.
Approach
The system is split into two cooperating layers so that no single point of failure can place an unsafe order:
- Decision layer (React + Claude): each tick, Chart & TA, News & Macro, and a market-specific Specialist agent analyze the instrument in parallel; the Orchestrator fuses their weighted outputs into a proposed direction, entry, stop, and targets; the Risk Agent independently re-checks prop-firm rules and can veto (BLOCK), throttle (REDUCE), or clear (CLEAR) the trade.
- Execution layer (Python bridge): a Flask server holds the live MT5 connection, maps instrument names to broker symbols, computes position size from tick value/contract size, and runs its own
risk_gate.pychecks (daily loss, max drawdown, consistency cap, single-trade-target guard, order-rate/HFT limiter, news blackout, reset-time blackout) against live MT5 account data before ever callingmt5.order_send. The bridge defaults to dry-run mode so the full pipeline (sizing, gating, logging) can be exercised without placing real orders.
A parallel, independent implementation of the same idea exists as a native MQL5 Expert Advisor (XAU_Scalper_TTP.mq5 in a sibling project): a rule-based (non-AI) M5 scalper with two setups (Bollinger Band Bounce, Session Open Burst) that enforces the same prop-firm constraints directly inside MT5, without any external bridge or LLM calls. A companion schedule document defines its exact session windows and a per-tick/per-bar/per-trade decision checklist.
Architecture
- React 18 + Vite front end (
src/TradingSystem.jsx), a single-page dashboard with Dashboard, Agents, Calendar, Signals, Reports, Feed, and Settings tabs - 11 Claude agents across 4 tiers: Authority (Risk Agent - Sonnet, Orchestrator - Sonnet), Analysis (Chart & TA - Sonnet, News & Macro - Haiku), Market specialists (Metals/Forex/Crypto/Equities - Haiku, only the relevant one runs per instrument), and Ops (Execution, Portfolio, Backtest, Reporting - Haiku)
- Python Flask bridge (
mt5-bridge/mt5_bridge.py, ~512 lines) exposing endpoints for status, account, positions, daily state, place/close order, and halt/resume risk_gate.py(~202 lines), the server-side gatekeeper that recomputes lot sizing and re-checks every rule against live MT5 state, independent of the React Risk Agent's decisiondaily_state.pytracks realized P&L and trade count against the 16:15 Chicago Time reset boundary rather than UTC midnightaccount_profile.pyholds the locked account numbers (loss caps, drawdown floor, symbol map) read by both the bridge and its risk gate- JSONL audit logs (
orders.jsonl,refusals.jsonl, plus end-of-day equity snapshots) for every order attempt, refusal, and daily reset - Sibling native EA (
XAU_Scalper_TTP.mq5) implementing the same account rules as MQL5 code running directly inside MT5
Tech stack
- React 18, Vite 5, JavaScript (front end)
- Claude API (Sonnet and Haiku models) for the 11 trading agents
- Python 3.12, Flask, Flask-CORS, the MetaTrader5 Python package (execution bridge)
- MetaTrader 5 terminal and MQL5 (bridge target and the separate native EA)
- Optional data integrations referenced in the docs: Twelve Data (OHLCV), Finnhub (calendar/news), FRED (macro), Telegram (alerts), Notion (trade journal)
AI work
- Designed the two-tier agent hierarchy (Risk Agent veto over Orchestrator synthesis) so no single agent's output can bypass risk controls
- Wrote the weighted signal-fusion logic (Chart & TA 40%, Specialist 35%, News & Macro 25%) that the Orchestrator uses to turn three independent agent opinions into one trade decision
- Built a market-specialist pattern where only the relevant specialist activates per instrument, keeping token usage down (README documents roughly 4,000 to 6,000 tokens per tick across Sonnet + Haiku calls)
- Implemented the Reporting Agent that grades each agent's session accuracy (A-F) and generates pattern/recommendation summaries at session close
- Encoded a full prop-firm rulebook as explicit, human-reviewed rules rather than leaving compliance to model judgment alone, then mirrored those same rules in the independent Python
risk_gate.pyas a non-LLM backstop
Engineering highlights
- Defense-in-depth risk enforcement: the same account rules are checked twice, once by the Claude Risk Agent and again independently by the Python risk gate against live MT5 numbers, so a prompt drift or UI bug cannot bypass the account's actual limits
- Dry-run-by-default bridge:
mt5_bridge.pywill not place a real order until explicitly launched with--live, letting the full pipeline be validated risk-free first - Position sizing computed from live broker tick value/contract size (not a fixed formula), clamped to broker min/max/step, with a dedicated unit test suite (
tests/test_sizing.py, ~234 lines) that must pass before any demo order - A kill switch (halt endpoint) that can freeze the bridge from any device on the network, checked on every place-order call so it stops mid-tick
- Append-only JSONL audit trail for every order, every refusal, and every daily reset, giving a paper trail independent of the UI
- Daily accounting anchored to the broker's actual reset time (16:15 Chicago Time) rather than assuming UTC midnight
Lessons
- The connection/execution plan itself documents that the first version had a hard-coded default equity far larger than the real account, which would have sized every position many times too large; this was caught during planning rather than in a live trade.
- The project deliberately treats the Claude-driven Risk Agent as advisory, not authoritative, for real-money safety: the final, load-bearing checks live in plain Python code that reads live MT5 state, not in an LLM's output.
- As of the reviewed files, the system has been validated as a research/paper-trading tool with a dry-run-capable execution bridge; the documented path to live trading requires a minimum one-week demo validation period before any real capital, which had not yet been marked complete.
Want to dig deeper?
Ask my AI agent anything about how this was built, what tradeoffs I made, or how it could fit your team.
Ask my AI →// related projects
WhatsApp AI Shopify Bot
A WhatsApp bot powered by Claude and connected live to a Shopify store, answering product and order questions, generating secure checkout links, and handing off to a human when needed.
AI SEO Collection Optimizer
Autonomous SEO content engine that captures Lebanese organic search demand by generating high-confidence collection landing pages on a parallel VPS layer, grounded in Search Console signals, Shopify orders, and live catalog data, with a self-improving GSC measurement loop.
Marketing Intelligence Dashboard
Enterprise marketing operations platform (16 modules) covering campaigns, approvals, creative intake, compliance, and analytics, with an OpenAI-powered AI assistant via the Vercel AI SDK and one-click PPTX stakeholder reporting.