Files
trading_bot_v4/docs/1MIN_ALERTS_SETUP.md
mindesbunister 4458cd1dae feat: Add 1-minute market data TradingView indicator and setup guide
- Created Pine Script indicator: moneyline_1min_data_feed.pinescript
  * Calculates ADX, ATR, RSI, volumeRatio, pricePosition, MA gap
  * Sends JSON with action="market_data_1min" every bar close
  * Uses same metrics as v9 indicator for consistency
  * Alert fires every 1 minute on 1-min chart

- Created setup guide: docs/1MIN_ALERTS_SETUP.md
  * Step-by-step TradingView alert configuration (SOL/ETH/BTC)
  * Alert slot usage: 3 needed, 16 remaining free (no upgrade needed)
  * n8n workflow validation steps (already has Is 1min Data? condition)
  * 24-48 hour testing procedures
  * Troubleshooting guide for common issues
  * Integration plan for ADX validation in revenge system

- Verified n8n workflow ready:
  * market_data_handler.json has "Is 1min Data?" condition (checks action === market_data_1min)
  * Forwards to http://trading-bot-v4:3000/api/trading/market-data
  * Responds with {success: true, cached: true}
  * NO workflow changes needed - infrastructure already prepared

Alert volume: 180/hour (60 per symbol) = 129,600/month
Storage impact: 19.44 MB/month (negligible)
Cost: $0/month (no TradingView upgrade required)

Ready to implement - user can create alerts immediately
Next: Validate 24-48 hours, then integrate ADX confirmation in revenge system
2025-11-27 08:53:28 +01:00

7.8 KiB

1-Minute Market Data Alerts - Setup Instructions

Status: READY TO IMPLEMENT - Zero Cost!
Date: November 27, 2025
Cost: $0/month (3 alert slots, 16 remaining free)

Quick Summary

  • Purpose: Send market data every 1 minute for real-time ADX validation in revenge trades
  • Indicator: /workflows/trading/moneyline_1min_data_feed.pinescript
  • Webhook: https://flow.egonetix.de/webhook/3371ad7c-0866-4161-90a4-f251de4aceb8
  • n8n Workflow: market_data_handler.json (already has "Is 1min Data?" condition)
  • Alert Slots: 3 needed (SOL/ETH/BTC), 16 remaining free

Step 1: Add Indicator to TradingView

1.1 Copy Pine Script

Open /home/icke/traderv4/workflows/trading/moneyline_1min_data_feed.pinescript and copy the entire code.

1.2 Create New Indicator

  1. Open TradingView.com
  2. Click Pine Editor at bottom of screen
  3. Click "Open""New blank indicator"
  4. Delete template code
  5. Paste the copied Pine Script
  6. Click "Save" → Name: "Money Line - 1min Data Feed"

Step 2: Create Alerts (Do This 3 Times)

2.1 SOL-PERP 1-Minute Alert

  1. Open Chart:

    • Symbol: SOL-PERP (or SOLUSDT)
    • Timeframe: 1 minute ← CRITICAL!
  2. Add Indicator:

    • Click Indicators button
    • Search: "Money Line - 1min Data Feed"
    • Add to chart (should appear at bottom)
  3. Create Alert:

    • Click Alert button ( icon) or right-click chart → "Add alert"
    • Condition: Select indicator → "Money Line - 1min Data Feed" → "Any alert() function call"
    • Alert Name: SOL-PERP 1min Data Feed
    • Frequency: Once Per Bar Close ← CRITICAL! (NOT "Once Per Bar" or "All")
    • Expiration: Open-ended (no expiration)
  4. Configure Webhook:

    • Check "Webhook URL"
    • URL: https://flow.egonetix.de/webhook/3371ad7c-0866-4161-90a4-f251de4aceb8
    • Message: Leave blank (indicator provides JSON in alert message)
  5. Notification Settings:

    • Uncheck email/push notifications (optional - reduce noise)
    • Click Create

2.2 ETH-PERP 1-Minute Alert

Repeat Step 2.1 for:

  • Symbol: ETH-PERP (or ETHUSDT)
  • Timeframe: 1 minute
  • Alert Name: ETH-PERP 1min Data Feed
  • Same webhook URL

2.3 BTC-PERP 1-Minute Alert

Repeat Step 2.1 for:

  • Symbol: BTC-PERP (or BTCUSDT)
  • Timeframe: 1 minute
  • Alert Name: BTC-PERP 1min Data Feed
  • Same webhook URL

Step 3: Verify Alerts Created

  1. Go to TradingView → Alerts panel (right side)
  2. You should see 3 new alerts in "Active" section:
    • SOL-PERP 1min Data Feed
    • ETH-PERP 1min Data Feed
    • BTC-PERP 1min Data Feed
  3. Alert slots used: 7/20 (was 4, added 3)
  4. Remaining: 13 alert slots free

Step 4: Test Data Flow (24 Hours)

4.1 Monitor n8n Executions

# Watch n8n container logs
docker logs compose_files-n8n -f | grep market_data_1min

# Expected: JSON payloads every ~1 minute per symbol
# {"action":"market_data_1min","symbol":"SOL-PERP","adx":26.5,...}

4.2 Monitor Bot API

# Watch bot cache updates
docker logs trading-bot-v4 -f | grep "Market data updated"

# Expected: "✅ Market data updated for SOL-PERP: ADX 26.5"

4.3 Check Fresh Data Availability

# Query cached market data
curl -s http://localhost:3001/api/trading/market-data | jq '.'

# Expected: Fresh data for SOL-PERP, ETH-PERP, BTC-PERP with timestamps <60s old

4.4 Verify Cache Age

# Check API response
curl -s http://localhost:3001/api/analytics/reentry-check \
  -H "Content-Type: application/json" \
  -d '{"symbol":"SOL-PERP","direction":"long"}' | jq '.marketData.age'

# Expected: "23s old" (not "5 minutes old")

Expected Behavior

Data Frequency

  • Per Symbol: 60 alerts/hour = 1,440/day = 43,200/month
  • Total (3 symbols): 180 alerts/hour = 4,320/day = 129,600/month
  • Storage: ~19.44 MB/month (negligible)

n8n Workflow Flow

TradingView Alert (every 1 min)
  ↓ webhook/3371ad7c-0866-4161-90a4-f251de4aceb8
n8n: "Is 1min Data?" (action === "market_data_1min") ✅
  ↓ Forward to Bot
POST http://trading-bot-v4:3000/api/trading/market-data
  ↓ Cache updated (5-minute expiry)
Respond: {success: true, cached: true}

API Endpoint Behavior

// app/api/trading/market-data/route.ts
// Receives 1-minute data, stores in cache with 5-minute expiry
// Multiple updates per expiry window = always fresh data

Troubleshooting

Problem: No Data in Logs

Symptom: Bot logs show no "Market data updated" messages

Check:

  1. TradingView alerts are active (green icon in Alerts panel)
  2. Webhook URL correct: https://flow.egonetix.de/webhook/3371ad7c-0866-4161-90a4-f251de4aceb8
  3. n8n container running: docker ps | grep n8n (should show "Up" status)
  4. n8n receiving webhooks: docker logs compose_files-n8n | tail -20

Fix: Recreate alert with correct webhook URL and "Once Per Bar Close" frequency

Problem: "Is 1min Data?" Condition Not Triggering

Symptom: n8n receives webhooks but doesn't forward to bot

Check:

  1. Alert message has "action":"market_data_1min" in JSON
  2. n8n workflow has condition: {{ $json.body.action }} equals market_data_1min
  3. Workflow connections: "Is 1min Data?" → "Forward to Bot"

Fix: Update market_data_handler.json condition to check $json.body.action

Problem: Cache Still Showing Stale Data

Symptom: reentry-check shows "5 minutes old" despite 1-min alerts

Check:

  1. Bot API actually receiving data: docker logs trading-bot-v4 | grep "Market data updated"
  2. Symbol name match: TradingView sends "SOLUSDT", bot expects "SOL-PERP"
  3. Cache logic: lib/trading/market-data-cache.ts set() method

Fix: Verify symbol normalization in execute endpoint (line ~130)


Integration with Revenge System (Future)

Once 1-minute data validated for 48 hours, integrate ADX validation:

// lib/trading/stop-hunt-tracker.ts - shouldExecuteRevenge()

// Get fresh ADX from cache
const cache = getMarketDataCache()
const marketData = cache.get(stopHunt.symbol)

if (marketData && marketData.adx !== undefined) {
  if (marketData.adx < 20) {
    console.log(`⚠️ Revenge blocked: ADX ${marketData.adx.toFixed(1)} too low (need 20+)`)
    return false  // Weak trend, skip revenge
  }
  console.log(`✅ ADX validation passed: ${marketData.adx.toFixed(1)} (strong trend)`)
} else {
  console.log(`⚠️ No fresh ADX data, allowing revenge (cache age: ${Date.now() - marketData?.timestamp}ms)`)
  // Fail-open: Allow revenge if data unavailable (don't block on cache failures)
}

Alert Slot Usage Summary

Before 1-min alerts: 4/20 slots used (16 free)
After 1-min alerts: 7/20 slots used (13 free)
Cost: $0/month (no upgrade needed)

Remaining capacity: 13 alert slots available for:

  • Additional symbols (ADA, MATIC, etc.)
  • Multi-timeframe alerts (5min/15min/1H for same symbols)
  • Stop-loss/take-profit notifications
  • Custom pattern alerts

Success Criteria

After 24-48 hours of monitoring:

Data Freshness: reentry-check shows "<60s old" for all 3 symbols
Frequency: ~180 cache updates/hour (60 per symbol)
Availability: 99%+ cache hit rate (data always available)
Accuracy: ADX/ATR/RSI values match TradingView chart
Storage: Database logs confirm negligible storage impact (<20 MB)

Once validated, proceed with Enhancement #1 (ADX Confirmation) integration.


References

  • Implementation Plan: /home/icke/traderv4/docs/1MIN_MARKET_DATA_IMPLEMENTATION.md
  • Pine Script Indicator: /home/icke/traderv4/workflows/trading/moneyline_1min_data_feed.pinescript
  • n8n Workflow: /home/icke/traderv4/workflows/trading/market_data_handler.json
  • Bot API Endpoint: /home/icke/traderv4/app/api/trading/market-data/route.ts
  • Market Data Cache: /home/icke/traderv4/lib/trading/market-data-cache.ts