Reputation: 1
I'm working on a TradingView strategy that relies on multiple time frames and different financial symbols for additional trading conditions. I'm using Pine Script v5 for this. My concern is about the dreaded issue of repainting, as the strategy involves fetching data from different time frames and symbols.
Here's a snippet of the code related to fetching data from different time frames and symbols:
//@version=5
// Function to avoid repainting while using the security function
f_security(_sym, _res, _src, _rep) =>
request.security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
// Fetching data
thirtyMinuteClose = f_security(syminfo.tickerid, str.tostring(Interval), close, false)
I want to avoid repainting at all costs, and I'm trying to be cautious with the functions I use, particularly the f_security function, which is essentially a wrapper for request.security.
My questions are:
Is the f_security function susceptible to repainting? If yes, how can I modify it to avoid repainting?
Should I consider using ta.valuewhen instead of f_security for certain conditions?
I've implemented the f_security function in my Pine Script code as a wrapper for request.security, aiming to fetch data from different time frames and symbols to use in my trading strategy. My expectation is that this would allow me to incorporate more complex conditions for trade entries and exits without causing repainting issues.
However, after setting up alerts based on the strategy, I've noticed that the alerts are not always in correlation with the backtest results. This makes me suspect that the script may be subject to repainting.
I'm seeking guidance on how to best structure this part of the code to avoid any repainting issues while still being able to rely on data from multiple time frames and symbols.
Upvotes: 0
Views: 1883
Reputation: 1
I ran into the same issue. This link was quite helpful: https://www.tradingview.com/script/cyPWY96u-How-to-avoid-repainting-when-using-security-PineCoders-FAQ/
I think you need to convert all your timeframes to minutes or seconds the indicator above has code that allows to do that.
Upvotes: 0