Markets — Replay Feature
Steps through historical OHLC candles one at a time on marketsReplayPage.tsx. Detects patterns on the growing visible window, filters them by type, and simulates trades in real time as the playhead advances.
Page layout:
<MarketsReplayPage>
<ReplayControls /> ← symbol, timeframe, date, playback, pattern filters
<ReplayChart /> ← lightweight-charts canvas
<ReplayActiveTradeBox /> ← live P&L (null-renders when no active trade)
<ReplayTradeLog /> ← completed trades table (null-renders when empty)
</MarketsReplayPage>
Redux State
All replay state lives in the replay slice (replaySlice.ts). It is isolated from the global ohlc slice — components must not cross-read between them.
| Field | Type | Default | Description |
|---|---|---|---|
symbol | string | 'EUR/USD' | Active symbol |
timeframe | Timeframe | '1h' | Active timeframe |
allCandles | OhlcCandle[] | [] | Full loaded candle set |
currentIndex | number | 0 | Replay playhead position |
isPlaying | boolean | false | Tick timer running |
speedMs | number | 500 | Ms per tick |
detectedPatterns | FrontendPattern[] | [] | Patterns on visible window |
emergingPatterns | EmergingPattern[] | [] | Emerging patterns on visible window |
replaySwingFilter | HarmonicPatternType[] | 'all' | 'all' | Swing / harmonic pattern filter |
replayCandlestickFilter | HarmonicPatternType[] | 'all' | 'all' | Candlestick pattern filter |
activeTrade | ReplayActiveTrade | null | null | Currently open simulated trade |
tradeLog | ReplayTradeLogEntry[] | [] | Completed simulated trades |
setReplayCandles resets currentIndex, detectedPatterns, emergingPatterns, replaySwingFilter, replayCandlestickFilter, activeTrade, and tradeLog.
Pattern Filter Multiselects
ReplayControls renders two PatternMultiSelect components — one for swing/harmonic patterns, one for candlestick patterns. These bind to replay-specific state, not the global ohlc filter state.
| Action | Selector |
|---|---|
setReplaySwingFilter | selectReplaySwingFilter |
setReplayCandlestickFilter | selectReplayCandlestickFilter |
Both useReplayChartPatternSync (chart overlays) and useReplayTradeSimulation (trade entry) read these selectors independently, so filtering affects both chart rendering and which patterns can trigger a simulated trade.
Simulated Trade Overlay
useReplayTradeSimulation is a side-effect hook called inside useReplayChart. It runs on every currentIndex or detectedPatterns change.
No active trade — scan for entry:
- Iterates
detectedPatterns; skips IDs already inprocessedIdsRef - Applies
replaySwingFilter/replayCandlestickFilter - Enters the first pattern whose
dTimematches the current candle’s Unix timestamp - Dispatches
setReplayActiveTrade; records the pattern ID so it is never re-entered - SL / TP levels come from the pattern’s pre-calculated
sl,tp1,tp2,tp3
Active trade — check for exit:
- Tests candle
high/lowagainst SL and all TP levels - If SL and a TP both trigger on the same candle, SL wins
- On exit:
addReplayTradeLogEntry→clearReplayActiveTrade - If no exit: updates
currentPipsfrom the current close price
useReplayChart syncs activeTrade to markersPlugin.updateActiveTrades() after every change, keeping entry / SL / TP lines on the chart in sync.
ReplayActiveTrade type
| Field | Type | Description |
|---|---|---|
patternType | HarmonicPatternType | Pattern that triggered entry |
direction | 'bullish' | 'bearish' | Trade direction |
entryPrice | number | D-point close price |
entryTime | number | D-point Unix timestamp |
sl / tp1 | number | Stop-loss / first take-profit |
tp2 / tp3 | number | null | Optional take-profit levels |
currentPips | number | Live P&L in pips (signed, 1 d.p.) |
ReplayActiveTradeBox component
Renders a horizontal bar below the chart. Hidden when activeTrade is null. Shows pattern label, direction chip (green = bullish / red = bearish), Entry / SL / TP1–3 prices, and live pips coloured green (positive) or red (negative).
Trade Log
Completed trades accumulate in tradeLog. The ReplayTradeLog component renders a compact MUI sticky-header table (newest first, max-height 200 px). Hidden when the log is empty.
| Column | Notes |
|---|---|
| Pattern | PATTERN_TYPE_LABELS[patternType] |
| Direction | colour chip |
| Entry | entryPrice to 5 d.p. |
| Exit | exitPrice to 5 d.p. |
| Outcome | TP1 / TP2 / TP3 chip (success) or SL chip (error) |
| Pips | signed, coloured |
ReplayTradeLogEntry type
| Field | Type | Description |
|---|---|---|
id | string | {patternType}-{entryTime}-{exitTime} |
patternType | HarmonicPatternType | |
direction | 'bullish' | 'bearish' | |
entryPrice / exitPrice | number | |
entryTime / exitTime | number | Unix timestamps |
outcome | 'tp1' | 'tp2' | 'tp3' | 'sl' | |
pips | number | Signed, rounded to 1 d.p. |