diff --git a/frontend/src/components/charts/horizon.tsx b/frontend/src/components/charts/horizon.tsx index 04e3011..e9609fb 100644 --- a/frontend/src/components/charts/horizon.tsx +++ b/frontend/src/components/charts/horizon.tsx @@ -378,16 +378,15 @@ export function TradeChart({ // it wanders left as more post-entry bars arrive. const WINDOW = 21; const MID = 10; - let start: number; - let entryIdx: number; - if (postCount <= MID + 1) { - start = Math.max(0, entryAbs - MID); - entryIdx = entryAbs - start; - } else { + const start = postCount <= MID + 1 + ? Math.max(0, entryAbs - MID) // Enough history: keep the latest WINDOW bars; entry falls where it falls. - start = Math.max(0, bars.length - WINDOW); - entryIdx = entryAbs - start; - } + : Math.max(0, bars.length - WINDOW); + // A trade older than the window entered before the first visible bar. Clamp to + // the left edge — a negative index reads past the start of `series`/`stopPath` + // and NaNs out the price and trail paths entirely. + const entryBeforeWindow = entryAbs < start; + const entryIdx = Math.max(0, entryAbs - start); const windowBars = bars.slice(start); const series = windowBars.map((b) => b.close); if (series.length < 2) return null; @@ -601,7 +600,11 @@ export function TradeChart({ {entryIdx === lastIdx && ( )} - + {/* Entry marker only when the entry bar is actually in the window — for an + older trade the entry level line carries it instead. */} + {!entryBeforeWindow && ( + + )} );