critical: Fix MAE/MFE storing percentages instead of dollars + duplicate Telegram notifications
CRITICAL BUGS FIXED (Nov 19, 2025): 1. MAE/MFE Bug: - Was storing: account percentage (profit % × leverage) - Example: 1.31% move × 15x = 19.73% stored as MFE - Should store: actual dollar P&L (81 not 19.73%) - Impact: Telegram shows 'Max Gain: +19.73%' instead of '+.XX' - Fix: Changed from accountPnL (leverage-adjusted %) to currentPnLDollars - Lines 964-987: Removed accountPnL calculation, use currentPnLDollars 2. Duplicate Notification Bug: - handleExternalClosure() was checking if trade removed AFTER removal - Result: 16 duplicate Telegram notifications with compounding P&L - Example: 6 → 2 → 11 → ... → 81 (16 notifications for 1 close) - Fix: Check if trade already removed BEFORE processing - Lines 382-391: Move duplicate check to START of function - Early return prevents notification send if already processed 3. Database Compounding (NOT A BUG): - Nov 17 fix (Common Pitfall #49) still working correctly - Only 1 database record with 81 P&L - Issue was notification duplication, not DB duplication IMPACT: - MAE/MFE data now usable for TP/SL optimization - Telegram notifications accurate (1 per close, correct P&L) - Database analytics will show real dollar movements - Next trade will have correct Max Gain/Drawdown display FILES: - lib/trading/position-manager.ts: MAE/MFE calculation + duplicate check
This commit is contained in:
Reference in New Issue
Block a user