Loading page…
Loading page…
Scan Pine Script code for lookahead_on, unconfirmed alerts, and MTF repainting bugs with verified TradingView Bar Replay comparisons.
Paste any Pine v5/v6 script to statically audit 5 high-risk repainting patterns in the browser (zero server upload).
strategy("Leaky MTF EMA", overlay = true, calc_on_every_tick = true)Fix: Set calc_on_every_tick = false so realtime execution matches historical bar-close Strategy Tester fills.
htfEma = request.security(syminfo.tickerid, "60", ta.ema(close, 21), lookahead = barmerge.lookahead_on)
Fix: Offset the requested series by [1] (e.g. ta.ema(close, 21)[1]) when using barmerge.lookahead_on, or switch to barmerge.lookahead_off.
alert("BUY " + syminfo.ticker)Fix: Guard alert() with `if cond and barstate.isconfirmed` or pass `alert.freq_once_per_bar_close` to prevent phantom mid-bar webhook triggers.
Identical 1H EMA(21) crossover executed on 15m BTCUSDT.P — only the request.security() offset changed.
| Scenario | Net Profit | Profit Factor | Max Drawdown | Win Rate | Trades | Observed Behavior |
|---|---|---|---|---|---|---|
| Leaky: lookahead_on (no [1] shift) | +168.4% | 2.74 | 9.2% | 71.8% | 312 | Reads final 60m close at minute 0 of each hour (impossible live). |
| Fixed: expr[1] + lookahead_on | +14.6% | 1.18 | 21.7% | 42.3% | 298 | Locks previous completed 60m bar; 100% reproducible in Bar Replay. |
| Default: lookahead_off (no [1] shift) | +11.2% | 1.14 | 22.4% | 41.6% | 301 | Historical bars wait for HTF close, but realtime intrabar value flickers until 60m closes. |
1//@version=62indicator("Leaky HTF EMA", overlay = true)3// BUG: Reads future 60m close on historical 15m bars 1, 2, and 34htfEma = request.security(5 syminfo.tickerid, "60", ta.ema(close, 21),6 lookahead = barmerge.lookahead_on7)8if ta.crossover(close, htfEma)9 alert("Crossed HTF EMA")1//@version=62indicator("Verified Non-Repainting HTF EMA", overlay = true)3// FIX: Index [1] locks the last completed 60m bar across history & live4f_htfNoRepaint(string tf, series float expr) =>5 request.security(6 syminfo.tickerid, tf, expr[1],7 gaps = barmerge.gaps_off,8 lookahead = barmerge.lookahead_on9 )10 11htfEma = f_htfNoRepaint("60", ta.ema(close, 21))12if ta.crossover(close, htfEma) and barstate.isconfirmed13 alert("Confirmed Cross HTF EMA", alert.freq_once_per_bar_close)