A fully automated trading system that integrates TradingView alerts with MetaTrader 5 (MT5) using n8n and Docker for real-time execution.
- Real-time execution: Minimal latency between signal generation and trade execution
- Docker-based: Easy deployment and scaling
- Webhook integration: Seamless connection between TradingView and MT5
- Comprehensive logging: Full audit trail of all trading activities
- Health monitoring: Built-in health checks and error handling
- 24/7 operation: Designed for continuous operation on VPS
TradingView β n8n Webhook β MT5 Bridge β MetaTrader 5
β β β β
Strategy Workflow REST API Live Trading
Alerts Processing Service Execution
- TradingView Account with Pine Script strategy
- MetaTrader 5 terminal installed on your VPS
- Docker & Docker Compose installed
- VPS/Server with sufficient resources (2GB RAM minimum)
- Stable internet connection
git clone <your-repo-url>
cd Tradingview2MT5# Copy and edit the environment template
cp mt5-bridge/.env.example mt5-bridge/.env
# Edit the .env file with your MT5 credentials
nano mt5-bridge/.envRequired environment variables:
# MetaTrader 5 Configuration
MT5_LOGIN=your_mt5_login_number
MT5_PASSWORD=your_mt5_password
MT5_SERVER=your_mt5_server
MT5_PATH=/opt/mt5
# Trading Parameters
TRADING_SYMBOL=EURUSD
LOT_SIZE=0.01
MAGIC_NUMBER=123456
# Bridge Service
BRIDGE_PORT=5000
LOG_LEVEL=INFO# Build and start all services
docker-compose up -d --build
# Check if services are running
docker-compose ps
# View logs
docker-compose logs -f- Access n8n at
http://your-vps-ip:5678 - Import the workflow from
n8n-workflows/tradingview-to-mt5-workflow.json - Activate the workflow
- Copy the webhook URL for TradingView alerts
- Open your TradingView chart
- Add the strategy from
tradingview/moving-averages-strategy.pine - Create alerts for "Long Signal" and "Short Signal"
- Set webhook URL to:
http://your-vps-ip:5678/webhook/tradingview-webhook - Set alert frequency to "Once per bar"
| Parameter | Description | Default |
|---|---|---|
period1 |
Fast MA period | 20 |
period2 |
Slow MA period | 50 |
maType1 |
Fast MA type | SMA |
maType2 |
Slow MA type | EMA |
takeProfitPercent |
TP percentage | 2.0% |
stopLossPercent |
SL percentage | 1.0% |
lotSize |
Position size | 0.01 |
symbol |
Trading symbol | EURUSD |
- SMA: Simple Moving Average
- EMA: Exponential Moving Average
- TEMA: Triple Exponential Moving Average
- HMA: Hull Moving Average
- KAMA: Kaufman's Adaptive Moving Average
- ALMA: Arnaud Legoux Moving Average
- FRAMA: Fractal Adaptive Moving Average
- VIDYA: Variable Index Dynamic Average
# Check all services
curl http://localhost:5678/healthz # n8n
curl http://localhost:5000/health # MT5 Bridge# n8n logs
docker-compose logs -f n8n
# MT5 Bridge logs
docker-compose logs -f mt5-bridge
# All logs
docker-compose logs -f# Check current positions
curl http://localhost:5000/positions
# Check account info
curl http://localhost:5000/account
# Check symbol info
curl http://localhost:5000/symbol/EURUSD| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Service health check |
/webhook/tradingview |
POST | Receive TradingView signals |
/positions |
GET | Get current positions |
/account |
GET | Get account information |
/symbol/<symbol> |
GET | Get symbol information |
{
"signal": "BUY|SELL",
"symbol": "EURUSD",
"lot_size": 0.01,
"sl_percent": 1.0,
"tp_percent": 2.0,
"timestamp": "2023-10-30T12:00:00Z"
}# Check MT5 terminal is running
# Verify credentials in .env file
# Check MT5 server connectivity
docker-compose logs mt5-bridge# Verify n8n workflow is active
# Check webhook URL in TradingView alert
# Check n8n logs for incoming requests
docker-compose logs n8n# Check Docker resources
docker system df
# Rebuild services
docker-compose down
docker-compose up -d --build- Ensure strategy is added to chart
- Check alert conditions match strategy signals
- Verify webhook URL is correct
- Test alert with "Test Alert" button
- n8n logs:
docker-compose logs n8n - MT5 Bridge logs:
mt5-bridge/logs/mt5_bridge.log - System logs:
docker-compose logs
-
Network Security:
- Use firewall to restrict access to ports 5678, 5000
- Consider using VPN for remote access
-
API Security:
- Keep MT5 credentials secure
- Use strong passwords
- Regularly rotate API keys if used
-
Trading Security:
- Start with small lot sizes for testing
- Implement proper risk management
- Monitor account balance regularly
- CPU: 2 cores minimum
- RAM: 2GB minimum, 4GB recommended
- Storage: 20GB SSD minimum
- Network: Stable 10Mbps+ connection
- Colocate Services: Run everything on the same VPS
- Network Optimization: Use high-speed internet
- MT5 Settings: Configure MT5 for fastest execution
- Docker Optimization: Use host networking if possible
# Update Docker images
docker-compose pull
# Restart services
docker-compose restart
# Update with new code
git pull
docker-compose up -d --build# Backup n8n workflows and data
docker run --rm -v tradingview-n8n:/data -v $(pwd):/backup alpine tar czf /backup/n8n-backup.tar.gz -C /data .
# Backup MT5 bridge logs
cp -r mt5-bridge/logs ./backup/- Check the logs:
docker-compose logs -f - Verify configuration files
- Test individual components
- Check network connectivity
# Start system
docker-compose up -d
# Stop system
docker-compose down
# Restart specific service
docker-compose restart mt5-bridge
# View resource usage
docker stats
# Clean up
docker system prune -a- Initial release
- Docker-based deployment
- n8n workflow integration
- MT5 bridge service
- TradingView webhook support
- Comprehensive logging and monitoring
This project is licensed under the MIT License - see the LICENSE file for details.