The one-line version: your backtest used information it couldn't have known at the time. So it looks brilliant on history — and falls apart live.
The most common source in Pine is request.security() pulling a higher-timeframe value with lookahead = barmerge.lookahead_on but no [1] offset. On historical bars, that hands your script the finished higher-timeframe value before that period actually closed — data from the future.
//@version=6
indicator("HTF bias")
// returns TODAY's daily close on bars from earlier in the day:
htf = request.security(syminfo.tickerid, "D", close, lookahead=barmerge.lookahead_on)Offset the series by [1] and keep lookahead_on — per TradingView's docs they're meant to be used together. Now you only ever see the last confirmed higher-timeframe value.
htf = request.security(syminfo.tickerid, "D", close[1], lookahead=barmerge.lookahead_on)
A backtest that looks too good is the symptom; this is usually the cause. Paste your script into the ForexCodes Validator and it flags look-ahead bias (and repainting) instantly.
Educational only — not financial advice. Trading involves substantial risk of loss.