CS3122
warning name changes on the chart bars (how), so a request cannot recompute it on the requested bars: there it is na (kw) or the chart’s current value. Compute it in a function called inside the request.
#What it means
This is a warning. Variables a request reads are normally recomputed on the requested bars. A variable declared with state, or one that is changed after its declaration, follows the chart's bars and cannot be recomputed there: the request sees na (for state) or the chart's current value.
#Typical cause
- A counter or other
statevariable, or a reassignedletvariable, used inside a request expression.
#How to fix it
Put the calculation in a function and call the function inside the request; it then runs on the requested bars with its own state. See Other timeframes and markets.
#Example
//@chartscript 1
indicator("Daily up streak")
state streak: int = 0
streak = close > open ? streak + 1 : 0
plot(request.tf("1D", streak))Fixed
//@chartscript 1
indicator("Daily up streak")
function upStreak() {
state n: int = 0
n = close > open ? n + 1 : 0
return n
}
plot(request.tf("1D", upStreak()))