MT4 trading system with a Python dashboard, named-pipe DLL bridge, and customer-specific SMC / ICT market structure logic.
ZONES is a hybrid MT4 + Python trading application built around customer-defined market structure rules.
Current foundation in this repo includes:
- ZigZag-driven
Temp Zones - Fractal-promoted
Main Zones S1 / S2 / S3main-zone strength classesHH / LH / LL / HL / EQHH / EQLLstructure labelingBOS,CHOC, andRRRevent flow- candle-body buy/sell mode logic
- support, resistance, and liquidity mapping
- multi-timeframe analysis for
1H,5M, and1M - browser dashboard with structured route views
- browser candle terminal with ZONES overlays filtered by selected symbol and timeframe
- TradingView Advanced Chart page with live symbol switching, public drawing tools, and ZONES projection overlays
- browser backtesting for zone-touch entries with risk, drawdown, R-multiple, and trade-list metrics
- hedge fund style portfolio analysis with exposure, leverage, concentration, VaR proxy, and PnL attribution metrics
- system status page for runtime settings, remote DB control, AI training, and feedback capture
- editable allowed-session control on the system page for the execution gate
- local MT4 bridge using a localhost WebSocket as the primary transport, with the named-pipe path kept for legacy compatibility
- local SQLite by default, with optional remote PostgreSQL support
The repo currently uses this flow:
MT4 EAcollects candles, account data, and symbol context.ZONES.mq4sends requests through the local WebSocket bridge, while the named-pipe server remains available for legacy clients.zones.pyruns the Python service and dashboard.supply_demand_eaanalyzes structure, zones, execution filters, and phase outputs.- The dashboard renders readable HTML views for live monitoring.
- The MT4 chart fetches the latest analyzed overlay from Python, so chart zones and backend decisions come from the same ZigZag / Fractal report.
Key files:
- Python entrypoint:
zones.py - Engine:
supply_demand_ea/analysis.py - Browser dashboard:
supply_demand_ea/dashboard.py - Live bridge service:
supply_demand_ea/bridge.py - Pipe server:
supply_demand_ea/ipc.py - MT4 EA:
MQL4/Experts/Zones/Zones.mq4 - MT4 include:
MQL4/Include/ZonesBridge.mqh - DLL source:
bridge_dll/ZonesBridgeDll.cpp - Prebuilt x86 debug DLL:
bridge_dll/bin/x86/Debug/ZonesBridge.dll - PDF rulebook summary:
docs/zones_pdf_rulebook.md
The Python engine has been refactored around the provided PDF requirements and now models:
- temp-zone creation from ZigZag structure points
- main-zone promotion from Fractal confirmation
- discrete main-zone strengths instead of generic scores only
- body-based zone mode detection
CHOCdeletion of unconfirmed temp zonesRRRstages:respect,reject,retest,close_confirm- structural invalidation language and structural trailing references
- MT4 chart rendering from the same analyzed ZigZag / Fractal overlay that powers the browser dashboard
Supporting docs:
docs/mt4-python-architecture.mddocs/zones_pdf_rulebook.mddocs/supply_demand_ea_phase1.mddocs/live_mt4_bridge.mddocs/mt4_dll_bridge.mddocs/chart_terminal.mddocs/backtesting.mddocs/runtime_settings.mddocs/installation_package.mddocs/INSTALL.mddocs/RELEASE.mddocs/TROUBLESHOOTING.mddocs/GITHUB_RELEASE_CHECKLIST.md
Start the Python service:
python zones.pyOpen the browser dashboard:
http://127.0.0.1:8787
Useful routes:
//chart/backtest/portfolio/systemPOST /api/ingest/api/analysis/api/reports/api/symbols/api/commands/api/backtest/api/portfolio/api/health/api/schema/api/system/status/api/chart
Browser routes render structured HTML by default.
For raw JSON, add:
?format=json
Live MT4 or bridge clients can post JSON snapshots directly to:
http://127.0.0.1:8787/api/ingest
Open the chart page:
http://127.0.0.1:8787/chart
What it includes:
- local ZONES candle terminal rendered from the app payload
- supply, demand, support, and resistance overlays drawn directly on the candles
- candlestick chart for live or waiting candle data
- TradingView Advanced Chart widget as the main browser chart surface
- drawn zone overlays from the ZONES engine
- tracked-symbol and custom-symbol switching on the chart page
- TradingView symbol override input for provider-specific symbols like
FX:EURUSDorOANDA:XAUUSD - timeframe switching for available feeds
- pending command queue view
- execution history view
- browser form that queues MT4 commands through the existing DLL bridge flow
- auto-filled entry, SL, and TP from the current setup, with manual adjustment before queueing
- basic validation so empty lot, price, ticket, or alert message inputs are rejected before hitting MT4
Symbol workflow:
- Start
python zones.py. - Open
http://127.0.0.1:8787/chart. - Use
Tracked Symbolto load a symbol already ingested from MT4, or type a custom symbol such asEURUSD. - Pick the timeframe tab shown above the terminal.
- Review the local ZONES candle terminal. The rectangular overlays are the exact zones from the selected symbol payload.
The browser command panel can queue:
market_buymarket_sellbuy_limitsell_limitbuy_stopsell_stopmodify_ticketclose_ticketdelete_ticketclose_allalert
Those commands are picked up by the MT4 EA when it polls the local bridge.
Open:
http://127.0.0.1:8787/backtest
The backtester uses the selected symbol's chart_data and filtered ZONES overlays. It simulates a zone-touch strategy where the signal candle touches an eligible zone and the entry happens at the next candle open.
Metrics include:
- ending balance, net PnL, and return percentage
- win rate, profit factor, expectancy in R, and net R
- max drawdown percentage
- full trade list with entry, stop, target, exit reason, R multiple, and PnL
Raw JSON is available at:
http://127.0.0.1:8787/api/backtest?symbol=EURUSD&timeframe=5M&format=json
Open:
http://127.0.0.1:8787/portfolio
The portfolio page shows hedge fund style metrics from the latest account snapshot:
- NAV and daily return proxy
- gross and net exposure in lots
- long/short lots and long/short ratio
- leverage proxy
- margin level and margin utilization
- concentration risk, HHI concentration, and effective bets
- 95% VaR proxy and 2% stress-loss proxy
- PnL attribution by long and short books
- exposure by symbol
Raw JSON is available at:
http://127.0.0.1:8787/api/portfolio?format=json
For the current local bridge, MT4 uses DLL imports instead of WebRequest.
- Copy
bridge_dll/bin/x86/Debug/ZonesBridge.dllinto your MT4MQL4/Librariesfolder asZonesBridge.dll. - Copy or compile
MQL4/Experts/Zones/Zones.mq4in MetaEditor. - Ensure
MQL4/Include/ZonesBridge.mqhis available. - In MT4, enable
Allow DLL imports. - Start
python zones.py. - Attach the
ZONESEA to a chart.
Notes:
- MT4 must use the
32-bitDLL build. - The Python app should be running before the EA starts posting data.
- The dashboard can ingest all symbols from Market Watch while drawing on the attached chart.
- When
PostAllMarketWatchSymbolsis enabled, the EA now polls command queues across Market Watch symbols too, so browser orders are not limited to the attached chart symbol. - The attached MT4 chart now draws zones, swings, and structure markers from the Python analysis snapshot instead of a second local swing algorithm.
- If you update the DLL source, rebuild the x86 DLL and replace
MQL4/Libraries/ZonesBridge.dllbefore testing in MT4.
The DLL project is in bridge_dll.
Open that folder in VS Code or Visual Studio and build the x86 target.
Helpful files:
bridge_dll/CMakeLists.txtbridge_dll/CMakePresets.jsonbridge_dll/build_msvc.batbridge_dll/build_mingw.batbridge_dll/README.md
Expected output:
bridge_dll/bin/x86/Debug/ZonesBridge.dll
Default database:
SQLite
Default file:
logs/zones.sqlite
Optional remote database:
$env:ZONES_DATABASE_URL = "postgresql://user:password@host:5432/zones"
python zones.pySQLite URLs also work:
$env:ZONES_DATABASE_URL = "sqlite:///C:/path/to/zones.db"The browser system page can also switch the runtime repository without editing environment variables:
- open
/system - paste a SQLite or PostgreSQL URL
- enter the database username and password separately when the URL requires credentials
- save runtime settings
The same /system page also stores Telegram settings:
- paste the Telegram bot token
- send one message to the bot from the Telegram account or group you want to use
- save runtime settings, and ZONES will call Telegram
getUpdatesto discover the chat id automatically - confirm the discovered chat id in the system status card
For chart viewing, /system can store a default chart symbol, and /chart also lets the user select a tracked symbol or type a custom symbol before viewing the ZONES candle terminal.
The same page also exposes live zone sizing controls:
Temp Zone Min ThicknessTemp Zone Max ThicknessMain Zone Min ThicknessMain Zone Max Thickness
ZONES now includes a lightweight trainable signal model for runtime status and signal guidance.
What it does today:
- trains from recorded trade feedback when enough samples exist
- falls back to bootstrap training from stored reports and execution decisions
- scores the latest live report with a current AI signal and confidence
- exposes model state on
/systemand/api/system/status
To use it:
- ingest live MT4 reports or let the app collect reports normally
- open
/system - record feedback rows for wins, losses, and PnL
- click
Train Signal Model
Run the test suite:
python -m unittest discover -s tests -vThe current tests cover:
- multi-timeframe analysis
- live ingest contracts
- named-pipe health and ingest processing
- command queue flow
- browser HTML route rendering
- temp-to-main promotion
RRRstage generation- candle-body mode logic
CHOCdeletion behavior
A few legacy files and folders still exist in the repo from earlier project history, but the current active application path is:
zones.pysupply_demand_ea/MQL4/Experts/Zones/MQL4/Include/bridge_dll/docs/tests/
See LICENSE and LICENSE.md.