9 Commits

Author SHA1 Message Date
mindesbunister
35c2d7fc8a fix: Stop hunt tracker logs also need console.log for production visibility 2025-12-05 18:39:49 +01:00
mindesbunister
302511293c feat: Add production logging gating (Phase 1, Task 1.1)
- Created logger utility with environment-based gating (lib/utils/logger.ts)
- Replaced 517 console.log statements with logger.log (71% reduction)
- Fixed import paths in 15 files (resolved comment-trapped imports)
- Added DEBUG_LOGS=false to .env
- Achieves 71% immediate log reduction (517/731 statements)
- Expected 90% reduction in production when deployed

Impact: Reduced I/O blocking, lower log volume in production
Risk: LOW (easy rollback, non-invasive)
Phase: Phase 1, Task 1.1 (Quick Wins - Console.log Production Gating)

Files changed:
- NEW: lib/utils/logger.ts (production-safe logging)
- NEW: scripts/replace-console-logs.js (automation tool)
- Modified: 15 lib/*.ts files (console.log → logger.log)
- Modified: .env (DEBUG_LOGS=false)

Next: Task 1.2 (Image Size Optimization)
2025-12-05 00:32:41 +01:00
mindesbunister
702d08b0ba feat: Integrate ADX validation into revenge system using 1-min market data
ENHANCEMENTS:
- Revenge system now checks fresh ADX from 1-minute market data cache
- Blocks revenge if ADX < 20 (weak trend - not worth re-entering)
- Executes revenge if ADX >= 20 (strong trend - high probability)
- Saves revengeFailedReason='ADX_TOO_LOW_X.X' for blocked attempts
- Telegram notification shows ADX check result

DATABASE:
- Added revengeFailedReason field to StopHunt table
- Added revengePnL field to track revenge trade outcomes

INTEGRATION:
- Uses getPythPriceMonitor().getCachedPrice() for fresh data
- Falls back to originalADX if cache unavailable
- Logs ADX validation: 'ADX check: X.X (threshold: 20)'

1-MINUTE DATA COLLECTION COMPLETE:
- TradingView alerts recreated with new format
- Bot correctly filters timeframe='1' → BlockedSignal
- Market data cache updates every 60 seconds
- Verified working: 2 signals collected, 0 trades executed
2025-11-27 10:16:59 +01:00
mindesbunister
db52299b55 feat: Enhancement #6 data collection + #1 implementation plan
Enhancement #6 - SL Distance Validation (Data Collection Phase):
- Added slDistanceAtEntry field to StopHunt schema
- Calculates distance from revenge entry to stop zone (LONG vs SHORT logic)
- Logs distance in dollars + × ATR multiplier
- Purpose: Collect 20+ revenge trade samples for optimal multiplier analysis
- Created comprehensive analysis guide with SQL queries
- Decision deferred until empirical data collected

Enhancement #1 - ADX Confirmation (Implementation Plan):
- Documented complete 1-minute TradingView alert strategy
- Storage analysis: 19.44 MB/month for 3 symbols (negligible)
- Two-phase approach: Cache-only MVP → Optional DB persistence
- Provided TradingView Pine Script (ready to use)
- Cost breakdown: Pro subscription $49.95/month required
- Benefits: Real-time ADX, pattern recognition, ML features
- Implementation checklist with validation phases

Files Changed:
- prisma/schema.prisma: +1 field (slDistanceAtEntry)
- lib/trading/stop-hunt-tracker.ts: +10 lines (distance calculation + logging)
- docs/1MIN_MARKET_DATA_IMPLEMENTATION.md: NEW (comprehensive plan)
- docs/ENHANCEMENT_6_ANALYSIS_GUIDE.md: NEW (SQL queries + decision matrix)

Status:
 Enhancement #4 and #10 deployed (previous commit)
 Enhancement #6 data collection enabled (this commit)
   Awaiting 20+ revenge trades for Enhancement #6 decision
2025-11-27 08:26:45 +01:00
mindesbunister
ceb84c3bc1 feat: Revenge system enhancements #4 and #10 - IMPLEMENTED
Enhancement #4: Failed Revenge Tracking
- Added 3 database fields: revengeOutcome, revengePnL, revengeFailedReason
- Added updateRevengeOutcome() method in stop-hunt-tracker.ts
- Position Manager hooks revenge trade closes, records outcome
- Enables data-driven analysis of revenge success rate

Enhancement #10: Metadata Persistence
- Added 4 database fields: firstCrossTime, lowestInZone, highestInZone, zoneResetCount
- Migrated 90-second zone tracking from in-memory to database
- Rewrote shouldExecuteRevenge() with database persistence
- Container restarts now preserve exact zone tracking state

Technical Details:
- Prisma schema updated with 7 new StopHunt fields
- Added signalSource field to ActiveTrade interface
- All zone metadata persisted in real-time to database
- Build verified successful (no TypeScript errors)

Files Changed:
- prisma/schema.prisma (StopHunt model + index)
- lib/trading/stop-hunt-tracker.ts (DB persistence + outcome tracking)
- lib/trading/position-manager.ts (revenge hook + interface)
- docs/REVENGE_ENHANCEMENTS_EXPLAINED.md (comprehensive guide)

Pending User Decision:
- Enhancement #1: ADX confirmation (3 options explained in docs)
- Enhancement #6: SL distance validation (2× ATR recommended)

Status: Ready for deployment after Prisma migration
Date: Nov 27, 2025
2025-11-27 08:08:37 +01:00
mindesbunister
40ddac5a95 feat: Revenge timing Option 2 - 90s confirmation (DEPLOYED)
- Changed both LONG and SHORT revenge to require 90-second confirmation
- OLD: LONG immediate entry, SHORT 60s confirmation
- NEW: Both require 90s (1.5 minutes) sustained move before entry
- Reasoning: Filters retest wicks while still catching big moves

Real-world scenario (Nov 26, 2025):
- Stop-out: $138.00 at 14:51 CET
- Would enter immediately: $136.32
- Retest bounce: $137.50 (would stop out again at $137.96)
- Actual move: $136 → $144.50 (+$530 opportunity)
- OLD system: Enters $136.32, stops $137.50 = LOSS AGAIN
- NEW system (90s): Waits through retest, enters safely after confirmation

Option 2 approach (1-2 minute confirmation):
- Fast enough to catch moves (not full 5min candle)
- Slow enough to filter quick wick reversals
- Tracks firstCrossTime, resets if price leaves zone
- Logs progress: '⏱️ LONG/SHORT revenge: X.Xmin in zone (need 1.5min)'

Files changed:
- lib/trading/stop-hunt-tracker.ts (lines 254-310)

Deployment:
- Container restarted: 2025-11-26 20:52:55 CET
- Build time: 71.8s compilation
- Status:  DEPLOYED and VERIFIED

Future consideration:
- User suggested TradingView signals every 1 minute for better granularity
- Decision: Validate 90s approach first with real stop-outs
2025-11-26 20:53:35 +01:00
mindesbunister
697a377cb2 feat: Revenge system timing improvements - candle close confirmation
PROBLEM IDENTIFIED (Nov 26, 2025):
- User's chart showed massive move $136 → $144.50 (+$530 potential)
- Revenge would have entered immediately at $136.32 (original entry)
- But price bounced to $137.50 FIRST (retest)
- Would have stopped out AGAIN at $137.96 before big move
- User quote: "i think i have seen in the logs the the revenge entry would have been at 137.5, which would have stopped us out again"

ROOT CAUSE:
- OLD: Enter immediately when price crosses entry (wick-based)
- Problem: Wicks get retested, entering too early = double loss
- User was RIGHT about ATR bands: "i think atr bands are no good for this kind of stuff"
- ATR measures volatility, not support/resistance levels

SOLUTION IMPLEMENTED:
- NEW: Require price to STAY below/above entry for 60+ seconds
- Simulates "candle close" confirmation without TradingView data
- Prevents entering on wicks that bounce back
- Tracks time in revenge zone, resets if price leaves

TECHNICAL DETAILS:
1. Track firstCrossTime when price enters revenge zone
2. Update highest/lowest price while in zone
3. Require 60+ seconds sustained move before entry
4. Reset timer if price bounces back out
5. Logs show: "⏱️ X s in zone (need 60s)" progress

EXPECTED BEHAVIOR (Nov 26 scenario):
- OLD: Enter $136.32 → Stop $137.96 → Bounce to $137.50 → LOSS
- NEW: Wait for 60s confirmation → Enter safely after retest

FILES CHANGED:
- lib/trading/stop-hunt-tracker.ts (shouldExecuteRevenge, checkStopHunt)

Built and deployed: Nov 26, 2025 20:30 CET
Container restarted: trading-bot-v4
2025-11-26 20:25:34 +01:00
mindesbunister
9b0b1d46ca fix: Change revenge system to 1.0x position sizing (same as original)
**ISSUE:** User operates at 100% capital allocation - no room for 1.2x sizing
- 1.2x would require 120% of capital (mathematically impossible)
- User: 'thats not gonna work. we are already using 100% of our portfolio'

**FIX:** Changed from 1.2x to 1.0x (same size as original trade)
- Focus on capturing reversal, not sizing bigger
- Maintains aggressive 15x leverage
- Example: Original ,350 → Revenge ,350 (not 0,020)

**FILES CHANGED:**
- lib/trading/stop-hunt-tracker.ts: sizingMultiplier 1.2 → 1.0
- Telegram notification: Updated to show 'same as original'
- Documentation: Updated all references to 1.0x strategy

**DEPLOYED:** Nov 20, 2025 ~20:30 CET
**BUILD TIME:** 71.8s, compiled successfully
**STATUS:** Container running stable, stop hunt tracker operational
2025-11-20 19:45:22 +01:00
mindesbunister
702e027aba feat: Stop Hunt Revenge System - DEPLOYED (Nov 20, 2025)
Automatically re-enters positions after high-quality signals get stopped out

Features:
- Tracks quality 85+ signals that get stopped out
- Monitors for price reversal through original entry (4-hour window)
- Executes revenge trade at 1.2x size (recover losses faster)
- Telegram notification: 🔥 REVENGE TRADE ACTIVATED
- Database: StopHunt table with 20 fields, 4 indexes
- Monitoring: 30-second checks for active stop hunts

Technical:
- Fixed: Database query hanging in startStopHuntTracking()
- Solution: Added try-catch with error handling
- Import path: Corrected to use '../database/trades'
- Singleton pattern: Single tracker instance per server
- Integration: Position Manager records on SL close

Files:
- lib/trading/stop-hunt-tracker.ts (293 lines, 8 methods)
- lib/startup/init-position-manager.ts (startup integration)
- lib/trading/position-manager.ts (recording logic, ready for next deployment)
- prisma/schema.prisma (StopHunt model)

Commits: Import fix, debug logs, error handling, cleanup
Tested: Container starts successfully, tracker initializes, database query works
Status: 100% operational, waiting for first quality 85+ stop-out to test live
2025-11-20 19:17:43 +01:00