If your Pine Script indicator works flawlessly in backtests but fails in real time, congratulations: you've just fallen for the repaint trap.
And 90% of traders have no idea it's happening.
Let’s talk about the kind of heartbreak you don’t see coming.
You build or buy an indicator.
You backtest it.
You’re excited. The signals look beautiful. Entries? Flawless. Exits? Timed like a sniper.
So you go live.
And then… it fails.
Not once. But every damn time.
Sound familiar?
You're not cursed. You didn’t mess up your strategy.
The problem is more sinister — and baked directly into how Pine Script handles chart data.
Welcome to repainting.
🧠 What Repainting Really Means (And Why It’s Worse Than You Think)
Most new traders think repainting just means “it adjusts after the candle closes.”
No. That’s lag — or confirmation.
Repainting is when the script literally rewrites history.
It shows you signals that didn’t actually happen at that point in time.
Here’s how it tricks you:
-
In backtest mode, Pine Script uses all data — including future candles.
-
In real-time, that future data isn’t available yet.
-
Result: your perfect signal disappears, or comes in late, or never shows up live.
It’s like your indicator is time-traveling… until you actually trade.
⚠️ Real-World Example: The RSI Crossover Illusion
Let’s say you write a simple RSI crossover script:
Looks clean. Signals fire on overbought moves.
Backtest is amazing.
But unless you're using ta.crossover() with confirmed candle logic, you're seeing entries based on a value that might have never crossed live — it was just peeking above 70 mid-candle.
Your backtest assumed that the candle finished above 70. But in real life, it didn’t.
Boom. That’s repainting.
🔍 How to Spot Repainting (Before You Lose Real Money)
Most people don’t realize an indicator repaints until it’s too late. But there are clear signs:
🔹 1. Your strategy looks too good to be true
10 wins, 0 losses? 90% win rate? That’s not strategy — that’s a time-traveling chart lie.
🔹 2. Signals disappear or move when you reload the chart
If your indicator fires on a candle, then vanishes after refresh — it’s rewriting history.
🔹 3. Uses close, high, low without confirmation logic
This means it may be referencing price before the candle actually finishes forming.
🔹 4. Backtest results don’t match actual alerts
The live trading behavior never matches the glorious past. That’s the ghost of repainting.
✅ How to Fix It — And Make Your Pine Script Trustworthy
Here’s the antidote.
🔒 Use bar_index or barstate.isconfirmed
Only trigger signals on confirmed candle closes:
🔒 Avoid plotting future values
Don’t use offset = -1 or tricks that shift indicators forward — they only look good in hindsight.
🔒 Master request.security()
If using multi-timeframe logic, always explicitly set lookahead=barmerge.lookahead_on to avoid unintentional peeking.
🔒 Test in real-time playback
TradingView’s Bar Replay Mode is your friend. If your signals change in replay, your script isn’t safe.
💬 The Brutal Truth Most Coders Avoid
Pine Script is a double-edged sword.
It gives you control — but it doesn’t protect you from your own logic.
You can build a strategy that looks bulletproof.
You can optimize it for weeks.
But if you don’t understand how the data works under the hood, you’re setting yourself up for real-time failure and emotional burnout.
🧩 Final Thought: If You Don’t Code With Live Data In Mind, You’re Not Coding at All
Don’t chase signals that only exist in hindsight.
Don't trust an indicator just because it "looks good."
And don’t trade money based on backtests that haven’t been battle-tested live.
Every repainted signal is a fake promise.
And it’s not your fault — until you know better.

No comments:
Post a Comment