diff --git a/lib/trading-logic.ts b/lib/trading-logic.ts index 280f452..0f4494d 100644 --- a/lib/trading-logic.ts +++ b/lib/trading-logic.ts @@ -109,16 +109,10 @@ export function computeDailyTarget( path = 'reduced_day'; } else { const maxDay = Math.max(...qualifyingDays.map((d) => d.pnl)); - const realTarget = maxDay / consistency; - const needed = realTarget - totalProfit; // consistency calc stays on dailyPnL totalProfit - - if (needed > maxDay) { - baseAmount = maxDay; - path = 'normal_day'; - } else { - baseAmount = Math.max(0, needed); - path = 'reduced_day'; - } + // Consistency-cap the daily target at maxDay (can't exceed maxDay without breaking consistency ratio). + // Let min-day block handle the lower bound and cappedByFuture logic. + baseAmount = maxDay; + path = 'normal_day'; } // --- Min-day reservation (only when minDayPnL is a positive value) --- @@ -139,9 +133,12 @@ export function computeDailyTarget( // Cap: don't take more than what's available after reserving future days const cappedByFuture = remaining - futureReserve; - // Target what's needed to stay on track for profitTarget (cappedByFuture), floored at minDayPnL unconditionally. - // If minDay × remainingDays >= remaining, we can coast on min-day (cappedByFuture < minDay → floor wins). - const amount = Math.max(effectiveMinDay, cappedByFuture); + // Target what's needed to stay on track for profitTarget (cappedByFuture), floored at minDayPnL. + // Cap at baseAmount when the consistency calc produced a positive value — ensures we don't + // exceed maxDay / (maxDay/consistency) constraint. When baseAmount is 0 (0/100% consistency + // or target already met), cappedByFuture drives the target directly. + const consistencyCap = baseAmount > 0 ? Math.min(baseAmount, cappedByFuture) : cappedByFuture; + const amount = Math.max(effectiveMinDay, consistencyCap); return { amount: Math.round(amount * 100) / 100, path }; }