critical: Fix MFE/MAE storing dollars instead of percentages
Root Cause (Nov 23, 2025): - Database showed MFE 64.08% when TradingView showed 0.48% - Position Manager was storing DOLLAR amounts ($64.08) not percentages - Prisma schema comment says 'Best profit % reached' but code stored dollars - Bug caused 100× inflation in MFE/MAE analysis (0.83% shown as 83%) The Bug (lib/trading/position-manager.ts line 1127): - BEFORE: trade.maxFavorableExcursion = currentPnLDollars // Storing $64.08 - AFTER: trade.maxFavorableExcursion = profitPercent // Storing 0.48% Impact: - All quality 90 analysis was based on wrong MFE values - Trade #2 (Nov 22): Database showed 0.83% MFE, actual was 0.48% - TP1-only simulation used inflated MFE values - User observation (TradingView charts) revealed the discrepancy Fix: - Changed to store profitPercent (0.48) instead of currentPnLDollars ($64.08) - Updated comment to reflect PERCENTAGE storage - All future trades will track MFE/MAE correctly - Historical data still has inflated values (can't auto-correct) Validation Required: - Next trade: Verify MFE/MAE stored as percentages - Compare database values to TradingView chart max profit - Quality 90 analysis should use corrected MFE data going forward
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user