# dn0218/mt5-ftmo-trader architecture

> Architecture diagram of the GitHub repository dn0218/mt5-ftmo-trader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dn0218/mt5-ftmo-trader
- Repository: https://github.com/dn0218/mt5-ftmo-trader

## Overview

MT5 FTMO Trader is an autonomous MetaTrader 5 trading bot. Its principal workflow scans broker bars, detects and scores Smart Money Concepts setups, optionally sends qualified signals through an LLM veto, then applies risk controls and places/manages trades. Separate capabilities cover session/news filtering, Telegram monitoring, performance tracking, audit records, and replay snapshots. The worker excerpt and source index support several internal calls; the README documents the broader trade lifecycle. Some unsampled service wiring is therefore shown only where documented.

Main entry points: [`services/worker/engine.py`](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/worker/engine.py) (Scan & Monitor), [`core/evidence/build_evidence.py`](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/evidence/build_evidence.py) (Signal Evidence), [`main.py`](https://github.com/dn0218/mt5-ftmo-trader/blob/main/main.py) (Application Entry), [`core/mt5/data.py`](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/mt5/data.py) (MT5 Market Data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Runtime"]
  node_main["Application Entry<br/>[main.py]"]
  node_engine["Scan &amp; Monitor<br/>[engine.py]"]
end

subgraph group_analysis["Market Analysis"]
  node_mt5data["MT5 Market Data<br/>[data.py]"]
  node_structure["Structure &amp; Breakouts<br/>[structure.py]"]
  node_liquidity["Liquidity Sweeps<br/>[liquidity.py]"]
  node_orderblocks["Order Blocks<br/>[orderblocks.py]"]
  node_fvg["Fair Value Gaps<br/>[fvg.py]"]
  node_regime["Market Regime<br/>[regime.py]"]
  node_trendlines["Trendlines<br/>[trendlines.py]"]
  node_indicators["Technical Indicators<br/>[indicators.py]"]
  node_evidence["Signal Evidence<br/>[build_evidence.py]"]
  node_confluence["Confluence Score<br/>[confluence.py]"]
end

subgraph group_trading["Trade Lifecycle"]
  node_targets["Target Ladder<br/>[targets.py]"]
  node_decider["LLM Veto<br/>[ollama_decider.py]"]
  node_risk["FTMO Risk Controls<br/>[risk_manager.py]"]
  node_execution["MT5 Execution<br/>[mt5_exec.py]"]
  node_manager["Position Management<br/>[manager.py]"]
  node_calendar["News Filter<br/>[news_filter.py]"]
  node_state[("Risk State Store<br/>[state_store.py]")]
end

subgraph group_operations["Operations &amp; Insights"]
  node_telegram["Telegram Alerts<br/>[telegram.py]"]
  node_audit[("Audit Logging<br/>[audit_logger.py]")]
  node_snapshot[("Trade Snapshots<br/>[snapshot_writer.py]")]
  node_performance[("Performance Tracker<br/>[performance.py]")]
end

node_operator(("Operator"))
node_telegram_api(("Telegram API"))
node_broker(("MetaTrader 5"))
node_llm_provider(("OpenAI / Ollama"))

node_operator -->|"starts"| node_main
node_main -->|"starts"| node_engine
node_engine -->|"loads bars"| node_mt5data
node_mt5data -->|"requests data"| node_broker
node_engine -->|"analyzes"| node_structure
node_engine -->|"analyzes"| node_liquidity
node_engine -->|"checks regime"| node_regime
node_engine -->|"calculates"| node_indicators
node_engine -->|"builds evidence"| node_evidence
node_evidence -->|"reads signals"| node_structure
node_evidence -->|"reads signals"| node_liquidity
node_evidence -->|"reads signals"| node_orderblocks
node_evidence -->|"reads signals"| node_fvg
node_evidence -->|"reads signals"| node_regime
node_evidence -->|"reads values"| node_indicators
node_engine -->|"scores setup"| node_confluence
node_engine -->|"requests veto"| node_decider
node_decider -->|"queries"| node_llm_provider
node_engine -->|"builds targets"| node_targets
node_engine -->|"checks risk"| node_risk
node_risk -->|"reads/writes"| node_state
node_engine -->|"filters news"| node_calendar
node_engine -->|"places trades"| node_execution
node_execution -->|"sends orders"| node_broker
node_engine -->|"monitors positions"| node_manager
node_manager -->|"records outcomes"| node_performance
node_engine -->|"submits context"| node_snapshot
node_snapshot -->|"logs events"| node_audit
node_engine -->|"sends alerts"| node_telegram
node_telegram -->|"posts messages"| node_telegram_api
node_engine -->|"records events"| node_audit
node_engine -.->|"includes detection"| node_orderblocks
node_engine -.->|"includes detection"| node_fvg
node_engine -.->|"includes detection"| node_trendlines

click node_main "https://github.com/dn0218/mt5-ftmo-trader/blob/main/main.py"
click node_engine "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/worker/engine.py"
click node_mt5data "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/mt5/data.py"
click node_structure "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/structure.py"
click node_liquidity "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/liquidity.py"
click node_orderblocks "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/orderblocks.py"
click node_fvg "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/fvg.py"
click node_regime "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/regime.py"
click node_trendlines "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/trendlines.py"
click node_indicators "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/indicators/indicators.py"
click node_evidence "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/evidence/build_evidence.py"
click node_confluence "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/scoring/confluence.py"
click node_targets "https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/scoring/targets.py"
click node_decider "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/decision/ollama_decider.py"
click node_risk "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/risk/risk_manager.py"
click node_execution "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/mt5_exec.py"
click node_manager "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/trade_management/manager.py"
click node_calendar "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/calendar/news_filter.py"
click node_state "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/risk/state_store.py"
click node_telegram "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/notifications/telegram.py"
click node_audit "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/logging/audit_logger.py"
click node_snapshot "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/snapshots/snapshot_writer.py"
click node_performance "https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/analytics/performance.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_engine toneBlue
class node_mt5data,node_structure,node_liquidity,node_orderblocks,node_fvg,node_regime,node_trendlines,node_indicators,node_evidence,node_confluence toneAmber
class node_targets,node_decider,node_risk,node_execution,node_manager,node_calendar,node_state,node_telegram_api toneMint
class node_telegram,node_audit,node_snapshot,node_performance toneRose
class node_operator,node_broker,node_llm_provider toneIndigo
```

## Components

### Runtime

- [Application Entry](https://github.com/dn0218/mt5-ftmo-trader/blob/main/main.py): `main.py`
- [Scan & Monitor](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/worker/engine.py): `services/worker/engine.py`

### Market Analysis

- [MT5 Market Data](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/mt5/data.py): `core/mt5/data.py`
- [Structure & Breakouts](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/structure.py): `core/detection/structure.py`
- [Liquidity Sweeps](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/liquidity.py): `core/detection/liquidity.py`
- [Order Blocks](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/orderblocks.py): `core/detection/orderblocks.py`
- [Fair Value Gaps](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/fvg.py): `core/detection/fvg.py`
- [Market Regime](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/regime.py): `core/detection/regime.py`
- [Trendlines](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/detection/trendlines.py): `core/detection/trendlines.py`
- [Technical Indicators](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/indicators/indicators.py): `core/indicators/indicators.py`
- [Signal Evidence](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/evidence/build_evidence.py): `core/evidence/build_evidence.py`
- [Confluence Score](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/scoring/confluence.py): `core/scoring/confluence.py`

### Trade Lifecycle

- [Target Ladder](https://github.com/dn0218/mt5-ftmo-trader/blob/main/core/scoring/targets.py): `core/scoring/targets.py`
- [LLM Veto](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/decision/ollama_decider.py): `services/decision/ollama_decider.py`
- [FTMO Risk Controls](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/risk/risk_manager.py): `services/risk/risk_manager.py`
- [MT5 Execution](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/mt5_exec.py): `services/mt5_exec.py`
- [Position Management](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/trade_management/manager.py): `services/trade_management/manager.py`
- [News Filter](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/calendar/news_filter.py): `services/calendar/news_filter.py`
- [Risk State Store](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/risk/state_store.py): `services/risk/state_store.py`

### Operations & Insights

- [Telegram Alerts](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/notifications/telegram.py): `services/notifications/telegram.py`
- [Audit Logging](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/logging/audit_logger.py): `services/logging/audit_logger.py`
- [Trade Snapshots](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/snapshots/snapshot_writer.py): `services/snapshots/snapshot_writer.py`
- [Performance Tracker](https://github.com/dn0218/mt5-ftmo-trader/blob/main/services/analytics/performance.py): `services/analytics/performance.py`

### Other components

- **Operator**
- **Telegram API**
- **MetaTrader 5**
- **OpenAI / Ollama**

## Connections

- Operator → Application Entry: starts (evidence: `README.md`)
- Application Entry → Scan & Monitor: starts (evidence: `main.py`)
- Scan & Monitor → MT5 Market Data: loads bars (evidence: `services/worker/engine.py`)
- MT5 Market Data → MetaTrader 5: requests data (evidence: `README.md`)
- Scan & Monitor → Structure & Breakouts: analyzes (evidence: `services/worker/engine.py`)
- Scan & Monitor → Liquidity Sweeps: analyzes (evidence: `services/worker/engine.py`)
- Scan & Monitor → Market Regime: checks regime (evidence: `services/worker/engine.py`)
- Scan & Monitor → Technical Indicators: calculates (evidence: `services/worker/engine.py`)
- Scan & Monitor → Signal Evidence: builds evidence (evidence: `services/worker/engine.py`)
- Signal Evidence → Structure & Breakouts: reads signals (evidence: `core/evidence/build_evidence.py`)
- Signal Evidence → Liquidity Sweeps: reads signals (evidence: `core/evidence/build_evidence.py`)
- Signal Evidence → Order Blocks: reads signals (evidence: `core/evidence/build_evidence.py`)
- Signal Evidence → Fair Value Gaps: reads signals (evidence: `core/evidence/build_evidence.py`)
- Signal Evidence → Market Regime: reads signals (evidence: `core/evidence/build_evidence.py`)
- Signal Evidence → Technical Indicators: reads values (evidence: `core/evidence/build_evidence.py`)
- Scan & Monitor → Confluence Score: scores setup (evidence: `services/worker/engine.py`)
- Scan & Monitor → LLM Veto: requests veto (evidence: `services/worker/engine.py`)
- LLM Veto → OpenAI / Ollama: queries (evidence: `README.md`)
- Scan & Monitor → Target Ladder: builds targets (evidence: `services/worker/engine.py`)
- Scan & Monitor → FTMO Risk Controls: checks risk (evidence: `README.md`)
- FTMO Risk Controls → Risk State Store: reads/writes (evidence: `services/risk/risk_manager.py`)
- Scan & Monitor → News Filter: filters news (evidence: `README.md`)
- Scan & Monitor → MT5 Execution: places trades (evidence: `README.md`)
- MT5 Execution → MetaTrader 5: sends orders (evidence: `README.md`)
- Scan & Monitor → Position Management: monitors positions (evidence: `services/worker/engine.py`)
- Position Management → Performance Tracker: records outcomes (evidence: `services/trade_management/manager.py`)
- Scan & Monitor → Trade Snapshots: submits context (evidence: `services/worker/engine.py`)
- Trade Snapshots → Audit Logging: logs events (evidence: `services/snapshots/snapshot_writer.py`)
- Scan & Monitor → Telegram Alerts: sends alerts (evidence: `services/worker/engine.py`)
- Telegram Alerts → Telegram API: posts messages (evidence: `services/notifications/telegram.py`)
- Scan & Monitor → Audit Logging: records events (evidence: `README.md`)
- Scan & Monitor → Order Blocks: includes detection
- Scan & Monitor → Fair Value Gaps: includes detection
- Scan & Monitor → Trendlines: includes detection
