How to Avoid Repainting Signals in TradingView Strategies
The Complete Guide to Building Reliable TradingView Strategies for Automation and Mirrorpip
One of the most common reasons why a TradingView strategy performs exceptionally well during backtesting but fails during live trading is repainting. Many traders discover that signals shown on historical charts do not match the signals generated in real-time. A strategy that appears highly profitable in the Strategy Tester may produce completely different results once connected to an exchange through automation platforms such as Mirrorpip. Understanding and eliminating repainting is one of the most important steps when building reliable TradingView indicators, strategies, and automated trading systems. In this guide, we’ll explain what repainting is, why it happens, how to identify it, and the best practices to avoid repainting in TradingView Pine Script strategies.What is Repainting in TradingView?
Repainting occurs when a signal changes after a candle has closed or when historical signals appear differently than they would have in real-time. In simple terms: A strategy is repainting if it uses information that was not actually available at the time the signal was generated. This can result in:- Signals appearing earlier than they should
- Buy and sell markers moving after chart refresh
- Better backtest results than live performance
- Unrealistic win rates
- False confidence in strategy profitability
Why Repainting is Dangerous for Automated Trading
For manual traders, repainting can be misleading. For automated trading, repainting can be disastrous. Consider the following scenario:Historical Chart
Buy signal appears at:- Price: 100
- Entry: 100
- Exit: 110
- Profit: 10%
Real-Time Trading
The same signal only becomes valid after the candle closes:- Actual Entry: 104
- Actual Exit: 110
- Profit: 5.7%
Common Causes of Repainting
Most repainting issues come from one of the following sources:1. Using Open Candles
Signals generated while a candle is still forming can change before the candle closes.2. Multi-Timeframe Data
Improper use of higher timeframe data can cause signals to change retroactively.3. Future Data Leakage
Using information that would not have been available at the time of the signal.4. Tick-by-Tick Calculations
Strategies that calculate on every tick may behave differently in backtests and live trading.5. Improper Indicator Design
Some custom indicators are intentionally or unintentionally designed using future information.Best Practice #1: Generate Signals Only After Candle Close
This is the single most effective way to avoid repainting.Incorrect Approach
Generating signals during candle formation:Correct Approach
Wait for candle confirmation:Example: EMA Crossover Strategy
Repainting Version
Non-Repainting Version
Best Practice #2: Use Previous Candle Values
Many professional strategy developers prefer using completed candle data.Example
Instead of:- No intrabar changes
- Stable signals
- Consistent backtests
- Better live execution accuracy
Best Practice #3: Avoid Repainting with Multi-Timeframe Strategies
Multi-Timeframe (MTF) strategies are one of the biggest sources of repainting. Imagine:- Trading on a 5-minute chart
- Using a 1-hour Supertrend filter
Incorrect MTF Example
Correct MTF Example
Example: Multi-Timeframe Supertrend Strategy
Suppose your strategy requires:Long Conditions
- 5 Minute Supertrend = Bullish
- 15 Minute Supertrend = Bullish
- 1 Hour Supertrend = Bullish
Best Practice #4: Avoid Future Data References
Future data creates the worst form of repainting. Examples include:Best Practice #5: Be Careful with calc_on_every_tick
Many developers enable:- Open
- High
- Low
- Close
- Backtests behave differently
- Live signals behave differently
- Strategy results become inconsistent
Best Practice #6: Create Alerts Only After Candle Close
Many traders accidentally create repainting alerts.Risky Alert
Recommended Alert
Best Practice #7: Handle Heikin Ashi Correctly
Many traders use Heikin Ashi charts because they provide smoother trends. However, running a strategy directly on a Heikin Ashi chart can create unrealistic backtest results. A better approach is:- Use a normal candlestick chart
- Access Heikin Ashi values internally
- Generate signals from Heikin Ashi data
- Execute trades using real market prices