A community-driven registry for Claude, Cursor, Windsurf, Cline & more. Not affiliated with Anthropic.
Are you the author? Sign in to claim
🤖 AI-Agent Friendly MT5 Expert Advisor with intelligent order splitting, automatic trailing stops, and REST API. Perfec
🤖 AI-Agent Friendly | Professional-grade MetaTrader 5 Expert Advisor with intelligent order splitting, automatic trailing stop loss, and REST API integration for Gold (XAUUSD) and Silver (XAGUSD) trading. Built for seamless integration with Claude AI and other AI agents.
This system is designed for seamless integration with AI agents like Claude AI, ChatGPT, and other LLMs:
Example AI Agent Workflow:
User: "Buy Gold at 4100 with 30-pip TPs"
AI Agent: Parses signal → Calls REST API → Monitors response
System: Splits order → Manages positions → Returns status
pip install -r requirements.txt
python server.py
The server will start on:
bulk-add-signals.mq5 (F7)curl -X POST http://localhost:8080/order \
-H "Content-Type: application/json" \
-d '{
"symbol": "XAUUSD",
"order_type": "BUY_STOP",
"price": 4100.0,
"sl": 4096.0,
"tp_levels": [4103.0, 4106.0, 4109.0, 4112.0, 4115.0],
"lot_size": 0.1
}'
┌─────────────┐ REST API ┌──────────────┐ TCP Socket ┌─────────────┐
│ External │ ─────────────────> │ Python │ ──────────────────> │ MT5 EA │
│ Client │ POST /order │ FastAPI + │ JSON Commands │ (Client) │
│ (Claude AI)│ │ TCP Server │ │ │
└─────────────┘ <───────────────── └──────────────┘ <────────────────── └─────────────┘
JSON Response :5555 Response Execute
(ticket #) Queue Trade
Traditional single-TP orders force you to choose between:
Solution: Split one order into 5 positions with different TPs!
When you place 0.1 lot, the EA creates 5 separate orders:
| Order | Volume | % of Total | Take Profit | Purpose |
|---|---|---|---|---|
| TP1 | 0.06 | 60% | 15 pips | Secure majority profit quickly |
| TP2 | 0.01 | 10% | 45 pips | Trailing SL trigger point |
| TP3 | 0.01 | 10% | 75 pips | Medium-term profit |
| TP4 | 0.01 | 10% | 105 pips | Extended profit |
| TP5 | 0.01 | 10% | 135 pips | Maximum profit target |
Option 1: Standard Structure (15-pip initial)
Option 2: Aggressive Structure (30-pip initial)
The EA automatically adjusts pip values based on symbol:
When TP2 closes (45 pips profit):
Entry: Sell Stop @ 50.051 (Silver) Initial SL: 50.101 (5 pips above entry)
Trade Progression:
Price drops to 49.901 → TP1 closes (0.06 lots, 60% profit = +15 pips)
Price drops to 49.601 → TP2 closes (0.01 lots, 10% profit = +45 pips)
→ EA MOVES SL to 49.901 for TP3/TP4/TP5
→ Position now RISK-FREE!
Price drops to 49.301 → TP3 closes (0.01 lots, protected, +75 pips)
Price drops to 49.001 → TP4 closes (0.01 lots, protected, +105 pips)
Price drops to 48.701 → TP5 closes (0.01 lots, protected, +135 pips)
If price reverses after TP2:
When you close MT5 and the EA stops running:
Before closing MT5, activate safe shutdown mode:
curl -X POST http://localhost:8080/safe-shutdown
Before Safe Shutdown:
TP1: 15 pips (0.06 lots, 60%)
TP2: 45 pips (0.01 lots, 10%)
TP3: 75 pips (0.01 lots, 10%)
TP4: 105 pips (0.01 lots, 10%)
TP5: 135 pips (0.01 lots, 10%)
After Safe Shutdown:
TP1: 15 pips (0.06 lots, 60%) ← unchanged
TP2: 45 pips (0.01 lots, 10%)
TP3: 45 pips (0.01 lots, 10%) ← moved to TP2!
TP4: 45 pips (0.01 lots, 10%) ← moved to TP2!
TP5: 45 pips (0.01 lots, 10%) ← moved to TP2!
✅ All remaining positions (40%) will close at maximum 45 pips ✅ No manual monitoring needed while away ✅ Safe to close MT5 and sleep/leave ✅ Guarantees minimum profit even if EA is offline
{
"success": true,
"message": "Safe shutdown applied",
"groups_modified": 3,
"pending_orders_modified": 12,
"open_positions_modified": 8,
"details": [
{"group": "XAUUSD_4065.000_1234567890", "modified": 4},
{"group": "XAUUSD_4053.000_1234567891", "modified": 4},
{"group": "XAUUSD_4012.000_1234567892", "modified": 4}
]
}
http://localhost:8080
GET /health
Check if server is running.
Response:
{
"status": "healthy",
"tcp_host": "127.0.0.1",
"tcp_port": 5555
}
POST /order
Place a new order with automatic splitting.
Request Body:
{
"symbol": "XAUUSD",
"order_type": "BUY_STOP",
"price": 4100.0,
"sl": 4096.0,
"tp_levels": [4103.0, 4106.0, 4109.0, 4112.0, 4115.0],
"lot_size": 0.1,
"deviation": 3,
"comment": "My Trade",
"magic_number": 20250117
}
Parameters:
symbol (string): Trading symbol ("XAUUSD" or "XAGUSD")order_type (string): "BUY_STOP" or "SELL_STOP"price (float): Entry pricesl (float): Stop loss pricetp_levels (array): 5 take profit levelslot_size (float): Total volume (will be split into 5 orders)deviation (int, optional): Maximum price deviation in pipscomment (string, optional): Order commentmagic_number (int, optional): Magic number for identificationResponse:
{
"success": true,
"message": "Order placed successfully",
"ticket": 171645717
}
GET /positions
Get all open positions.
Response:
{
"success": true,
"positions": [
{
"ticket": 123456,
"symbol": "XAUUSD",
"type": "BUY",
"volume": 0.06,
"price_open": 4100.0,
"sl": 4096.0,
"tp": 4103.0,
"profit": 18.50
}
]
}
GET /orders
Get all pending orders.
Response:
{
"success": true,
"orders": [
{
"ticket": 171645717,
"symbol": "XAUUSD",
"type": "BUY_STOP",
"volume": 0.06,
"price": 4100.0,
"sl": 4096.0,
"tp": 4103.0
}
]
}
DELETE /order/{ticket}
Cancel a pending order.
Response:
{
"success": true,
"message": "Order deleted",
"ticket": 171645717
}
DELETE /position/{ticket}
Close an open position.
Response:
{
"success": true,
"message": "Position closed",
"ticket": 123456
}
GET /stats
Get account statistics and EA status.
Response:
{
"success": true,
"stats": {
"balance": 10000.00,
"equity": 10050.00,
"margin": 500.00,
"free_margin": 9550.00,
"profit": 50.00,
"total_positions": 5,
"total_orders": 15,
"tracked_groups": 3,
"magic_number": 20250117
}
}
POST /safe-shutdown
Activate safe shutdown mode - consolidate all TPs to TP2 level.
Response:
{
"success": true,
"message": "Safe shutdown applied",
"groups_modified": 3,
"pending_orders_modified": 12,
"open_positions_modified": 8
}
{
"mt5": {
"zmq_port": 5555,
"default_lot_size": 0.1
},
"symbols": {
"gold": "XAUUSD",
"silver": "XAGUSD"
},
"risk_management": {
"max_daily_loss_percent": 5.0,
"max_positions": 10
}
}
Configure in MT5 when attaching EA to chart:
| Parameter | Default | Description |
|---|---|---|
ServerHost | "127.0.0.1" | Python server IP address |
ServerPort | 5555 | TCP server port |
MagicNumber | 20250117 | Unique identifier for EA orders |
SocketCheckIntervalMs | 500 | How often to check for commands (ms) |
MaxSpreadPips | 10 | Maximum allowed spread in pips |
MaxDailyLossPercent | 5.0 | Stop trading if daily loss exceeds % |
git clone https://github.com/yourusername/mt5-bulk-order-manager.git
cd mt5-bulk-order-manager
pip install -r requirements.txt
cp bulk-add-signals.mq5 "~/MetaTrader 5/MQL5/Experts/"
python server.py
docker-compose up -d
The server will be available at http://localhost:8080
curl -X POST http://localhost:8080/order \
-H "Content-Type: application/json" \
-d '{
"symbol": "XAUUSD",
"order_type": "BUY_STOP",
"price": 4100.0,
"sl": 4096.0,
"tp_levels": [4103.0, 4106.0, 4109.0, 4112.0, 4115.0],
"lot_size": 0.1
}'
This creates 5 orders:
curl -X POST http://localhost:8080/order \
-H "Content-Type: application/json" \
-d '{
"symbol": "XAGUSD",
"order_type": "SELL_STOP",
"price": 29.50,
"sl": 29.65,
"tp_levels": [29.35, 29.05, 28.75, 28.45, 28.15],
"lot_size": 0.5
}'
curl http://localhost:8080/positions
curl -X POST http://localhost:8080/safe-shutdown
Symptoms: EA shows "Not connected" in Experts tab
Solutions:
curl http://localhost:8080/healthnetstat -an | grep 5555Symptoms: All split orders fail immediately
Cause: Order type doesn't match price position relative to market
Solution: The EA now auto-detects and converts:
Recompile the EA with the latest code.
Symptoms: Server fails to start with "Address already in use"
Solution:
# Find and kill process using port 8080
lsof -ti:8080 | xargs kill -9
# Find and kill process using port 5555
lsof -ti:5555 | xargs kill -9
# Restart server
python server.py
Symptoms: TP2 closes but SL doesn't move to TP1
Possible Causes:
Solution:
Symptoms: Command succeeds but TPs not modified
Cause: EA not compiled with latest code
Solution:
Q: Can I use this with other symbols besides Gold and Silver?
A: The code is optimized for XAUUSD and XAGUSD pip values. For other symbols, you'll need to adjust the pipValue calculation in the MQL5 code.
Q: What happens if I restart MT5 while positions are open? A: The EA has position recovery logic that rebuilds order group tracking from position comments. However, trailing SL won't trigger during the restart period.
Q: Can I change the volume distribution (60/10/10/10/10)?
A: Yes, edit the volumes[] array in the ExecuteOrder() function in bulk-add-signals.mq5.
Q: Does this work on MT4? A: No, this is specifically designed for MT5. MT4 uses a different API and doesn't support the same socket operations.
Q: Can I run multiple EAs with different magic numbers? A: Yes, each EA instance can have a unique magic number. Configure it in the EA input parameters.
Q: Is there a web interface? A: Currently, the system uses a REST API. You can build a web frontend that calls the API endpoints.
Q: How do I backtest this EA? A: The EA uses socket communication which isn't available in Strategy Tester. For backtesting, you'd need to modify the code to use simulated data instead of TCP sockets.
Q: What's the minimum lot size? A: Depends on your broker. Since orders are split into 0.01 lot increments, your broker must support 0.01 lots (micro lots).
MIT License - see LICENSE file for details
Contributions welcome! Please:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This software is for educational purposes only. Trading forex and CFDs involves substantial risk of loss. Past performance is not indicative of future results. Always test on a demo account first.
Made with ❤️ for algorithmic traders
Keywords: MetaTrader 5, MT5, Expert Advisor, EA, Gold Trading, XAUUSD, Silver Trading, XAGUSD, Forex Bot, Trading Bot, Algorithmic Trading, Automated Trading, Split Orders, Trailing Stop, Risk Management, FastAPI, Python Trading, MQL5, Trading API, REST API, Socket Trading
Native macOS app to monitor Claude AI usage limits and watch your coding sessions live
npx CLI installing 100+ agents, commands, hooks, and integrations in one command
干净、强大、属于你的 AI Agent 平台 --AI agents, without the clutter.
Pocket Flow: Codebase to Tutorial