Historical data doesn’t include records of intra-bar movements of price. This leads to a script working differently on historical data and at real-time. If we add a script on a chart, wait till it calculates on some number of real-time bars and then reload the page, we can see this difference. This peculiarity is called Indicator repainting. Not all indicators have an effect of repainting. In most cases it depends on whether or not some certain functions or language constructs are used in the code. This document reveals this question in detail.
We can see repainting in the following cases:
Strategies with parameter calc_on_every_tick
set to true
.
A strategy with parameter calc_on_every_tick = false
will be
prone to repainting too (though to a lesser degree) as any strategy
depends on a starting point, more on this below.
Using security
for requesting data with a resolution higher than the resolution of chart main symbol:
// Add this study on 1 minute chart
//@version=3
study("My Script")
c = security(tickerid, "5", close)
plot(close)
plot(c, color=red)
Such a study will be calculated differently at real-time and on
historical data, regardless of using the parameter lookahead
(see
Understanding lookahead).
Using security
for requesting data with resolution lower than the resolution of chart main symbol
(this case in more detail here).
if lookahead=false
, there will be repainting. When lookahead=true
,
repainting is less possible. It still could happen, when 1 and 5 minute updates
outrun each other.
All the scripts which calculation results depend on a starting point. Intraday data gets aligned to the beginning of the week, month or a year, depending on the resolution. Due to this, the results produced by such scripts can differ from time to time. Here are the examples of scripts relying on the starting point:
calc_on_every_tick
).There is a dependency between the alignment of a starting point and resolution:
The following limitations of history length are taken into account when processing the data:
Changes in historical data, for example, due to a split.
Presence of the following variables in the script usually leads to repainting:
The “repainting” issue usually occurs when using tools above — since an indicator is calculated based on real-time data first. After reloading the chart, an indicator is REcalculated using the data that had become a historical data, while still using the same time period. The appearance of the indicator changes.
In this case, the “repainting” effect is not a bug — it’s a result of applying certain language tools with different calculation methods. This needs to be understood and taken into consideration while using Pine Script.