OPEN-SOURCE SCRIPT
Daily Backtest Pivots

Problem with the built-in Pivot Points Standard indicator in backtesting/replay mode:
The default "Pivot Points Standard" indicator is excellent on live charts, but it becomes completely unusable for proper backtesting or bar-replay because it always calculates and displays the current day’s pivot points (P, R1, R2, S1, S2, etc.) using the high/low/close of the still-forming current day — even when you're replaying historical bars.
Example:
When replaying or backtesting September 8 at 08:00 (Asian session), the indicator already shows the final R1, R2, S1, S2 for the entire September 8 daily candle, even though in real trading at that moment you would have no idea where the day will close or what the final daily range will be. This creates massive look-ahead bias and makes any strategy that uses daily pivots impossible to test realistically.
Desired behavior (historical accuracy):
During backtesting or bar replay, the indicator should only plot:
The previous day’s completed pivot levels (which were actually known at the start of the current day)
NO current-day pivot levels at all (or only plot them after the daily candle is closed)
Many custom pivot scripts already do exactly this (they only show the prior day’s levels throughout the current day), which is why people abandon the built-in indicator for backtesting.
The default "Pivot Points Standard" indicator is excellent on live charts, but it becomes completely unusable for proper backtesting or bar-replay because it always calculates and displays the current day’s pivot points (P, R1, R2, S1, S2, etc.) using the high/low/close of the still-forming current day — even when you're replaying historical bars.
Example:
When replaying or backtesting September 8 at 08:00 (Asian session), the indicator already shows the final R1, R2, S1, S2 for the entire September 8 daily candle, even though in real trading at that moment you would have no idea where the day will close or what the final daily range will be. This creates massive look-ahead bias and makes any strategy that uses daily pivots impossible to test realistically.
Desired behavior (historical accuracy):
During backtesting or bar replay, the indicator should only plot:
The previous day’s completed pivot levels (which were actually known at the start of the current day)
NO current-day pivot levels at all (or only plot them after the daily candle is closed)
Many custom pivot scripts already do exactly this (they only show the prior day’s levels throughout the current day), which is why people abandon the built-in indicator for backtesting.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.