S001
live value used in setup
Severity Error
A setup value, a state initializer or a declaration argument reads something that only exists while a handler runs: a subscription field, a status flag such as chart.isLast, a state variable or the strategy position. Setup expressions are evaluated once, before the first bar is delivered, so there is nothing to read yet.
Compute the value inside a handler. If it must persist, declare it as state with a neutral starting value and assign it in the handler.
Failing example
script "Opening price"
data chart = subscribe(data.ohlcv)
setup firstOpen = chart.open
plot ref = plot.line(title: "First open")
on chart.close {
ref.plot(firstOpen)
}Fixed example
script "Opening price"
data chart = subscribe(data.ohlcv)
state firstOpen: float? = null
plot ref = plot.line(title: "First open")
on chart.close {
if firstOpen == null {
firstOpen = chart.open
}
ref.plot(firstOpen)
}