Glossary

What is repainting in Pine Script?

Repainting is script behaviour that makes the calculations or plots of a Pine Script behave differently on historical bars than on real-time bars.

A historical bar is finished: its open, high, low and close are fixed. A real-time bar is still forming, and its high, low and close change with every price update. Not all repainting is harmful: an RSI on the live candle moves until the candle closes, which is fine as long as you know it.

The dangerous kind feeds a backtest information it could not have had – lookahead bias. Common causes are request.security() calls, the settings calc_on_every_tick, calc_on_order_fills and process_orders_on_close, and pivots drawn on a bar before they were confirmed. The reload test shows it: note the live signals, reload the chart and compare.

In practice

In our repainting guide, a script reads the daily high on a 4h BTC/USDT chart. At 04:00 UTC the historical bar sees the day’s final high of 61,500 and buys; the real-time bar sees the high so far, 60,150, and does nothing.

Illustrative numbers from the post, not a backtest result.

Read more

Topic: Data pitfalls

Part of the guide: Overfitting and luck

Sources