MT5 Multi-Pair Market Scanner
An alert-only Python scanner that reads six FX and gold markets from MetaTrader 5, stores candles and setup history in SQLite, sends Telegram alerts and shows a trader dashboard.
The problem
The client trades a structure-based method (bias, liquidity sweep, break of structure, fair value gap retest) by hand across gold and five FX pairs. The client wanted a scanner that watches every market, scores setups and sends the alerts to Telegram. It must never place a trade itself: execution stays manual.
What I built
Phase 1 was the foundation. Phase 2, the full strategy engine, was specified and designed.
- MT5 data layer: the MetaTrader 5 Python package pulls OHLC, tick and spread data from the local terminal for 6 symbols and 4 timeframes (D1, H4, M15, M5).
- Candle cache: an idempotent upsert into SQLite, keyed on symbol, timeframe and time, with pruning to a set bar depth per timeframe.
- 12-table SQLite schema: scanner runs, symbol state, snapshots, candles, setups, alerts, screenshots, journal entries, account snapshots, psychology check-ins, news events and self-checks.
- CLI with seven commands:
init-db,check-mt5,scan-once,doctor, test and demo alerts, anddashboard. doctorself-test: checks the config, the manual-only safety flag, the MT5 connection, every symbol, the candle cache and a Telegram dry run. Results are stored in the database.- Telegram alerts with HTML formatting and a dry-run mode. Credentials are read from environment variables only.
- Trader dashboard in Streamlit: live setup board, session countdowns, account KPIs, a rules gate, a psychology check-in and a preview of the final alert.
- Config-first settings: sessions, EMA and swing parameters, FVG retest tolerance, news blackout and score weights all live in JSON, not in code.
Details
- Setup pipeline design: D1/H4 bias → Asian or previous-day liquidity sweep → break of structure on close → fair value gap → retest → M5/M15 rejection candle → entry, stop and 1:2 target.
- Setup lifecycle: a 12-state machine from idle to final alert, invalidated or expired, with staged alert levels and score bands. This stops duplicate alerts for the same setup.
- Hybrid AI design for phase 2: the deterministic scanner stays the source of truth for detection. Each setup stage writes structured JSON evidence that a language model later reads for journaling and reviews. The model never inspects charts on every scan, which keeps cost down and results testable.
- Clean handoff: the source-only delivery package excluded secrets, the database, the virtual environment and logs.