Control MetaTrader 5 directly from Claude: open, close, modify trades, manage pending orders, calculate lot sizes, apply trailing stop and break-even. Use this skill EVERY TIME the user mentions trading, MetaTrader, MT5, forex, opening/closing positions, stop loss, take profit, orders, lots, risk percentage, trailing stop, break-even, or describes a trading strategy to execute. Even if the user doesn't explicitly say "MT5", if they talk about trading currency pairs, indices, commodities, or describe entry/exit rules for the market, this is the right skill.
This skill enables Claude to operate as a trading assistant on MetaTrader 5, executing real operations on the user's account via a local Python library.
mt5-trading/
├── SKILL.md ← This file (instructions for Claude)
├── scripts/
│ ├── mt5_trading.py ← Python library + CLI for MT5
│ ├── mt5_strategy_executor.py ← JSON strategy executor
│ ├── mt5_indicators.py ← Technical indicators (RSI, MACD, BB, ATR, ADX, TEMA...)
│ └── mt5_monitor.py ← Continuous monitoring with automatic rules
└── references/
├── strategy_format.md ← JSON strategy format
└── monitor_rules.md ← Monitor rules documentation
MetaTrader5 package:
pip install MetaTrader5
mt5_trading.py and mt5_strategy_executor.py files copied to the PCIMPORTANT: These scripts run on the user's PC, NOT in Claude's sandbox. Claude generates commands/strategies, the user executes them locally.
mt5_trading.py libraryFor simple and direct operations. Claude provides python mt5_trading.py ... commands.
Examples:
# Connect
python mt5_trading.py connect
# View account
python mt5_trading.py account
# Buy 0.1 lots EURUSD with SL and TP
python mt5_trading.py buy EURUSD 0.1 --sl 1.0800 --tp 1.1000 --magic 1001
# Close position
python mt5_trading.py close 123456
# Trailing stop
python mt5_trading.py trailing 123456 200
# Calculate lot for 1% risk with 300-point SL
python mt5_trading.py lot_size EURUSD 1.0 300
For complex multi-step operations. Claude generates a JSON and provides the command
to execute it via mt5_strategy_executor.py.
# Save the JSON to a file
# Then execute:
python mt5_strategy_executor.py strategy.json
# Or inline:
python mt5_strategy_executor.py --inline '{ "actions": [...] }'
For the complete JSON format, see: references/strategy_format.md
Claude must ALWAYS consider risk:
When the user describes a strategy in natural language, Claude must:
User: "I want to buy EURUSD if it breaks 1.1000, with a 30-pip stop and 60-pip target. Risk 1% of the account."
Claude should:
python mt5_trading.py lot_size EURUSD 1.0 300
python mt5_trading.py pending_order EURUSD BUY_STOP [LOT] 1.1000 --sl 1.0970 --tp 1.1060 --magic 1001 --comment "breakout_long"
| Command | Description |
|---|---|
connect | Connect to MT5 |
disconnect | Disconnect |
account | Account info (balance, equity, margin) |
symbol EURUSD | Symbol info (spread, digits, volumes) |
tick EURUSD | Latest bid/ask price |
ohlc EURUSD --timeframe H1 --count 20 | OHLC candles |
positions | Open positions |
pending | Pending orders |
buy EURUSD 0.1 --sl X --tp Y | Market BUY order |
sell EURUSD 0.1 --sl X --tp Y | Market SELL order |
pending_order EURUSD BUY_LIMIT 0.1 1.0850 --sl X --tp Y | Pending order |
close 123456 | Close position (full) |
close 123456 --volume 0.05 | Partial close |
close_all | Close all |
close_all --symbol EURUSD | Close all for symbol |
cancel 789012 | Cancel pending order |
cancel_all | Cancel all pending |
modify 123456 --sl 1.0850 --tp 1.1050 | Modify SL/TP |
modify_pending 789012 --price 1.0840 | Modify pending order |
trailing 123456 200 | Trailing stop (200 points) |
breakeven 123456 --offset 10 | Move SL to break-even |
lot_size EURUSD 1.0 300 | Calculate lot (1% risk, 300pt SL) |
Every command outputs the result in JSON. Always prefix with:
python mt5_trading.py <command>
symbol_info| Error | Cause | Solution |
|---|---|---|
MT5 not initialized | Terminal not started | python mt5_trading.py connect |
Symbol not found | Symbol unavailable | Check exact name with broker |
Invalid volume | Lot out of range | Check limits with symbol_info |
Order rejected [10013] | Market closed | Check trading hours |
Order rejected [10016] | Invalid SL/TP | SL/TP too close to price |
Insufficient margin | Insufficient funds | Reduce volume or close positions |
The mt5_indicators.py script provides technical indicators calculated directly on MT5 data.
Claude should use it BEFORE suggesting trades, to support decisions with objective data.
# Full analysis (all indicators + signals + bias)
python mt5_indicators.py EURUSD --analysis
# Specific indicators
python mt5_indicators.py EURUSD --indicators rsi macd bbands atr
# Daily pivot points
python mt5_indicators.py EURUSD --pivots classic
python mt5_indicators.py EURUSD --pivots fibonacci
python mt5_indicators.py EURUSD --pivots camarilla
# Different timeframe
python mt5_indicators.py XAUUSD --analysis --timeframe M15
| Indicator | CLI Key | Output |
|---|---|---|
| SMA (20, 50, 200) | sma | Simple moving averages |
| EMA (12, 26) | ema | Exponential moving averages |
| TEMA (20) | tema | Triple EMA — low-lag trend filter |
| RSI (14) | rsi | Relative strength index (0-100) |
| MACD (12,26,9) | macd | Line, signal, histogram |
| Bollinger Bands (20,2) | bbands | Upper, middle, lower |
| ATR (14) | atr | Average volatility |
| Stochastic (14,3) | stoch | %K and %D (0-100) |
| ADX (14) | adx | Trend strength + DI+/DI- |
| Pivot Points | --pivots | Classic, Fibonacci, Camarilla |
The --analysis output includes an overall_bias field (BULLISH / BEARISH / NEUTRAL) and
a signals list with each indicator and its signal. Claude should:
Example workflow for Claude:
python mt5_indicators.py EURUSD --analysisThe mt5_monitor.py script runs in a loop on the user's PC and applies automatic rules.
Claude generates the JSON configuration, the user executes it.
# Generate an example config
python mt5_monitor.py --generate-config
# Start the monitor
python mt5_monitor.py mt5_monitor_config.json
# Simulation mode (doesn't execute real actions)
python mt5_monitor.py mt5_monitor_config.json --dry-run
# Override interval
python mt5_monitor.py mt5_monitor_config.json --interval 10
| Type | Description |
|---|---|
trailing_stop | Automatic trailing stop on profitable positions |
breakeven | Move SL to break-even when profit exceeds a threshold |
price_alert | Notify when price crosses above/below a level |
close_on_profit | Close position when target profit is reached (currency) |
close_on_loss | Close position when loss exceeds a limit (currency) |
close_on_time | Close positions after a specified time (HH:MM) |
indicator_alert | Alerts based on indicators (RSI, MACD cross, Bollinger breakout) |
tema_price_cross | Open trade on TEMA/price crossover (auto close opposite) |
max_drawdown | Close ALL if account drawdown exceeds a percentage |
When the user describes automatic management rules, Claude should:
--dry-run for the first testmax_drawdown rule as protectionExample:
{
"interval_seconds": 30,
"log_file": "mt5_monitor_log.json",
"rules": [
{
"name": "Descriptive name",
"type": "trailing_stop",
"enabled": true,
"trail_points": 200,
"symbol": "EURUSD"
}
]
}
For the complete rules documentation, see: references/monitor_rules.md
The price_alert and indicator_alert rules can include an action to execute
automatically when the alert triggers:
{
"type": "price_alert",
"symbol": "EURUSD",
"level": 1.1000,
"direction": "above",
"notify_desktop": true,
"action": {
"action": "buy",
"symbol": "EURUSD",
"volume": 0.1,
"sl": 1.0970,
"tp": 1.1060
}
}
The tema_price_cross rule opens trades automatically on TEMA/price crossovers:
{
"type": "tema_price_cross",
"symbol": "EURUSD",
"timeframe": "H1",
"tema_period": 20,
"volume": 0.01,
"sl_points": 200,
"tp_points": 400,
"magic": 1001,
"close_opposite": true,
"comment": "tema_cross_h1"
}
close_opposite: true closes existing opposite positions before openingWhen the user asks for a trade or strategy, Claude follows this flow:
python mt5_indicators.py SYMBOL --analysispython mt5_trading.py account (for balance and margin)python mt5_trading.py lot_size SYMBOL RISK SL_POINTSmt5_monitor_log.json that can be checked at any timeCtrl+C to stop the monitor cleanly