Anti-Repainting Safeguards
Understand what indicator repainting is, how Backtrex prevents it, and why your backtest results are reliable.
What is Repainting?
Repainting occurs when an indicator or strategy changes its historical signals after the fact. A signal that appeared to trigger a buy at a specific time may disappear or change when you look at the same chart later.
This is one of the most common sources of misleading backtest results. A strategy that looks highly profitable in backtesting may perform poorly in live trading because the signals it showed historically were modified after the price moved.
Common Causes of Repainting
Using Current Bar Data
Many indicators use the current bar's close price while the bar is still forming. The value changes with every tick until the bar closes, which means:
- A "buy" signal may appear mid-bar, then disappear by the time the bar closes
- Backtest engines that use final bar data will show the signal as if it were confirmed, but in live trading, you would have acted on an unconfirmed signal
Lookahead Bias
Some indicator calculations reference future data points. For example, a zigzag indicator needs to "look ahead" to find the next pivot, which means its historical values change as new data arrives.
Recalculating History
Certain indicators recalculate their entire history when new data arrives, effectively rewriting past signals.
How Backtrex Prevents Repainting
Confirmed Bar Data Only
Backtrex enforces a strict rule: all indicator calculations and signal evaluations use confirmed bar data only. Specifically:
- All price references use
close[1](the previous bar's confirmed close), notclose[0](the current forming bar) - No indicator can access the current bar's data for signal generation
- This ensures that every signal in your backtest existed and was visible at the time it triggered
No Lookahead
The backtest engine processes bars strictly in chronological order. At any given bar:
- Only past data is available
- Future bars are completely invisible to the calculation
- No indicator can reference data that would not have been available at that point in time
What This Means for You
When you see a buy signal at a specific bar in your Backtrex backtest:
- That signal was generated using only data available at the time
- The signal would have been visible to you if you were watching the chart live
- The same signal will appear if you export to TradingView and check the same bar
Verification Through Export
The Pine Script export feature provides an additional verification layer:
- Export your strategy and run it on TradingView
- Compare the signals and trade entries between Backtrex and TradingView
- The guaranteed less than 2% divergence confirms that anti-repainting is working correctly
Why This Matters
A strategy with realistic backtest results gives you:
- Confidence: What you see is what you would have experienced in live trading
- Accurate risk assessment: Drawdown and loss figures reflect real risk
- Reliable optimization: Parameter changes produce genuine improvements, not artifacts of repainting
Common Misconception
Some traders believe that using close[1] instead of close[0] means "missing" one bar. This is not a limitation. It is the only correct way to evaluate signals:
- In live trading, you can only act on a signal after the bar closes
- Using
close[0]would give you a signal based on data you cannot trade on in real-time - The one-bar "delay" is actually how real trading works