N003
null needs an explicit type
Severity Error
A bare null was used where no type can be inferred from context, for example state peak = null or let x = null. The compiler cannot tell whether it is meant to be a float?, a time? or something else.
Add a type annotation (state peak: float? = null), or use the null where the expected type is known, such as a typed parameter or the other branch of a ternary.
Failing example
script "Swing memory"
data chart = subscribe(data.ohlcv)
state lastPivot = null
plot level = plot.line(title: "Last pivot high", style: linestyle.step)
on chart.close {
let p = ta.pivotHigh(chart.high, 3, 3)
if p != null {
lastPivot = p
}
level.plot(lastPivot)
}Fixed example
script "Swing memory"
data chart = subscribe(data.ohlcv)
state lastPivot: float? = null
plot level = plot.line(title: "Last pivot high", style: linestyle.step)
on chart.close {
let p = ta.pivotHigh(chart.high, 3, 3)
if p != null {
lastPivot = p
}
level.plot(lastPivot)
}