Backtest results (28 days): - Original: 32 trades, 43.8% win rate, -16.82 loss - New: 13 trades, 69.2% win rate, +49.99 profit - Improvement: +66.81 (+991%), +25.5% hit rate Changes: 1. Set MIN_SIGNAL_QUALITY_SCORE_LONG/SHORT=95 (was 90/85) 2. Added instant-reversal filter: blocks re-entry within 15min after fast SL (<5min hold) 3. Added 5-candle time exit: exits after 25min if MFE <0 4. HTF filter already effective (no Q≥95 trades blocked) Expected outcome: Turn consistent losses into consistent profits with 69% win rate
5.4 KiB
5.4 KiB
Forward Shadow Testing Plan
Objective
Validate Q≥95 + instant reversal + HTF + 5-candle exit strategy in real-time without risking capital before live deployment.
Shadow Mode Design
1. What Gets Logged
-
All incoming signals (5m timeframe, non-manual):
signalQualityScoredirection(long/short)- HTF alignment status (5m vs 15m BlockedSignal)
- Instant reversal flag (prior candle body reversal > threshold)
- Final decision:
WOULD_ENTER,BLOCKED_Q,BLOCKED_HTF,BLOCKED_INSTANT_REVERSAL,BLOCKED_OTHER
-
Simulated trade lifecycle:
- Entry price (current Pyth price at signal time)
- TP1/TP2/SL levels (ATR-based)
- Exit price and reason:
TP1,TP2,TRAILING_SL,SL,TIME_EXIT_5_CANDLE - Simulated PnL after fees/slippage (use 0.04% taker + 0.5% slippage estimate)
- Duration in candles
- MFE/MAE
2. Storage
- New table:
ShadowTradeCREATE TABLE "ShadowTrade" ( id TEXT PRIMARY KEY, "createdAt" TIMESTAMP NOT NULL DEFAULT NOW(), symbol TEXT NOT NULL, timeframe TEXT NOT NULL, direction TEXT NOT NULL, "signalQualityScore" INTEGER NOT NULL, "htfAligned" BOOLEAN NOT NULL, "instantReversalDetected" BOOLEAN NOT NULL, "wouldEnter" BOOLEAN NOT NULL, "blockReason" TEXT, "entryPrice" NUMERIC(20,8), "exitPrice" NUMERIC(20,8), "exitReason" TEXT, "simulatedPnL" NUMERIC(10,2), "durationCandles" INTEGER, "maxFavorableExcursion" NUMERIC(10,2), "maxAdverseExcursion" NUMERIC(10,2), "exitedAt" TIMESTAMP );
3. Implementation Steps
Step 1: Add Shadow Mode Flag
- ENV:
SHADOW_MODE=true - When true,
check-riskandposition-managerlog decisions but do not place orders.
Step 2: Instant Reversal Detection
- In
check-risk, before quality gate:- Fetch last completed 5m candle (from Pyth or cache).
- Compute body size:
abs(close - open). - Compute reversal: if signal is long and prior candle body was strong down (close < open and body > k·ATR), flag
instantReversalDetected=true. - Similarly for short.
- Suggested k=0.5 initially; tune based on results.
Step 3: HTF Alignment Check
- In
check-risk, after quality gate:- Fetch most recent 15m
BlockedSignaldirection. - If 5m signal direction == 15m blocked direction AND quality < 85, flag
htfBlocked=true. - Else
htfAligned=true.
- Fetch most recent 15m
Step 4: Shadow Entry Decision
- Combine checks:
wouldEnter = (Q >= 95) AND htfAligned AND !instantReversalDetected AND (other risk checks pass)- If
wouldEnter=false, setblockReasonand write toShadowTradewithentryPrice=null. - If
wouldEnter=true, write toShadowTradewithentryPriceand start shadow monitoring.
Step 5: Shadow Monitoring
- Position Manager polls every 10s:
- Fetch current Pyth price.
- Check TP1, TP2, SL, trailing SL (same logic as live).
- Check 5-candle time: if 25 minutes elapsed and MFE < $30, exit with
TIME_EXIT_5_CANDLE. - On exit, compute
simulatedPnL(with fees/slippage) and updateShadowTrade.
Step 6: Daily Reports
- Cron job or API endpoint
/api/trading/shadow-report:- Aggregate
ShadowTradeby day:- Total signals, would-enter count, per-block-reason counts.
- Win rate, avg PnL, total PnL, max drawdown.
- Per-direction breakdown.
- Push to Telegram or email.
- Aggregate
4. Validation Criteria (4–6 weeks, ≥100 trades)
Go criteria:
- Net simulated PnL > 0 after all costs.
- Win rate > 40% or expectancy > $5/trade.
- Max drawdown < 20% of starting capital.
- Return-to-drawdown > 1.0.
- Metrics stable across 2-week rolling windows.
No-go criteria:
- Net PnL < 0 or expectancy < 0.
- Max drawdown > 30%.
- Hit rate < 35% with large tail losses.
- Sensitivity tests show parameter brittleness.
5. Dashboard (Optional)
- Build Next.js page
/shadow-dashboard:- Real-time counters: signals today, would-enter today, blocked by reason.
- PnL chart: cumulative simulated equity curve.
- Table: last 20 shadow trades with entry/exit/PnL.
- Filters: date range, direction, block reason.
6. Rollout After Validation
- Disable shadow mode:
SHADOW_MODE=false. - Deploy unified Q≥95, instant reversal filter, HTF enforcement, 5-candle exit to live
check-riskandposition-manager. - Monitor live logs for first 48h with small position sizes.
- Compare live vs shadow metrics; revert if divergence or losses exceed kill-switch.
Files to Create/Edit
prisma/schema.prisma: AddShadowTrademodel.app/api/trading/check-risk/route.ts: Add instant reversal + HTF checks, shadow logging.lib/trading/position-manager.ts: Add shadow monitoring loop and 5-candle exit.app/api/trading/shadow-report/route.ts: Daily aggregation endpoint.app/shadow-dashboard/page.tsx: (Optional) Real-time UI..env: AddSHADOW_MODE=true.
Timeline
- Week 1: Implement shadow logging, instant reversal, HTF checks.
- Week 2: Deploy shadow mode; verify logging and first results.
- Weeks 3–6: Collect ≥100 shadow trades; daily review.
- Week 7: Validation decision; if pass, deploy live with small size.
- Week 8: Scale up if live matches shadow.
Risk Mitigations
- Shadow mode ensures no capital at risk during validation.
- Kill-switches remain active in live deployment.
- Telegram alerts for anomalies (slippage spikes, API errors, sudden drawdown).
- Rollback plan: revert to current thresholds (90 long / 85 short) within 5 minutes if loss > $50 in one day.