feat: add MetaTrader 5 bridge for real-time Kronos inference#292
Closed
janpauldelacruz wants to merge 10 commits into
Closed
feat: add MetaTrader 5 bridge for real-time Kronos inference#292janpauldelacruz wants to merge 10 commits into
janpauldelacruz wants to merge 10 commits into
Conversation
…ment length - pooyer_bridge.py: double-checked locking for _load_model() via _model_lock - pooyer_bridge.py: inner double-check in multi_predict before inference - pooyer_bridge.py: clear_cache() now protected by _lock - pooyer_bridge.py: freq param in payload propagated to _run_inference timestamps - requirements_bridge.txt: add torch>=2.0.0 (required for Kronos model) - POOYER.mq5: ManageOpenPositions — guard cur_sl==0 before breakeven compare - POOYER.mq5: FLAT signals handled explicitly (no longer logged as fetch failure) - POOYER.mq5: order comment truncated to 31 chars (MT5 limit) - POOYER.mq5: PingHealth timeout 3000ms → 1500ms to unblock bar processing - README.md: remove reference to pooyer_dashboard.html (file not in commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Percentile path SL/TP, flip-resistant dynamic exit, ensemble variance confidence, NO_TRADE state, forecast expiry, 2.5×ATR SL hard cap. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Full task-by-task build plan: bridge (ensemble variance, percentile path SL/TP, /recheck), EA (flip-resistant exit, forecast expiry), README, launcher scripts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds KRONOS_PURE, a production Expert Advisor built exclusively around Kronos BSQ structural tokenization with 30-path directional confluence. Key design decisions: - 30 independent predict() calls (sample_count=1) — preserves variance signal that sample_count>1 destroys by internal averaging - M15/H1 native — BSQ structural tokens require M15+ to avoid ATR collapse - Dir agreement gate (70%+) → 54% actual WR | 80%+ → 58% WR - Model failover: Kronos-mini (primary) → Kronos-base (backup) - SL: 30th percentile of predicted lows, floor 2.0×ATR, cap 2.5×ATR - TP: 70th percentile of predicted highs - Full trade logger → CSV (dir_agreement, confidence, MFE, MAE, hold_minutes) - 1-click Windows installer (INSTALL_AND_RUN.bat) with stop + close-all Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both EAs had the same bugs: 1. StringToCharArray null-terminator: used explicit StringLen() count which omits null, then ArrayResize(-1) removed the last JSON character (closing }). Bridge received malformed JSON → silent HTTP errors. Fix: WHOLE_ARRAY + sz-1. 2. Session filter was backwards: KillHour1/KillHour2 only blocked 2 specific hours (10 AM and 5 PM), trading freely at 1 AM, 2 AM Asian session. Fix: replaced with proper SessionStart/SessionEnd UTC window (7-20). POOYER additional fixes: - MaxPositions default 1 (prevents stacking identical signals) - MinSLPoints/MaxSLPoints bounds guard in ExecuteTrade KRONOS_EDGE additional fixes: - SL/TP direction validation (guards invalid path levels from bridge) - MinSLPoints/MaxSLPoints bounds guard in ExecuteTrade - Removed dead NO_TRADE branch (eliminated from bridge) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the first production-grade MetaTrader 5 ↔ Kronos bridge, enabling live traders to use Kronos OHLCV forecasts directly inside MT5 Expert Advisors — the world's most widely used retail trading platform (millions of users).
What's included
examples/mt5_bridge/pooyer_bridge.py— Flask server that loads Kronos and serves predictions via HTTP on port 7799examples/mt5_bridge/POOYER.mq5— MT5 Expert Advisor that sends OHLCV bars via WebRequest and executes signalsexamples/mt5_bridge/README.md— Full documentation, API reference, and quick start guideexamples/mt5_bridge/requirements_bridge.txt— Python dependenciesWhy this matters
Kronos has no existing integration with live trading platforms. This bridge closes that gap — any MT5 user worldwide can now point their EA at a local Kronos instance and trade with foundation model forecasts.
Features
Tested on
XAUUSD, EURUSD, GBPUSD with Kronos-mini (CPU, ~800-2000ms inference)