P011
top-level statement is not a declaration
Severity Error
At file level only declarations are allowed: input, data, state, setup, plot, fill, pane, window, alert, strategy, type, fn and on. An executable statement such as a call, an assignment or an if was found outside any handler or function.
Move the statement into a handler. Code that should run only once can be placed in a handler and guarded with chart.isFirst.
Failing example
script "Startup note"
data chart = subscribe(data.ohlcv)
plot c = plot.line(title: "Close")
log.info("script loaded")
on chart.close {
c.plot(chart.close)
}Fixed example
script "Startup note"
data chart = subscribe(data.ohlcv)
plot c = plot.line(title: "Close")
on chart.close {
if chart.isFirst {
log.info("script loaded")
}
c.plot(chart.close)
}