From 324e5ba0025f2d48cdc14db5d76c3e1937920a43 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Sat, 15 Nov 2025 11:06:44 +0100 Subject: [PATCH] refactor: Rename breakEvenTriggerPercent to profitLockAfterTP1Percent for clarity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Renamed config variable to accurately reflect behavior (locks profit, not breakeven) - Updated log messages to say 'lock +X% profit' instead of misleading 'breakeven' - Maintains backwards compatibility (accepts old BREAKEVEN_TRIGGER_PERCENT env var) - Updated .env with new variable name and explanatory comment Why: Config was named 'breakeven' but actually locks profit at entry ± X% For SHORT at $141.51 with 0.3% lock: SL moves to $141.08 (not breakeven $141.51) This protects remaining runner position after TP1 by allowing small profit giveback Files changed: - config/trading.ts: Interface + default + env parsing - lib/trading/position-manager.ts: Usage + log message - .env: Variable rename with migration comment --- .env | 2 +- config/trading.ts | 8 ++++---- lib/trading/position-manager.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 5d1b975..741f1fd 100644 --- a/.env +++ b/.env @@ -129,7 +129,7 @@ EMERGENCY_STOP_PERCENT=-2 # Dynamic stop-loss adjustments # Move SL to breakeven when profit reaches this level -BREAKEVEN_TRIGGER_PERCENT=0.3 +PROFIT_LOCK_AFTER_TP1_PERCENT=0.3 # Lock this % profit on remaining position after TP1 (was BREAKEVEN_TRIGGER_PERCENT) # Lock in profit when price reaches this level PROFIT_LOCK_TRIGGER_PERCENT=1 diff --git a/config/trading.ts b/config/trading.ts index fcf12f9..dd76693 100644 --- a/config/trading.ts +++ b/config/trading.ts @@ -40,7 +40,7 @@ export interface TradingConfig { hardStopPercent: number // Hard stop trigger (e.g., -2.5) // Dynamic adjustments - breakEvenTriggerPercent: number // When to move SL to breakeven + profitLockAfterTP1Percent: number // Lock this % profit on remaining position after TP1 profitLockTriggerPercent: number // When to lock in profit profitLockPercent: number // How much profit to lock @@ -132,7 +132,7 @@ export const DEFAULT_TRADING_CONFIG: TradingConfig = { hardStopPercent: -2.5, // Hard stop (TRIGGER_MARKET) // Dynamic adjustments - breakEvenTriggerPercent: 0.4, // Move SL to this profit level after TP1 hits + profitLockAfterTP1Percent: 0.4, // Lock this % profit on remaining position after TP1 profitLockTriggerPercent: 1.0, // Lock profit at +1.0% profitLockPercent: 0.4, // Lock +0.4% profit @@ -482,8 +482,8 @@ export function getConfigFromEnv(): Partial { ? parseFloat(process.env.MAX_TP2_PERCENT) : undefined, - breakEvenTriggerPercent: process.env.BREAKEVEN_TRIGGER_PERCENT - ? parseFloat(process.env.BREAKEVEN_TRIGGER_PERCENT) + profitLockAfterTP1Percent: process.env.PROFIT_LOCK_AFTER_TP1_PERCENT || process.env.BREAKEVEN_TRIGGER_PERCENT + ? parseFloat(process.env.PROFIT_LOCK_AFTER_TP1_PERCENT || process.env.BREAKEVEN_TRIGGER_PERCENT!) : undefined, profitLockTriggerPercent: process.env.PROFIT_LOCK_TRIGGER_PERCENT ? parseFloat(process.env.PROFIT_LOCK_TRIGGER_PERCENT) diff --git a/lib/trading/position-manager.ts b/lib/trading/position-manager.ts index 48abf7f..132401a 100644 --- a/lib/trading/position-manager.ts +++ b/lib/trading/position-manager.ts @@ -708,13 +708,13 @@ export class PositionManager { trade.currentSize = trade.positionSize * ((100 - this.config.takeProfit1SizePercent) / 100) const newStopLossPrice = this.calculatePrice( trade.entryPrice, - this.config.breakEvenTriggerPercent, // Use configured breakeven level + this.config.profitLockAfterTP1Percent, // Lock profit on remaining position trade.direction ) trade.stopLossPrice = newStopLossPrice trade.slMovedToBreakeven = true - console.log(`🔒 SL moved to +${this.config.breakEvenTriggerPercent}% (${this.config.takeProfit1SizePercent}% closed, ${100 - this.config.takeProfit1SizePercent}% remaining): ${newStopLossPrice.toFixed(4)}`) + console.log(`🔒 SL moved to lock +${this.config.profitLockAfterTP1Percent}% profit (${this.config.takeProfit1SizePercent}% closed, ${100 - this.config.takeProfit1SizePercent}% remaining): ${newStopLossPrice.toFixed(4)}`) // CRITICAL: Cancel old on-chain SL orders and place new ones at updated price // BUT: Only if this is the ONLY active trade on this symbol