From 91f8abed193f3b839afe4e572792c41cf1e91a1d Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Fri, 26 Dec 2025 10:19:48 +0100 Subject: [PATCH] docs: Update documentation for Dec 26 config changes - Updated Active System section: v11.2 INDICATOR now production - Documented v11.2 optimized parameters (ATR 12, Mult 3.8, ADX 15, RSI 56-69) - Updated Adaptive Leverage: NOW DISABLED, fixed 5x leverage - Removed 10x tier references, consistent 5x across all symbols --- .github/copilot-instructions.md | 97 +++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 18 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index a8abf35..5d10d77 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -39,19 +39,23 @@ **⚠️ CRITICAL: Always check this section first to know what's currently deployed in production** ### TradingView Indicator (Signal Generation) -- **Active Version:** v11.2 IMPROVED (or v11 All Filters - CHECK TRADINGVIEW) -- **Production File:** User has v11.2 indicator active in TradingView (reports "v11 v2") +- **Active Version:** v11.2 INDICATOR (optimized Dec 26, 2025) +- **Production File:** `workflows/trading/moneyline_v11_2_indicator.pinescript` - **Available Files:** + * `workflows/trading/moneyline_v11_2_indicator.pinescript` - v11.2 INDICATOR (backtested +50% return, PF 2.507) * `workflows/trading/moneyline_v11_2_improved.pinescript` - v11.2 IMPROVED (balanced parameters) * `workflows/trading/moneyline_v11_all_filters.pinescript` - v11 All Filters (exhaustive sweep optimal) + * `workflows/trading/breaker_v1.pinescript` - NEW experimental squeeze-and-release breakout concept (not deployed) - **Status:** ✅ PRODUCTION (filters NOW WORKING as of v11.1 - Dec 15, 2025) - **Critical Bug Fixed:** Bug #84 - Filters were calculated but never applied to signal logic (caused $1,000 loss) -- **v11.2 IMPROVED Parameters (Balanced):** - * Flip Threshold: 0.20% (tighter trend confirmation vs v11's 0.15%) - * ADX Minimum: 12 (moderate between v11's 5 and emergency 18) - * RSI LONG: 56-69 (balanced vs v11's 55-70) - * RSI SHORT: 30-70 (momentum-based, RSI 50+ showed 68.2% WR) - * Entry Buffer: 0.10 ATR +- **v11.2 INDICATOR Parameters (Optimized Dec 26, 2025):** + * ATR Period: 12, Multiplier: 3.8 + * Flip Threshold: 0.0%, Confirm Bars: 1 + * ADX Minimum: 15 (ADX Length: 17) + * RSI LONG: 56-69, RSI SHORT: 30-70 + * Entry Buffer: -0.15 ATR (negative = early entry) + * Long Position Max: 85%, Short Position Min: 5% + * Volume Filter: OFF - **v11 All Filters Parameters (Exhaustive Sweep Optimal):** * Flip Threshold: 0.15% * ADX Minimum: 5 (26,244 config sweep optimal) @@ -93,16 +97,17 @@ - **Last Updated:** Dec 17, 2025 (state persistence fix - commit 341341d) ### Adaptive Leverage System -- **Status:** ✅ ACTIVE with direction-specific thresholds +- **Status:** ❌ DISABLED (Dec 26, 2025) - Using fixed 5x leverage - **Configuration:** - * `USE_ADAPTIVE_LEVERAGE=true` - * `HIGH_QUALITY_LEVERAGE=10` (10× for high-quality signals) - * `LOW_QUALITY_LEVERAGE=5` (5× for borderline signals) - * `QUALITY_LEVERAGE_THRESHOLD_LONG=95` (LONG threshold) - * `QUALITY_LEVERAGE_THRESHOLD_SHORT=90` (SHORT threshold) -- **Logic:** Quality score determines leverage tier BEFORE position sizing -- **Impact:** 2× profit on high-quality signals vs fixed leverage -- **Last Updated:** Dec 1, 2025 (direction-specific thresholds + UI controls) + * `USE_ADAPTIVE_LEVERAGE=false` + * `LEVERAGE=5` (global default) + * `SOLANA_LEVERAGE=5` + * `ETHEREUM_LEVERAGE=5` + * `HIGH_QUALITY_LEVERAGE=5` (no 10x tier) + * `LOW_QUALITY_LEVERAGE=5` +- **Rationale:** Simplified risk management with consistent 5x leverage +- **Previous Config:** Was 10x for quality ≥95, 5x for quality 90-94 +- **Last Updated:** Dec 26, 2025 (commit 5d8fa78) ### Supporting Systems (All Active) - **Stop Hunt Revenge:** Quality 85+ signals get auto re-entry on reversal (90s confirmation) @@ -2517,6 +2522,7 @@ scoreSignalQuality({ - Runs alongside: data cleanup, blocked signals, stop hunt, smart validation - No manual intervention needed - Auto-recovery: If DB shows open trades but Position Manager monitoring is off, the health monitor now forces a Position Manager reinitialize from the database before raising a critical alert (avoids container restarts when possible). +- Auto-remediation (Dec 23, 2025): Health monitor now actively fixes missing protection on any open trade (including auto-synced/manual). When SL/soft/hard stops are absent, it calculates TP/SL prices from current config, calls `placeExitOrders()` to lay down protection, and writes returned signatures back to the Trade record (tp1/tp2/SL/soft/hard). Logs success/failure so unprotected positions are corrected within the 30s health loop instead of only alerting. **Test Suite:** - File: `tests/integration/position-manager/monitoring-verification.test.ts` (201 lines) @@ -3630,7 +3636,62 @@ This section contains the **TOP 10 MOST CRITICAL** pitfalls that every AI agent - **Why Bug #81 Didn't Fix This:** Bug #81 = orders never placed, Bug #82 = orders placed then REMOVED by verifier - **Status:** ✅ EMERGENCY FIX DEPLOYED Dec 10, 2025 11:06 CET (commit e5714e4) -**12. Docker Cache Prevents Telegram Notification Code Deployment (#86 - CRITICAL - Dec 17, 2025)** - `--force-recreate` ≠ `--no-cache` +**12. Auto-Synced Positions Have No Exit Orders (#88 - CRITICAL - Dec 23, 2025)** - Manually opened positions unprotected +- **Symptom:** Position appears in Drift UI, auto-synced to database, NO Telegram notification, NO TP/SL orders, completely unprotected +- **User Report:** "why the hell is there a position open that i didnt get notified about without risk management. no tp and no stop loss ?????!!!!!!" +- **Financial Impact:** -$1.38 loss on unprotected position (small this time, could have been catastrophic) +- **Real Incident (Dec 23, 2025 19:06 CET):** + * Position appeared in Drift: SOL-PERP SHORT 35.95 tokens @ $123.96 + * Database record created: Trade `cmjiyi3d500hcrz07jiv9u3sk` + * Quality score: NULL (not from TradingView signal) + * Exit orders: ALL NULL (slOrderTx, tp1OrderTx, tp2OrderTx) + * Telegram notification: NONE (auto-sync is silent) + * Position Manager: Monitoring active but no on-chain protection +- **Root Cause:** + * Position opened manually (via Drift UI, Telegram manual command, or other method) + * Health monitor detected: "🚨 UNTRACKED POSITIONS DETECTED: Drift has 1, PM has 0" + * Auto-sync triggered: "🔄 AUTO-SYNC TRIGGERED: Untracked positions detected" + * Placeholder trade created: "⚠️ No open DB trade found for SOL-PERP. Creating synced placeholder" + * BUT: Can't place exit orders on positions opened elsewhere + * Result: Position tracked but COMPLETELY UNPROTECTED +- **Why This Happens:** + * Auto-sync system designed to restore tracking for orphaned positions + * Can't retroactively place TP/SL orders on positions not opened by bot + * Drift API doesn't allow modifying orders for positions opened externally + * System prioritizes tracking over crashing (fail-open for monitoring) +- **THE ISSUE:** + * ✅ Position Manager IS monitoring (logs show price checks every 2s) + * ❌ NO on-chain TP/SL orders (vulnerable if PM crashes or restarts) + * ❌ NO Telegram notification (user unaware of unprotected position) + * ❌ Quality score NULL (can't apply quality-based risk management) +- **Prevention Rules:** + 1. NEVER open positions manually outside the bot system + 2. If you must open manually, immediately place TP/SL via Drift UI + 3. Check Telegram notifications - no notification = something wrong + 4. Monitor for auto-sync alerts in docker logs + 5. Use `/api/trading/positions` endpoint to verify protection status + 6. Close manually-opened positions immediately if discovered unprotected +- **Red Flags Indicating This Bug:** + * Position in Drift but no Telegram notification received + * Database trade has quality score NULL + * All exit order TX fields are NULL (slOrderTx, tp1OrderTx, tp2OrderTx) + * Docker logs show "Creating synced placeholder to restore protection" + * Health monitor shows "UNTRACKED POSITIONS DETECTED" + * signalSource field is 'autosync' or 'manual' instead of 'tradingview' +- **IMMEDIATE ACTION When Detected:** + * **Option 1 (RECOMMENDED):** Close position immediately via Drift UI or Telegram + * **Option 2 (RISKY):** Manually place SL order via Drift UI (error-prone) + * DO NOT rely on Position Manager alone - no on-chain protection = vulnerable +- **Long-Term Fix Ideas (Not Implemented):** + 1. Attempt to place exit orders during auto-sync (may fail but worth trying) + 2. Send Telegram alert when auto-sync creates placeholder + 3. Auto-close positions that can't be protected + 4. Add "unprotected" flag to database for operator awareness + 5. Disable manual trading entirely (force all trades through bot) +- **Status:** ⚠️ DOCUMENTED Dec 23, 2025 - System working as designed, user education required +- **Lesson Learned:** Auto-sync saves tracking but can't add protection retroactively. Manual positions are dangerous in automated system. Always verify Telegram notifications received for every position. + +**13. Docker Cache Prevents Telegram Notification Code Deployment (#86 - CRITICAL - Dec 17, 2025)** - `--force-recreate` ≠ `--no-cache` - **Symptom:** Container newer than commits, but Telegram shows OLD notification format (0.15% instead of 0.3%) - **User Report:** "telegram is not fixed" after multiple rebuilds showing old code - **Financial Impact:** 2 hours of debugging, delayed feature deployment, confusion about system state