diff --git a/lib/trading-logic.ts b/lib/trading-logic.ts index 14fe8b2..d3f14c1 100644 --- a/lib/trading-logic.ts +++ b/lib/trading-logic.ts @@ -125,19 +125,24 @@ export function computeDailyTarget( // - 0% or 100%: no constraint // - Day 1 of cycle: max allowed = remaining × consistency // - Day 2+ of cycle: max allowed = maxDay (keeps consistency ratio stable) + // Always capped at profitTarget × consistency — the largest day the consistency + // rule would have allowed. Prevents a previous overshoot/loss from compounding. let consistencyCap: number; let path: 'first_day' | 'normal_day' | 'reduced_day'; if (consistency === 0 || consistency >= 1) { consistencyCap = Infinity; path = daysTraded === 0 ? 'first_day' : 'reduced_day'; - } else if (daysTraded === 0) { - consistencyCap = remaining * consistency; - path = 'first_day'; } else { - const maxDay = Math.max(...qualifyingDays.map((d) => d.pnl)); - consistencyCap = maxDay; - path = 'normal_day'; + const maxConsistencyDay = profitTarget * consistency; + if (daysTraded === 0) { + consistencyCap = Math.min(remaining * consistency, maxConsistencyDay); + path = 'first_day'; + } else { + const maxDay = Math.max(...qualifyingDays.map((d) => d.pnl)); + consistencyCap = Math.min(maxDay, maxConsistencyDay); + path = 'normal_day'; + } } // 4. Combine caps and apply min-day floor when mandatory days remain.