Skill
mt5-trading
Comprehensive MetaTrader 5 Python algotrading knowledge base covering the official synchronous API, polling-based event systems, order execution with fill modes, historical data functions, reconnection resilience, and Windows production deployment. Includes aiomql and ZeroMQ bridge alternatives. TRIGGER WHEN: building, optimizing, or debugging MT5 trading systems with Python. DO NOT TRIGGER WHEN: the task is outside the specific scope of this component.
From mt5-tradingInstall
1
Run in your terminal$
npx claudepluginhub acaprino/figtree-plugins --plugin mt5-tradingTool Access
This skill uses the workspace's default tool permissions.
Supporting Assets
View in Repositoryreferences/api-architecture.mdreferences/data-feed-historical.mdreferences/event-system-polling.mdreferences/order-execution.mdreferences/production-resilience.mdSkill Content
MetaTrader 5 Python Algotrading
Knowledge base for building production-grade algorithmic trading systems with MetaTrader 5 Python API.
When to Use
- Connecting to MT5 terminal via the official Python API
- Building polling-based event systems (on_tick, on_new_candle, on_position)
- Executing orders with correct fill modes (FOK, IOC, Return)
- Downloading historical data (copy_rates, copy_ticks)
- Handling MT5 disconnections and terminal restarts
- Deploying MT5 bots on Windows with process monitoring
- Choosing between official API, aiomql, and ZeroMQ bridge
Quick Start
For 80% of use cases, start with:
- Library:
pip install MetaTrader5(official) orpip install aiomql(async wrapper) - Connection:
mt5.initialize(path=..., login=..., server=..., password=...) - Event system: polling loop with candle/tick/position change detection
- Orders:
order_check()beforeorder_send(), always detect fill mode dynamically - Risk: server-side SL/TP on every position (non-negotiable)
- Resilience: health check every 30-60s, psutil process monitoring, exponential backoff
Then harden incrementally:
- Silent errors -- wrap every API call with None check + last_error()
- Fill mode rejections (10030) -- dynamic filling_mode detection per symbol
- Terminal crashes -- psutil watchdog + subprocess restart
- Weekend handling -- datetime.weekday() sleep mode
Reference Materials
api-architecture.md-- MT5 Python API architecture, 32 functions, named pipes IPC, MQL5 EA vs Python, library comparisonevent-system-polling.md-- polling patterns, new candle detection, tick monitoring, position tracking, concurrency rulesorder-execution.md-- order_send, fill modes (FOK/IOC/Return), hedging vs netting, retcodes, risk checks, magic numbersdata-feed-historical.md-- copy_rates, copy_ticks, depth, timezone caveats, caching, data quality, broker differencesproduction-resilience.md-- disconnection handling, reconnection, weekend management, Windows deployment, community resources
Key Decision Points
| Decision | Default | Upgrade When |
|---|---|---|
| Library | Official MetaTrader5 | Need async -- aiomql; need true streaming -- ZeroMQ bridge |
| Event model | Polling (1-5s interval) | Tick-sensitive -- poll 100-250ms; true events -- ZeroMQ EA bridge |
| Fill mode | Detect dynamically per symbol | Never hardcode -- changes between brokers/symbols |
| Account mode | Hedging (most forex brokers) | Check account_info().margin_mode at startup |
| Data caching | Parquet + Zstandard | Tick data -- partition by day/month |
| Concurrency | asyncio (single thread) | Multi-account -- separate processes per terminal |
| Backtesting | Python framework (Backtrader, Backtesting.py) | Need MT5 tester -- MQL5 EA wrapper |
| SL/TP | Server-side always | Python trailing only as supplement, never as sole protection |
Similar Skills
Stats
Parent Repo Stars0
Parent Repo Forks1
Last CommitMar 26, 2026