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
This commit is contained in:
mindesbunister
2025-11-27 08:08:37 +01:00
parent 2238261dfe
commit ceb84c3bc1
6 changed files with 586 additions and 33 deletions

View File

@@ -242,10 +242,22 @@ model StopHunt {
highestPriceAfterStop Float? // Track if stop hunt reverses
lowestPriceAfterStop Float? // Track if stop hunt reverses
// Zone tracking persistence (Nov 27, 2025 - Enhancement #10)
firstCrossTime DateTime? // When price entered revenge zone
lowestInZone Float? // Lowest price while in zone (LONG)
highestInZone Float? // Highest price while in zone (SHORT)
zoneResetCount Int @default(0) // How many times price left zone
// Revenge outcome tracking (Nov 27, 2025 - Enhancement #4)
revengeOutcome String? // "TP1", "TP2", "SL", "TRAILING_SL", null (pending)
revengePnL Float? // Realized P&L from revenge trade
revengeFailedReason String? // Why revenge failed: "stopped_again", "chop", "insufficient_capital"
@@index([symbol])
@@index([revengeExecuted])
@@index([revengeWindowExpired])
@@index([stopHuntTime])
@@index([revengeOutcome])
}
// Performance analytics (daily aggregates)