diff --git a/lib/trading/position-manager.ts b/lib/trading/position-manager.ts index b2a6f78..17e4bf8 100644 --- a/lib/trading/position-manager.ts +++ b/lib/trading/position-manager.ts @@ -1121,14 +1121,15 @@ export class PositionManager { trade.peakPnL = trade.unrealizedPnL } - // Track MAE/MFE in DOLLAR amounts (not percentages!) - // CRITICAL: Database schema expects DOLLARS for analysis and TP/SL optimization - if (currentPnLDollars > trade.maxFavorableExcursion) { - trade.maxFavorableExcursion = currentPnLDollars + // Track MAE/MFE in PERCENTAGE (not dollars!) + // CRITICAL FIX (Nov 23, 2025): Schema expects % (0.48 = 0.48%), not dollar amounts + // Bug was storing $64.08 when actual was 0.48%, causing 100× inflation in analysis + if (profitPercent > trade.maxFavorableExcursion) { + trade.maxFavorableExcursion = profitPercent trade.maxFavorablePrice = currentPrice } - if (currentPnLDollars < trade.maxAdverseExcursion) { - trade.maxAdverseExcursion = currentPnLDollars + if (profitPercent < trade.maxAdverseExcursion) { + trade.maxAdverseExcursion = profitPercent trade.maxAdversePrice = currentPrice }