T216
value cannot be reassigned
Severity Error
An assignment targets a binding that is immutable: a let local, an input, a setup value, a data subscription or a function. Only state variables (and their fields and elements) can change after initialisation.
Declare the value as state if it has to change between bars, or introduce a new let with a different name for a derived value.
Failing example
script "Adaptive threshold"
data (
chart = subscribe(data.ohlcv)
liq = subscribe(data.liquidations)
)
setup threshold = 1_000_000.0
plot hit = plot.marker(title: "Liq above threshold", shape: shape.diamond)
on chart.close {
let total = liq.total ?? 0.0
if total > threshold {
hit.plot(chart.high)
threshold *= 1.1
}
}Fixed example
script "Adaptive threshold"
data (
chart = subscribe(data.ohlcv)
liq = subscribe(data.liquidations)
)
state threshold: float = 1_000_000.0
plot hit = plot.marker(title: "Liq above threshold", shape: shape.diamond)
on chart.close {
let total = liq.total ?? 0.0
if total > threshold {
hit.plot(chart.high)
threshold *= 1.1
}
}