votungphan

CryptoSEE - Repainting Study

Description:
In fact, there are so many causes of the repainting problem in Pine scripts, especially in using different candlestick 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.

Setup:
Use 1M normal candlestick in TV chart
Use 5M HA candlestick in the script
Plot the close price from the 5M HA candlestick to see how it is displayed in the 1M normal candlestick TV chart
Review the real-time plot and historical plot


useHeikenAshi = input(true, "Use Heikin-ashi candlestick", type=bool)
res = input('5', "Candles resolution", type=resolution)
hacData = useHeikenAshi ? heikinashi(tickerid) : tickerid

  • Plot the 5M HA candlestick close price with lookahead_off - REPAINT
a = security(hacData, res, close, lookahead=barmerge.lookahead_off)
plot(a, color=blue, color=blue, style=cross, linewidth=3)

  • Plot the 5M HA candlestick close price with lookahead_on - REPAINT
b = security(hacData, res, close, lookahead=barmerge.lookahead_on)
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.
indexHighTF = barstate.isrealtime ? 1 : 0
indexCurrTF = barstate.isrealtime ? 0 : 1

  • Plot the 5M HA candlestick close price with lookahead_off - REPAINT at the last bar of the 1M normal candlestick chart.
d0 = security(hacData, res, close, lookahead=barmerge.lookahead_off)
plot(d0, color=yellow, linewidth=3)

  • Shift back 1 bar from the above close price - NO REPAINT
d = d0
plot(d, color=blue)
Rimuovi dagli script preferiti Aggiungi agli script preferiti
This has helped me a lot. Thanks!
Rispondi
I'm Still getting repaint??
Rispondi
votungphan Gazzafoonga
@Gazzafoonga, it would be no repaint if using correctly, please provide more info so that I can help :)
Rispondi
If you have a script with security(tickerid,'60',close,lookahead=barmerge.lookahead_off)

and you load 6 hour chart, will there be issues with backtesting?
Rispondi
@janor123, it would be no problem with the back-testing as you can see in the back-testing trades list the entry price would be similar as the 6 hours chart price. Also, i think it would be no repainting issue as the 60 minutes resolution of the security() is less than 6 hours (i.e. 360 minutes) resolution chart.
Rispondi
Home Screener azioni Screener forex Screener cripto Calendario economico Show Come funziona Caratteristiche Grafico Costi Regolamento Moderatori Soluzioni per broker & siti web Widget Librerie grafiche Libreria grafica leggera Centro di supporto Invita un amico Suggerisci funzionalità Blog & Novità Twitter
Profilo Impostazioni profilo Account e fatturazione Invita un amico I miei ticket di supporto Centro di supporto Idee pubblicate Follower Seguiti Messaggi Privati Chat Esci