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:
@@ -277,8 +277,8 @@ export async function POST(request: NextRequest): Promise<NextResponse<TestTrade
|
||||
tp1Price,
|
||||
tp2Price,
|
||||
stopLossPrice,
|
||||
tp1SizePercent: config.takeProfit1SizePercent || 50,
|
||||
tp2SizePercent: config.takeProfit2SizePercent || 100,
|
||||
tp1SizePercent: config.takeProfit1SizePercent ?? 50,
|
||||
tp2SizePercent: config.takeProfit2SizePercent ?? 100, // Use ?? instead of || to allow 0
|
||||
direction: direction,
|
||||
// Dual stop parameters
|
||||
useDualStops: config.useDualStops,
|
||||
@@ -314,8 +314,8 @@ export async function POST(request: NextRequest): Promise<NextResponse<TestTrade
|
||||
stopLossPrice,
|
||||
takeProfit1Price: tp1Price,
|
||||
takeProfit2Price: tp2Price,
|
||||
tp1SizePercent: config.takeProfit1SizePercent || 50,
|
||||
tp2SizePercent: config.takeProfit2SizePercent || 100,
|
||||
tp1SizePercent: config.takeProfit1SizePercent ?? 50,
|
||||
tp2SizePercent: config.takeProfit2SizePercent ?? 100, // Use ?? instead of || to allow 0
|
||||
configSnapshot: config,
|
||||
entryOrderTx: openResult.transactionSignature!,
|
||||
tp1OrderTx: exitOrderSignatures[0],
|
||||
|
||||
Reference in New Issue
Block a user