- Fix external closure P&L using tp1Hit flag instead of currentSize - Add direction change detection to prevent false TP1 on signal flips - Signal flips now recorded with accurate P&L as 'manual' exits - Add retry logic with exponential backoff for Solana RPC rate limits - Create /api/trading/cancel-orders endpoint for manual cleanup - Improves data integrity for win/loss statistics
5.4 KiB
TradingView Market Data Alert Setup
Quick Copy-Paste Alert Configuration
Alert 1: SOL Market Data (5-minute bars)
Symbol: SOLUSDT
Timeframe: 5 minutes
Alert Name: Market Data - SOL 5min
Condition:
ta.change(time("1"))
(This fires every bar close)
Alert Message:
{
"action": "market_data",
"symbol": "{{ticker}}",
"timeframe": "{{interval}}",
"atr": {{ta.atr(14)}},
"adx": {{ta.dmi(14, 14)}},
"rsi": {{ta.rsi(14)}},
"volumeRatio": {{volume / ta.sma(volume, 20)}},
"pricePosition": {{(close - ta.lowest(low, 100)) / (ta.highest(high, 100) - ta.lowest(low, 100)) * 100}},
"currentPrice": {{close}}
}
Webhook URL: (Choose one based on your setup)
Option 1 (if bot is publicly accessible):
https://YOUR-DOMAIN.COM:3001/api/trading/market-data
Option 2 (if using n8n as proxy):
https://flow.egonetix.de/webhook/market-data
Option 3 (local testing):
http://YOUR-SERVER-IP:3001/api/trading/market-data
Settings:
- ✅ Webhook URL (enable and enter URL above)
- ✅ Once Per Bar Close
- Expiration: Never
- Name on chart: Market Data - SOL 5min
Alert 2: ETH Market Data (5-minute bars)
Symbol: ETHUSDT
Timeframe: 5 minutes
Alert Name: Market Data - ETH 5min
Condition:
ta.change(time("1"))
Alert Message:
{
"action": "market_data",
"symbol": "{{ticker}}",
"timeframe": "{{interval}}",
"atr": {{ta.atr(14)}},
"adx": {{ta.dmi(14, 14)}},
"rsi": {{ta.rsi(14)}},
"volumeRatio": {{volume / ta.sma(volume, 20)}},
"pricePosition": {{(close - ta.lowest(low, 100)) / (ta.highest(high, 100) - ta.lowest(low, 100)) * 100}},
"currentPrice": {{close}}
}
Webhook URL: (Same as SOL above)
Settings:
- ✅ Webhook URL (same as SOL)
- ✅ Once Per Bar Close
- Expiration: Never
Alert 3: BTC Market Data (5-minute bars)
Symbol: BTCUSDT
Timeframe: 5 minutes
Alert Name: Market Data - BTC 5min
Condition:
ta.change(time("1"))
Alert Message:
{
"action": "market_data",
"symbol": "{{ticker}}",
"timeframe": "{{interval}}",
"atr": {{ta.atr(14)}},
"adx": {{ta.dmi(14, 14)}},
"rsi": {{ta.rsi(14)}},
"volumeRatio": {{volume / ta.sma(volume, 20)}},
"pricePosition": {{(close - ta.lowest(low, 100)) / (ta.highest(high, 100) - ta.lowest(low, 100)) * 100}},
"currentPrice": {{close}}
}
Webhook URL: (Same as SOL above)
Settings:
- ✅ Webhook URL (same as SOL)
- ✅ Once Per Bar Close
- Expiration: Never
Verification Steps
Step 1: Check Webhook Endpoint is Accessible
# From your server
curl http://localhost:3001/api/trading/market-data
# Should return:
# {"success":true,"availableSymbols":[],"count":0,"cache":{}}
Step 2: Wait 5 Minutes for First Alert
After creating alerts, wait for next bar close (5 minutes max)
Step 3: Verify Cache is Populated
curl http://localhost:3001/api/trading/market-data
# Should now show:
# {
# "success": true,
# "availableSymbols": ["SOL-PERP", "ETH-PERP", "BTC-PERP"],
# "count": 3,
# "cache": {
# "SOL-PERP": {
# "atr": 0.45,
# "adx": 32.1,
# "rsi": 58.3,
# "ageSeconds": 23
# },
# ...
# }
# }
Step 4: Test Telegram Trade
You: "long sol"
# Should see:
✅ Analytics check passed (68/100)
Data: tradingview_real (23s old) ← FRESH DATA!
Proceeding with LONG SOL...
Troubleshooting
Problem: Cache still empty after 10 minutes
Check:
- TradingView alerts show "Active" status
- Webhook URL is correct (check for typos)
- Port 3001 is accessible (firewall rules)
- Docker container is running:
docker ps | grep trading-bot - Check logs:
docker logs -f trading-bot-v4
Problem: Alerts not firing
Check:
- TradingView plan supports webhooks (Pro/Premium/Pro+)
- Chart is open (alerts need chart loaded to fire)
- Condition
ta.change(time("1"))is correct - Timeframe matches (5-minute chart)
Problem: JSON parse errors in logs
Check:
- Alert message is valid JSON (no trailing commas)
- TradingView placeholders use
{{ticker}}not{ticker} - No special characters breaking JSON
Alert Cost Optimization
Current setup: 3 alerts firing every 5 minutes = ~864 alerts/day
TradingView Alert Limits:
- Free: 1 alert
- Pro: 20 alerts
- Pro+: 100 alerts
- Premium: 400 alerts
If you need to reduce alerts:
- Use 15-minute bars instead of 5-minute (reduces by 67%)
- Only enable alerts for symbols you actively trade
- Use same alert for multiple symbols (requires script modification)
Advanced: n8n Proxy Setup (Optional)
If your bot is not publicly accessible, use n8n as webhook proxy:
Step 1: Create n8n webhook
- Webhook URL:
https://flow.egonetix.de/webhook/market-data - Method: POST
- Response: Return text
Step 2: Add HTTP Request node
- URL:
http://trading-bot-v4:3000/api/trading/market-data - Method: POST
- Body:
{{ $json }} - Headers: None needed (internal network)
Step 3: Use n8n URL in TradingView alerts
https://flow.egonetix.de/webhook/market-data
Next: Enable Market Data Alerts
- Copy alert message JSON from above
- Open TradingView → SOL/USD 5-minute chart
- Click alert icon (top right)
- Paste condition and message
- Save alert
- Repeat for ETH and BTC
- Wait 5 minutes and verify cache
Once verified, proceed to SQL analysis!