TradingView to MT5 Webhook Bridge
A TradingView alert pipeline that validated signed JSON, calculated position size, routed orders to MT5, and reconciled terminal state.
Problem and business goal
- Problem
- The client’s Pine Script alerts were useful but manual execution caused late entries, inconsistent lot sizing, and missed exits.
- Business goal
- Execute TradingView swing signals in MT5 without manual copying, duplicate alerts, or prop-rule mistakes.
Architecture
- Pine alert JSON
- Webhook receiver
- Token validation
- Risk sizing
- MT5 bridge
- Reconciliation job
Technology stack
- Pine Script v5
- FastAPI
- Python
- MetaTrader 5 bridge
- Uptime monitoring
Development challenges
- TradingView retries can duplicate alerts when the receiver is slow.
- Symbols used in TradingView did not match broker symbols exactly.
- MT5 terminal state could drift from expected position state after partial closes.
Implementation
- Designed a strict alert schema with side, symbol, timestamp, strategy ID, and idempotency key.
- Added token validation, replay checks, and symbol mapping before any order reached MT5.
- Built a reconciliation loop that compared expected position state with live terminal state.
Results
- Valid alerts executed within a predictable latency window.
- Duplicate alert execution was blocked by idempotency keys.
- The client could inspect each alert, decision, order, and reconciliation event.
Lessons learned
- TradingView automation fails most often in the bridge, not in Pine.
- Idempotency and reconciliation are mandatory once real capital is involved.
Frequently asked questions
Does TradingView place the trades directly?
No. TradingView sends alerts. A secure bridge receives the alert and routes the order to MT5, an exchange, or another broker API.
Can the bridge connect to Binance instead of MT5?
Yes. The routing layer can target MT5, Binance, Bybit, KuCoin, MEXC, or another venue with an API.