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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.