'timeChange() function returns with a yellow warning. What does it mean or simply how to fix it? Pine Script V5
isNewPeriod = anchor == "Earnings" ? new_earnings :
anchor == "Dividends" ? new_dividends :
anchor == "Splits" ? new_split :
na(src[1]) ? true :
anchor == "Session" ? timeChange("D") :
anchor == "Week" ? timeChange("W") :
anchor == "Month" ? timeChange("M") :
anchor == "Quarter" ? timeChange("3M") :
anchor == "Year" ? timeChange("12M") :
anchor == "Decade" ? timeChange("12M") and year % 10 == 0 :
anchor == "Century" ? timeChange("12M") and year % 100 == 0 :
false
Warning is: The function 'timeChange' should be called on each calculation for consistency. It is recommended to extract the call from the ternary operator or from the scope.
The interesting thing is: the PineScript Manual doesn't even know this timechange() function, neither V4 nor V5.
Solution 1:[1]
So, by calling that functions within the ternary operators, you are breaking the history and consistency. Not all those functions will be called on each execution.
If you want to fix the warning, use those functions in the global scope, assign their results to a variable and use those variables in the ternary operator instead.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vitruvius |
