S019
alert constructor outside an alert declaration
Severity Error
alert(...) does not create a value you can pass around; it only declares an alert, and it is allowed solely as the right-hand side of an alert declaration. Using it in setup, in a local or inside a handler is rejected.
Declare the alert at the top level with alert name = alert(...) and call name.trigger() from a handler.
Failing example
script "Funding flip"
data funding = subscribe(data.funding)
setup flip = alert(title: "Funding changed sign", onClose: true)
on funding.close {
let now = funding.rate ?? 0.0
let before = funding.rate[1] ?? 0.0
if now * before < 0.0 {
flip.trigger()
}
}Fixed example
script "Funding flip"
data funding = subscribe(data.funding)
alert flip = alert(title: "Funding changed sign", onClose: true)
on funding.close {
let now = funding.rate ?? 0.0
let before = funding.rate[1] ?? 0.0
if now * before < 0.0 {
flip.trigger()
}
}