Files
trading_bot_v4/TRADINGVIEW_STEP_BY_STEP.md
mindesbunister 22195ed34c Fix P&L calculation and signal flip detection
- 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
2025-11-09 17:59:50 +01:00

352 lines
8.3 KiB
Markdown

# TradingView Alert Setup - Step-by-Step Guide
## 🎯 Goal
Create 3 alerts that send market data to your trading bot every 5 minutes.
---
## STEP 1: Find Your Webhook URL
First, we need to know where to send the data.
**Check if your bot is accessible:**
```bash
# On your server, run:
curl http://localhost:3001/api/trading/market-data
```
**Expected response:**
```json
{"success":true,"availableSymbols":[],"count":0,"cache":{}}
```
**Your webhook URL will be ONE of these:**
- `http://YOUR-SERVER-IP:3001/api/trading/market-data` (if port 3001 is open)
- `https://YOUR-DOMAIN.COM:3001/api/trading/market-data` (if you have a domain)
- `https://flow.egonetix.de/webhook/market-data` (if using n8n as proxy)
**Write down your URL here:**
```
My webhook URL: ________________________________
```
---
## STEP 2: Open TradingView and Go to SOL Chart
1. **Go to:** https://www.tradingview.com
2. **Login** to your account
3. **Click** on the chart icon or search bar at top
4. **Type:** `SOLUSDT`
5. **Click** on `SOLUSDT` from Binance (or your preferred exchange)
6. **Set timeframe** to **5 minutes** (click "5" in the top toolbar)
**You should now see:** A 5-minute chart of SOLUSDT
---
## STEP 3: Create Alert
1. **Click** the **Alert icon** 🔔 in the right toolbar
- Or press **ALT + A** on keyboard
2. A popup window opens titled "Create Alert"
---
## STEP 4: Configure Alert Condition
In the "Condition" section:
1. **First dropdown:** Select `time("1")`
- Click the dropdown that says "Crossing" or whatever is there
- **Type** in the search: `time`
- Select: `time``time("1")`
2. **Second dropdown:** Select `changes`
- This should appear automatically after selecting time("1")
- If not, select "changes" from the dropdown
**What you should see:**
```
time("1") changes
```
This means: "Alert fires when time changes" = every bar close
---
## STEP 5: Set Alert Actions (IMPORTANT!)
Scroll down to the "Notifications" section:
**UNCHECK everything EXCEPT:**
-**Webhook URL** (leave this CHECKED)
**UNCHECK these:**
- ❌ Notify on app
- ❌ Show popup
- ❌ Send email
- ❌ Play sound
**We ONLY want webhook!**
---
## STEP 6: Enter Webhook URL
1. In the **Webhook URL** field, paste your URL from Step 1:
```
http://YOUR-SERVER-IP:3001/api/trading/market-data
```
*(Replace with your actual URL)*
2. **Click in the field** to make sure it's saved
---
## STEP 7: Configure Alert Message (COPY-PASTE THIS)
Scroll to the **"Alert message"** box.
**DELETE everything** in that box.
**PASTE this EXACTLY** (copy the entire JSON):
```json
{
"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}}
}
```
**IMPORTANT:** Make sure:
- No spaces added/removed
- The `{{` double brackets are kept
- No missing commas
- No extra text
---
## STEP 8: Set Alert Name and Frequency
**Alert name:**
```
Market Data - SOL 5min
```
**Frequency section:**
- Select: **"Once Per Bar Close"**
- NOT "Only Once"
- NOT "Once Per Bar"
- Must be **"Once Per Bar Close"**
**Expiration:**
- Select: **"Never"** or **"Open-ended"**
**Show popup / Name on chart:**
- You can uncheck these (optional)
---
## STEP 9: Create the Alert
1. **Click** the blue **"Create"** button at bottom
2. Alert is now active! ✅
You should see it in your alerts list (🔔 icon in right panel)
---
## STEP 10: Repeat for ETH and BTC
Now do the EXACT same steps for:
**For ETH:**
1. Search for `ETHUSDT`
2. Set to 5-minute chart
3. Create alert (ALT + A)
4. Condition: `time("1") changes`
5. Webhook URL: (same as SOL)
6. Alert message: (same JSON as SOL)
7. Alert name: `Market Data - ETH 5min`
8. Frequency: Once Per Bar Close
9. Create
**For BTC:**
1. Search for `BTCUSDT`
2. Set to 5-minute chart
3. Create alert (ALT + A)
4. Condition: `time("1") changes`
5. Webhook URL: (same as SOL)
6. Alert message: (same JSON as SOL)
7. Alert name: `Market Data - BTC 5min`
8. Frequency: Once Per Bar Close
9. Create
---
## ✅ VERIFICATION (Wait 5 Minutes)
After creating alerts, **WAIT UP TO 5 MINUTES** for the next bar close.
Then run this on your server:
```bash
curl http://localhost:3001/api/trading/market-data
```
**You should see:**
```json
{
"success": true,
"availableSymbols": ["SOL-PERP", "ETH-PERP", "BTC-PERP"],
"count": 3,
"cache": {
"SOL-PERP": {
"atr": 0.45,
"adx": 32.1,
"rsi": 58.3,
"volumeRatio": 1.25,
"pricePosition": 55.2,
"ageSeconds": 23
},
...
}
}
```
**If you see this → SUCCESS!** ✅
---
## 🐛 Troubleshooting
### Problem: Still shows empty cache after 10 minutes
**Check 1: Are alerts active?**
- Click 🔔 icon in TradingView
- Look for your 3 alerts
- They should say "Active" (not paused)
**Check 2: Is webhook URL correct?**
- Click on an alert to edit it
- Check the Webhook URL field
- No typos? Correct port (3001)?
**Check 3: Check bot logs**
```bash
docker logs -f trading-bot-v4
```
Wait for next bar close and watch for incoming requests.
You should see:
```
POST /api/trading/market-data
✅ Market data cached for SOL-PERP
```
**Check 4: Is port 3001 open?**
```bash
# From another machine or phone:
curl http://YOUR-SERVER-IP:3001/api/trading/market-data
```
If this fails, port 3001 might be blocked by firewall.
**Check 5: TradingView plan supports webhooks?**
- Free plan: NO webhooks ❌
- Pro plan: YES ✅
- Pro+ plan: YES ✅
- Premium: YES ✅
If you have Free plan, you need to upgrade to Pro ($14.95/month).
---
## 📸 Visual Guide
**Where is the Alert icon?**
```
TradingView Chart:
┌─────────────────────────────────────┐
│ [Chart toolbar at top] │
│ │
│ [Chart area] 🔔 ← Alert icon (right side)
│ │
│ │
└─────────────────────────────────────┘
```
**What the Alert popup looks like:**
```
┌─ Create Alert ────────────────┐
│ │
│ Condition: │
│ [time("1")] [changes] │
│ │
│ Notifications: │
│ ✅ Webhook URL │
│ [http://your-url...] │
│ │
│ Alert message: │
│ [{"action":"market_data",...}]│
│ │
│ Alert name: │
│ [Market Data - SOL 5min] │
│ │
│ Frequency: │
│ [Once Per Bar Close] │
│ │
│ [Create] │
└───────────────────────────────┘
```
---
## 🎬 Quick Recap
**You need to create 3 alerts total:**
| Symbol | Chart | Alert Name | Frequency |
|-----------|-----------|-------------------------|-------------------|
| SOLUSDT | 5-minute | Market Data - SOL 5min | Once Per Bar Close|
| ETHUSDT | 5-minute | Market Data - ETH 5min | Once Per Bar Close|
| BTCUSDT | 5-minute | Market Data - BTC 5min | Once Per Bar Close|
**All 3 use:**
- Same webhook URL
- Same alert message (the JSON)
- Same condition: `time("1") changes`
- Same frequency: Once Per Bar Close
**After 5 minutes:**
- Check cache is populated
- Test with Telegram: `long sol`
---
## ❓ Still Stuck?
**Common mistakes:**
1. ❌ Using "Once Per Bar" instead of "Once Per Bar Close"
2. ❌ Alert message has extra spaces or missing brackets
3. ❌ Webhook URL has typo or wrong port
4. ❌ Alert is paused (not active)
5. ❌ Free TradingView plan (needs Pro for webhooks)
**Need help?**
- Show me a screenshot of your alert configuration
- Show me the output of `docker logs trading-bot-v4`
- Show me the output of `curl http://localhost:3001/api/trading/market-data`
---
**Once alerts are working, you're ready to run the SQL analysis!** 🚀