Have you ever noticed that an indicator which looked perfect in historical data suddenly fails you in live trading? You're likely dealing with a 'repainting' indicator, a common issue where indicators change their historical data based on new price information. This phenomenon affects over 95% of trading indicators, including popular ones like MACD and RSI, often leading to misleading signals and distorted trading decisions. In this comprehensive guide, we will explore what causes repainting, how it impacts your trading strategies, and practical techniques to detect and minimize its effects, ensuring your trading decisions are based on accurate and reliable information.
The most common factors are:
security()
function in Pine ScriptRepainting in TradingView indicators primarily arises from the methodology used in computing and presenting data, which can differ significantly between real-time and historical chart views. A prevalent cause of repainting is the use of the security()
function within Pine Script. This function is employed to import data from different time frames into a single script. For instance, when an indicator uses security()
to retrieve a higher time frame's closing price for calculations in a lower time frame, the lower time frame indicator values can change until the higher time frame bar completes. This continual adjustment of the indicator's past values on the chart as new data becomes available leads to repainting, thus potentially misleading traders about the historical accuracy and reliability of the indicator.
Another significant contributor to repainting is applying indicators on Heikin-Ashi candles, along with calculations based on real-time bar data. Heikin-Ashi candles are designed to smooth out price movements by modifying standard price data, thereby simplifying the visualization of trends. However, this smoothing can distort the accuracy of real-time price information, leading indicators applied to these candles to revise previous values with incoming data. Additionally, indicators that calculate values based on the open, high, low, and close of real-time bars face a similar challenge; these values remain tentative and fluctuate until the bar officially closes. This aspect can cause temporary and potentially misleading values in the indicators, which traders might erroneously interpret as stable historical data.
Repainting in trading indicators can have significant adverse effects on trading decisions, primarily because it creates a false impression of an indicator's reliability and effectiveness in historical analysis. Traders who rely on these indicators for making entry and exit decisions might see perfect signals in a historical chart, which seemingly predict market movements with high accuracy. However, these signals may shift or disappear as new data comes in, leading to potentially disastrous trading decisions based on inaccurate information. This discrepancy between historical and real-time data can cause traders to misjudge the strength and direction of market trends, resulting in misplaced trust in the predictive capabilities of their trading strategies.
Furthermore, the effects of repainting can extend to automated trading systems, where algorithms act on signals generated by these indicators. If a trading strategy is backtested using repainted data, it will likely show highly favorable results that are not achievable in live trading. This can lead to a strategy being over-optimized for specific historical conditions that do not accurately represent future market behavior, thus setting unrealistic expectations for the system's performance. For traders, this often translates into increased risk exposure and potential financial losses, as the system fails to adapt to or accurately predict real market changes.
To effectively detect repainting in trading scripts, it's important to understand and identify the four common categories of repainting behavior. Here's how each type can be analyzed:
This type of repainting occurs when an indicator recalculates its values as the current bar is still forming, which means the indicator's value can change multiple times before the bar closes. To detect this, traders can use live testing or the "bar replay" feature on platforms like TradingView. This allows the observation of how indicator values change in real-time. If values remain unstable throughout the formation of the bar and then settle only once the bar closes, this indicates recalculation repainting, which can mislead real-time decision-making.
Indicators that repaint by plotting past data differently as new data arrives can significantly distort a trader's perception of market conditions. To uncover this, traders should scrutinize the historical data on a chart after refreshing or reloading the page. If historical indicator values change after a refresh, it is a clear sign of misleading plotting. This test helps in verifying whether past signals that appeared solid are actually false once new price data is considered.
Some scripts attempt to enhance their accuracy by incorporating future data into their current calculations, which is considered a deceptive practice in trading. Reviewing the Pine Script code for functions like security()
is vital here. The script should be checked to ensure it doesn't pull in future data that would only be available after the current bar has closed. Proper coding should ensure that data used for generating signals strictly corresponds to information that was historically available at that moment in time, without forecasting or assuming future conditions.
Certain repainting cannot be avoided, such as when historical price feeds are updated or corrected by data providers, or when the starting point of historical data on a chart changes. Detecting this requires understanding from the data feed and exchange documentation about how often data revisions occur and acknowledging these changes in the script’s logic. Traders should be aware that under these circumstances, some level of repainting is inevitable and should adjust their strategy accordingly to accommodate these data irregularities.
Another way to check for repainting, if you don’t have the bar replay tool, is to set up the strategy with TradersPost and watch the trades come through. If a trade was executed and shows up in TradersPost, but suddenly disappears from the TradingView window after the fact, then you have a repainting issue and should investigate further.
To minimize the effects of repainting, traders can employ several strategic approaches that enhance the reliability of their trading scripts and indicators. One effective strategy is to adjust the script to only use data from closed bars for calculations, rather than incorporating values from the current, unconfirmed bar. This approach ensures that the indicator's values are based on stable, confirmed data, reducing the likelihood of values changing retrospectively. For example, using the close[1]
instead of close
in Pine Script ensures that only the last confirmed closing price is used in calculations, thus eliminating the impact of ongoing market fluctuations within the current bar.
Another strategy involves simplifying the indicator logic to rely less on complex or layered data calls, especially from multiple time frames. By reducing dependency on functions like security()
that fetch data from higher time frames, traders can decrease the risk of repainting caused by the delayed closure of these time frame bars. If using multi-timeframe data is necessary, ensuring that these calls are designed to fetch only historical confirmed data will help. Additionally, embedding checks within the script to confirm the integrity and confirmation status of data before it is used in live trading conditions can further protect against repainting, maintaining both the accuracy and trustworthiness of trading signals generated by the script.
Exploring non-repainting alternatives is an essential strategy for traders who prioritize accuracy and reliability in their technical analysis. Non-repainting indicators, such as moving averages, standard deviation, or oscillators like RSI and Stochastic that do not alter their values once formed, offer a consistent view of market conditions and trends. These indicators are based on confirmed data points only, ensuring that their historical signals remain unchanged irrespective of future data. Employing these types of indicators can enhance a trading strategy by providing trustworthy signals that support solid decision-making based on stable historical performance, thus avoiding the pitfalls of retroactively altered signals that are common with repainting indicators.
Traders can also consider building or modifying their own custom scripts to avoid repainting. This involves designing scripts that strictly refrain from using future-looking functions and ensuring all calculations are based on historical data that has been fully confirmed and is immutable. Additionally, engaging with the community to share and discuss non-repainting strategies can be incredibly beneficial. Many experienced traders and programmers are often willing to share insights and code snippets that adhere to non-repainting principles. Such collaboration not only aids in refining one's trading approach but also contributes to a broader understanding and application of effective trading tools within the trading community.
Still unsure if your strategy or indicator repaints? Join us on Discord and share your TradingView URL.
REFERENCES:
https://www.tradingview.com/pine-script-docs/en/v5/concepts/Repainting.html
DISCLAIMER:
Trading in the financial markets involves a significant risk of loss. The content and strategies shared by TradersPost are provided for informational or educational purposes only and do not constitute trading or investment recommendations or advice. The views and opinions expressed in the materials are those of the authors and do not necessarily reflect the official policy or position of TradersPost.
Please be aware that the authors and contributors associated with our content may hold positions or trade in the financial assets, securities, or instruments mentioned herein. Such holdings could present a conflict of interest or influence the perspective provided in the content. Readers should consider their financial situation, objectives, and risk tolerance before making any trading or investment decisions based on the information shared. It is recommended to seek advice from a qualified financial advisor if unsure about any investments or trading strategies.
Remember, past performance is not indicative of future results. All trading and investment activities involve high risks and can result in the loss of your entire capital. TradersPost is not liable for any losses or damages arising from the use of this information. All users should conduct their own research and due diligence before making financial decisions.