Fix runner system + strengthen anti-chop filter
Three critical bugs fixed: 1. P&L calculation (65x inflation) - now uses collateralUSD not notional 2. handlePostTp1Adjustments() - checks tp2SizePercent===0 for runner mode 3. JavaScript || operator bug - changed to ?? for proper 0 handling Signal quality improvements: - Added anti-chop filter: price position <40% + ADX <25 = -25 points - Prevents range-bound flip-flops (caught all 3 today) - Backtest: 43.8% → 55.6% win rate, +86% profit per trade Changes: - lib/trading/signal-quality.ts: RANGE-BOUND CHOP penalty - lib/drift/orders.ts: Fixed P&L calculation + transaction confirmation - lib/trading/position-manager.ts: Runner system logic - app/api/trading/execute/route.ts: || to ?? for tp2SizePercent - app/api/trading/test/route.ts: || to ?? for tp1/tp2SizePercent - prisma/schema.prisma: Added collateralUSD field - scripts/fix_pnl_calculations.sql: Historical P&L correction
This commit is contained in:
@@ -25,7 +25,8 @@ model Trade {
|
||||
entryPrice Float
|
||||
entryTime DateTime
|
||||
entrySlippage Float?
|
||||
positionSizeUSD Float
|
||||
positionSizeUSD Float // NOTIONAL position size (with leverage)
|
||||
collateralUSD Float? // ACTUAL margin/collateral used (positionSizeUSD / leverage)
|
||||
leverage Float
|
||||
|
||||
// Exit targets (planned)
|
||||
|
||||
Reference in New Issue
Block a user