Files
mql-trading-bots/N8N_WORKFLOW_SETUP.md

153 lines
3.7 KiB
Markdown

# N8N Workflow for MQL Settings Monitoring
## Overview
This n8n workflow monitors your `.set` files every 6 hours and alerts you if there are issues like:
- Invalid variable names (typos)
- Missing critical parameters
- Overly restrictive settings blocking trades
- Weekend protection disabled
- Files not tracked in git
## Files Included
| File | Purpose |
|------|---------|
| `n8n-workflow-simple.json` | Simple workflow (recommended) |
| `n8n-workflow-check-sets.json` | Advanced workflow with Discord |
| `scripts/validate-settings.sh` | Validation script |
## Quick Setup (Simple Workflow)
### 1. Install N8N
```bash
# Using Docker
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n
```
### 2. Import Workflow
1. Open N8N: http://localhost:5678
2. Click **"Add Workflow"**
3. Click **"Import from File"**
4. Select `n8n-workflow-simple.json`
### 3. Configure Environment Variables
Add these to your n8n credentials or `.env`:
```bash
# Telegram Notifications (recommended)
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# Optional: Email Notifications
ALERT_EMAIL=garfield@fetcherpay.com
# Optional: Discord Notifications
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
```
### 4. Get Telegram Chat ID
1. Message @userinfobot on Telegram - it will give you your ID
2. Or use @getidsbot
### 5. Activate Workflow
1. Open the imported workflow
2. Click **"Active"** toggle (top right)
3. Click **"Save"**
## Validation Script
You can also run the validation manually:
```bash
# Run validation
./scripts/validate-settings.sh
# Run from anywhere
/home/garfield/mql-trading-bots/scripts/validate-settings.sh
```
## What It Checks
| Check | Description | Alert Level |
|-------|-------------|-------------|
| File count | Ensures .set files exist | Error |
| Invalid variables | Finds typos like `InpMinConfluenceStrength` | Error |
| Missing parameters | Checks critical params exist | Error |
| High strength | Warns if `InpMinStrength` > 0.8 | Warning |
| Debug mode | Warns if debug disabled | Warning |
| Weekend protection | Ensures `InpCloseBeforeWeekend=true` | Error |
| Git status | Warns about untracked files | Warning |
## Sample Telegram Alert
```
🚨 MQL Settings Issues Found:
ISSUE: confluence-eurusd.set missing: InpCloseBeforeWeekend
ISSUE: confluence-usdjpy.set missing: InpCloseBeforeWeekend
WARNING: High strength thresholds (may block trades):
- confluence-gbpusd.set: InpMinStrength=0.80
⏰ 2026-03-30 14:30
```
## Sample Success Message
```
✅ Settings check passed
Confluence settings: 13 files
Grid settings: 13 files
✓ No invalid variable names found
✓ All files have weekend protection enabled
```
## Scheduling Options
Edit the Schedule Trigger node to change frequency:
| Frequency | Settings |
|-----------|----------|
| Every 15 minutes | `interval: 15 minutes` |
| Every hour | `interval: 1 hour` |
| Every 6 hours | `interval: 6 hours` (default) |
| Daily at 9am | `cron: 0 9 * * *` |
## Troubleshooting
### No alerts received
- Check Telegram bot token is valid
- Verify chat ID is correct
- Check n8n execution log
### Script fails with permission denied
```bash
chmod +x /home/garfield/mql-trading-bots/scripts/validate-settings.sh
```
### Workflow shows error
- Ensure n8n can access `/home/garfield/mql-trading-bots`
- Check that script exists and is executable
## Advanced: Custom Checks
Edit `scripts/validate-settings.sh` to add your own checks:
```bash
# Example: Check for specific EA version
grep -q "EA_Version=1.16" *.set || echo "ISSUE: Files not updated to v1.16"
```
## Related Documentation
- [AGENTS.md](AGENTS.md) - Project context
- [SETTINGS_GUIDE.md](SETTINGS_GUIDE.md) - Settings documentation