Does Your TradingView Strategy Repaint? A 7-Point Checklist
A strategy with a 90% win rate and a smooth equity curve is usually a script that cheats, not a market that is easy. The cheating is rarely on purpose: it comes from a handful of Pine Script habits that make the past look better than any live chart could. Here are the seven to check before you trust a backtest, each with what to look for in the code and how to fix it.
Trading · 2026-12-02 · 8 min read
What "repainting" means
A script repaints when the signals it shows on past bars are not the signals it would have shown live. On a historical chart every bar is finished, so the script sees final prices; in real time the current bar is still moving. If the code is not careful about that difference, signals appear, move or vanish after the fact, and the backtest is built on information you could never have had.
Tip: The quickest test: add the script to a chart, note its signals for an hour on a live market, then refresh the page. If old signals moved or new ones appeared in the past, it repaints.
1. Higher-timeframe data with look-ahead
The biggest source of fake results. request.security() with lookahead=barmerge.lookahead_on and no offset hands every intraday bar the final daily (or weekly) value, hours before that value existed.
// Leaks the future on historical bars
dailyClose = request.security(syminfo.tickerid, "D", close,
lookahead=barmerge.lookahead_on)
// Safe: yesterday's finished close, known from the start of today
dailyClose = request.security(syminfo.tickerid, "D", close[1],
lookahead=barmerge.lookahead_on)Look for: lookahead_on without [1] on the series. Fix: add the [1] offset as above, which is the pattern TradingView itself recommends for non-repainting higher-timeframe values.
2. Acting on a bar that has not closed
With the default lookahead_off, higher-timeframe values are honest on history but still change during the live bar. The same is true of any indicator on the current bar. A cross that appears mid-bar can disappear before the close, but an alert or order may already have fired.
// Only act once the bar is final
longSignal = ta.crossover(fast, slow) and barstate.isconfirmedLook for: calc_on_every_tick=true in strategy(), alerts set to "once per bar" instead of "once per bar close", and no barstate.isconfirmed. Historical bars are only ever calculated at their close, so tick-by-tick logic makes live trading behave differently from the backtest.
3. Pivots and zigzags drawn in the past
ta.pivothigh(high, 5, 5) can only confirm a pivot five bars after it happens. Scripts that plot it with offset=-5, or draw labels back on the pivot bar, look like they called the exact top. In real time the signal arrived five bars late, at a worse price.
Look for: negative offset= values, label.new(bar_index - n, …) and zigzag or "support and resistance" scripts that trade the pivot bar itself. Fix: trade on the bar where the pivot is confirmed, and plot it there too.
4. Fills you could never get
The strategy tester only knows each bar's open, high, low and close. Several settings let it assume the best price inside that range:
process_orders_on_close=truefills at the close of the signal bar. Not look-ahead, but optimistic: live, you usually get the next bar's open.- Limit orders count as filled the moment price touches them, even when there was no volume at that price.
- Stop and target on the same bar: the tester has to guess which came first. Turn on Bar Magnifier (Properties tab) so it uses lower-timeframe data instead of guessing.
5. Zero commission and slippage
In Pine Script, strategy() defaults to no commission and no slippage. A scalping strategy that trades 400 times a year can go from profitable to losing once real costs are in.
strategy("My strategy", overlay=true,
commission_type=strategy.commission.percent, commission_value=0.05,
slippage=2)Use your broker's real commission and at least a tick or two of slippage, then compare the results.
6. Sizing that hides risk
Some scripts look safe only because of how they size trades:
- Martingale or averaging down: adding to a losing position (
if strategy.openprofit < 0followed by another entry). It wins often, until one trend wipes out months of gains. - All-in sizing:
default_qty_value=100withpercent_of_equityrisks the whole account on every trade. - Fixed size with no stop: the loss on any trade is unlimited.
7. Exits that hide losing trades
This is how most "95% win rate" scripts are made. The exit only fires when the trade is in profit, so losers are never closed and never counted as losses.
// Only ever closes winners: losers stay open forever
if ta.crossunder(fast, slow) and strategy.openprofit > 0
strategy.close("Long")
// Honest: close on the signal, and always have a stop
if ta.crossunder(fast, slow)
strategy.close("Long")
strategy.exit("Stop", "Long", stop=strategy.position_avg_price * 0.98)Look for: exit conditions that mention openprofit, no strategy.exit with a stop, and the "Open P&L" figure in the tester's overview. A large open loss at the end of the backtest is the giveaway.
Checklist
| Check | Red flag in the code | Fix |
|---|---|---|
| Higher timeframe | lookahead_on without [1] | Use close[1] with lookahead_on |
| Unconfirmed bars | calc_on_every_tick=true, no barstate.isconfirmed | Act on bar close only |
| Pivots | Negative offset, labels drawn in the past | Trade where the pivot is confirmed |
| Fills | process_orders_on_close, limit fills on touch | Bar Magnifier, next-bar fills |
| Costs | No commission_value, no slippage | Add real costs |
| Sizing | Averaging down, 100% of equity | Fixed risk per trade, tied to the stop |
| Exits | Exit needs openprofit > 0, no stop | Always-on stop, exit on the signal |
Check a script in two minutes
Reading Pine Script line by line takes time, especially someone else's. AI Flowchart turns a Pine Script or MQL5 strategy into a flowchart of its entry, exit and stop rules, runs it bar by bar on sample prices, and its 🛡 Safety check goes through these seven points, showing the line and a fix for each one it finds. It checks the code only: it never says whether a strategy will make money.
Tip: Whatever a backtest shows, forward-test on a paper or demo account for a few weeks before you trade a script with real money. Nothing here is trading advice.
Frequently asked questions
How do I know if a TradingView indicator repaints?
Watch it live on a fast chart, note its signals, then refresh. If past signals moved or new ones appeared, it repaints. In the code, look for request.security with lookahead_on and no [1], negative plot offsets, and signals that do not wait for barstate.isconfirmed.
Does lookahead_off stop repainting?
It stops request.security from leaking future values into historical bars, but the higher-timeframe value still changes during the live bar. Use close[1] with lookahead_on, or wait for the bar to close, for signals that never change.
Why is my live trading worse than the backtest?
The usual reasons are repainting signals, fills at prices you could not get, missing commission and slippage, and exits that leave losing trades open in the backtest. Fix those in the script and the backtest usually drops to something closer to live results.
Can a strategy with no repainting still be a bad strategy?
Yes. Removing repainting only makes the backtest honest. Whether the strategy works is a separate question that only forward testing can answer.