T301
type field has no type annotation
Severity Error
Every field of a user type needs an explicit type after a colon. Field types are never inferred, because the record layout is fixed before the script runs.
Add : Type to the field.
Failing example
script "Swing levels"
data chart = subscribe(data.ohlcv)
type Swing {
price
index: int
}
state last: Swing? = null
plot level = plot.line(title: "Last swing high", style: linestyle.step)
on chart.close {
let p = ta.pivotHigh(chart.high, 5, 5)
if p != null {
last = Swing { price: p, index: chart.index }
}
let s = last
level.plot(s != null ? s.price : null)
}Fixed example
script "Swing levels"
data chart = subscribe(data.ohlcv)
type Swing {
price: float
index: int
}
state last: Swing? = null
plot level = plot.line(title: "Last swing high", style: linestyle.step)
on chart.close {
let p = ta.pivotHigh(chart.high, 5, 5)
if p != null {
last = Swing { price: p, index: chart.index }
}
let s = last
level.plot(s != null ? s.price : null)
}