In fact, there are so many causes of the repainting problem in Pine scripts, especially in using different types and multiple time resolutions in the scripts. This study is to show how the repaint is happening and possible way to avoid repainting issues in the Pine scripts.
Use 1M normal in TV chart
Use 5M HA in the script
Plot the close price from the 5M HA to see how it is displayed in the 1M normal TV chart
Review the real-time plot and historical plot
res = input('5', "Candles resolution", type=resolution)
hacData = useHeikenAshi ? heikinashi(tickerid) : tickerid
plot(a, color=blue, color=blue, style=cross, linewidth=3)
plot(b, color=blue, style=circles, linewidth=4, transp=90)
- Use barstate.isrealtime to separate the close price from historical data or real-time data.
indexCurrTF = barstate.isrealtime ? 0 : 1
plot(d0, color=yellow, linewidth=3)
- Shift back 1 bar from the above close price - NO REPAINT