Your Ultimate Bridge Between Pythonโs Analytical Power and MetaTrader 5โs Execution Engine
Welcome to MetaTrader Bridge Pro โ a next-generation, open-source connector that transforms how algorithmic traders, quantitative analysts, and fintech developers interact with MetaTrader 5. Think of it as a diplomatic envoy between two powerful nations: Python (the land of data science) and MQL5 (the kingdom of forex execution). No more clunky APIs, no more manual file dragging, no more middleware that costs an arm and a leg. Just pure, encrypted, file-based communication that is fast, secure, and utterly reliable.
This repository is a complete reimagination of the original file-based connector concept. While inspired by the classic Python-to-MQL5 bridge, this version is rebuilt from the ground up with enterprise-grade reliability, zero-touch automation, and AI-ready integration. Whether you are backtesting a neural network or running a live scalping bot, this bridge ensures your signals flow like water through a well-piped system.
In the world of automated trading, the gap between strategy development (Python/R) and strategy execution (MetaTrader) is a canyon. Many traders resort to clunky DLL calls, expensive VPS middleware, or fragile web APIs. This repository offers a third path: a high-performance, file-based protocol that is:
- Latency-optimized for sub-second order placement.
- Encryption-aware using AES-256 for sensitive trading parameters.
- Cross-platform โ works on Windows, Linux, and macOS (via Wine or native MT5 builds).
- Multi-asset โ supports forex, indices, commodities, and custom symbols.
Instead of relying on a central server, the bridge uses a shared filesystem namespace โ a concept borrowed from distributed systems like Apache Kafka but simplified for the trading desk. Each file is a message; each directory is a topic. The result? A decoupled architecture where Python and MQL5 never need to be online at the same time.
graph TD
A[Python Client] -->|Write Request| B((File System Bridge))
B -->|Notify via File Watcher| C[MQL5 Server Connector]
C -->|Execute Order| D[MetaTrader 5 Terminal]
D -->|Confirmation| B
B -->|Read Response| A
E[OpenAI / Claude API] -->|AI Signals| A
F[User Config YAML] -->|Strategy Params| A
G[Risk Manager] -->|Dynamic Sizing| C
H[Telegram Bot] -->|Status Updates| A
How it works in plain English:
The Python client writes a trading signal (e.g., BUY EURUSD 0.1 lots) into a structured JSON file inside a watched directory. The MQL5 server connector, using a low-level file watcher (similar to inotify on Linux), detects the new file, reads the order, executes it in MT5, and writes back a confirmation. All this happens without HTTP overhead, without sockets, and without any third-party dependencies beyond Pythonโs standard library and MQL5โs built-in file functions.
| Feature | Description | Status |
|---|---|---|
| Bidirectional Communication | Send orders from Python to MT5; receive confirmations, balances, and market data back. | โ Stable |
| AES-256 Encryption | All trading files are encrypted at rest and in transit (via filesystem permissions). | โ Stable |
| Multi-Timeframe Sync | Request OHLCV data for any symbol and any timeframe. | โ Stable |
| AI Integration (OpenAI & Claude) | Plug in your favorite LLM to generate trading signals based on natural language prompts. | ๐งช Experimental |
| Responsive UI | Optional web dashboard built with Gradio for real-time monitoring. | ๐งช Beta |
| 24/7 Watchdog | Auto-restart mechanism for both Python and MQL5 components. | โ Stable |
| Multilingual Logging | Logs available in English, Spanish, Chinese, and Arabic. | โ Stable |
| Risk Management Layer | Built-in position sizing, max drawdown, and daily loss limits. | โ Stable |
The bridge is designed to be system-agnostic. Here is the official compatibility matrix:
| Operating System | Python Client | MQL5 Server | Notes |
|---|---|---|---|
| ๐ข Windows 10/11 | โ Full Support | โ Native | Recommended for production |
| ๐ข Windows Server 2019+ | โ Full Support | โ Native | Ideal for VPS environments |
| ๐ก macOS (Intel) | โ Full Support | Limited to backtesting | |
| ๐ก macOS (Apple Silicon) | โ Full Support | โ Not available | Use remote MT5 VPS |
| ๐ Linux (Ubuntu 22.04+) | โ Full Support | Requires Xvfb | |
| ๐ Linux (Debian) | โ Full Support | Community patches available |
Emoji Legend:
โ
= Fully Tested (2026 certified)
โ = Not supported
- Download the latest release from the link above.
- Extract the archive into your
MetaTrader 5\MQL5\Experts\directory. - Install the Python package:
pip install metatrader-bridge-pro
- Edit the configuration file (see example below).
- Run the Python client:
python bridge_client.py --config my_config.yaml
- In MT5, attach the expert advisor
BridgeServer.ex5to any chart (preferably on a 1-minute timeframe for lowest latency).
Below is a sample bridge_config.yaml that illustrates the full power of the bridge. Notice the AI integration and risk management sections:
# MetaTrader Bridge Pro - Configuration Profile
# Version: 2026.1.0
bridge:
mode: "production"
file_watch_directory: "C:/Users/Trader/AppData/Roaming/MetaQuotes/Terminal/Common/Files"
encryption_key: "${ENV:BridgeEncryptionKey}" # Use env variables, never hardcode
max_file_age_seconds: 30
watchdog_interval: 5
ai_agents:
openai:
model: "gpt-4-turbo"
api_key: "${ENV:OpenAIKey}"
prompt_template: "Analyze the latest {symbol} data and suggest a trade with rationale."
max_suggestions_per_minute: 5
claude:
model: "claude-3-opus-20240229"
api_key: "${ENV:AnthropicKey}"
usage: "sentiment_analysis"
confidence_threshold: 0.75
risk_management:
max_position_size: 1.0 # in lots
max_daily_drawdown: 0.05 # 5%
max_trades_per_symbol: 3
stop_loss_atr_multiplier: 2.0
take_profit_risk_reward: 1.5
multilingual:
logging_language: "en" # Options: en, es, zh, ar
timezone: "UTC"
telegram_notifications:
enabled: true
bot_token: "${ENV:TelegramBotToken}"
chat_id: "1234567890"
notify_on: ["open_trade", "close_trade", "error", "stop_loss"]
responsive_ui:
enabled: true
port: 7860
dark_mode: true
refresh_rate_seconds: 2Start a live trading session with AI assistance and password-less login using environment variables:
# Ensure your keys are set
export BridgeEncryptionKey="your-secure-key-here"
export OpenAIKey="sk-..."
export AnthropicKey="sk-ant-..."
# Launch the bridge with verbose logging and AI analysis
python main.py \
--config ./my_config.yaml \
--symbols "EURUSD,GBPUSD,XAUUSD,BTCUSD" \
--timeframes "M1,M5,H1,D1" \
--ai-mode "openai+claude" \
--risk-profile "conservative" \
--log-level DEBUG \
--ui-port 7860Expected output:
[Bridge Pro] 2026-01-15 09:30:01 - Server connector initialized (MT5 build 4000+)
[Bridge Pro] 2026-01-15 09:30:02 - Watching directory: /shared/mt5_bridge/
[Bridge Pro] 2026-01-15 09:30:03 - AI Agent (OpenAI) loaded. Suggestion limit: 5/min
[Bridge Pro] 2026-01-15 09:30:05 - [TRADE] BUY EURUSD 0.1 lots @ 1.1045 โ Order sent to MT5
[Bridge Pro] 2026-01-15 09:30:06 - [CONFIRM] Order #123456 executed. Open price: 1.1047
[Bridge Pro] 2026-01-15 09:30:07 - Dashboard available at http://localhost:7860
In 2026, a trading bridge without artificial intelligence is like a car without a steering wheel. This bridge supports two major AI ecosystems:
- Use case: Generate trade ideas from natural language prompts.
- Example: "Based on the last 100 candles of EURUSD on the M5 timeframe, suggest a trade entry with stop loss and take profit."
- Security: API keys are never stored in plain text; use environment variables or a vault.
- Use case: Sentiment analysis and narrative reasoning.
- Example: Analyze central bank statements or news headlines to gauge market direction.
- Edge: Claudeโs long-context window allows it to ingest days of market data in a single prompt.
Both agents can run simultaneously โ use OpenAI for technical analysis and Claude for fundamental analysis. Results are fused into a single trading decision using a simple voting mechanism (configurable via the YAML).
We take security as seriously as a central bank. All trading files are encrypted using AES-256-GCM before being written to the filesystem. This means:
- Even if an attacker gains access to the shared directory, they cannot read your trading signals.
- The encryption key is derived from a master password combined with a unique file nonce.
- Keys are never logged or transmitted.
Additionally, the bridge supports filesystem permission hardening on Linux and macOS, ensuring only the Python process and the MT5 process (under Wine or native) can access the bridge directory.
- Zero Server Dependency โ Unlike web-based bridges, there is no third-party server that can go down or be hacked. Your trading infrastructure is fully under your control.
- Sub-Millisecond Latency โ File writes and reads are faster than any HTTP request. For high-frequency strategies, this matters.
- Unlimited Scalability โ Run multiple Python clients and multiple MT5 terminals on the same machine, all sharing the same filesystem.
- Offline Operation โ No internet? No problem. The bridge works purely on the local filesystem. Internet is only needed for AI queries.
- Auditable โ Every trade is stored as a timestamped JSON file. Build your own compliance audit trail.
The bridge automatically detects your system locale and offers logs and error messages in:
- English (default)
- Spanish (latam)
- Mandarin Chinese (simplified)
- Arabic (MSA)
Even the AI prompts can be configured to generate responses in your native language. This makes the bridge ideal for international trading desks and prop firms with diverse teams.
The bridge includes a watchdog module that runs as a background daemon. It monitors:
- Whether the MT5 terminal is alive (via process list).
- Whether the filesystem watch is still active.
- Whether any stale files need to be cleaned up (configurable).
If any component fails, the watchdog automatically restarts it within 5 seconds. This means the bridge is truly 24/7 โ you can run it for months without human intervention.
IMPORTANT LEGAL AND RISK DISCLAIMER
Trading foreign exchange, cryptocurrencies, indices, and other financial instruments carries a high level of risk and may not be suitable for all investors. The MetaTrader Bridge Pro software is provided as a technological tool designed to facilitate automated trading between Python and MetaTrader 5. It does not constitute financial advice, investment recommendations, or any form of solicitation to trade.
- Past performance of any strategy or backtest does not guarantee future results.
- You are solely responsible for any financial losses incurred while using this bridge.
- The authors and contributors of this repository shall not be held liable for any direct, indirect, incidental, or consequential damages arising from the use of this software.
- Always use a demo account for initial testing and deployment.
- Consult with a qualified financial advisor before engaging in live trading.
By downloading or using this software, you acknowledge that you have read, understood, and agree to these terms. Trading is a high-risk activity; never risk more than you can afford to lose.
This project is licensed under the MIT License โ a permissive open-source license that allows free use, modification, and distribution, provided that the original copyright notice is included.
You can view the full license text here: https://opensource.org/licenses/MIT
Become part of a growing community of algorithmic traders who have liberated their strategies from the constraints of proprietary APIs. Download MetaTrader Bridge Pro today and build the bridge to your financial future.
MetaTrader Bridge Pro โ v2026.1 | Built with โค๏ธ for the open-source trading community