Guides

Alerts

Text
alert(condition, "Message", every: duration)

alert records an alert on each bar where condition is true.

What happens when an alert fires#

The app only signals new alerts on recent bars — never the alerts of the history it loads, and never right after the context changes (instrument, unit, session, or the script's code). Each alert is signaled once. A script hidden from the chart signals nothing.

The … menu of the StrateScript panel holds the alert options, shared by all scripts:

Alerts also appear in the Console, next to print lines.

Avoiding false alerts#

A condition computed on the bar that is still forming can be true for a moment and false at the close. Add bar.confirmed to alert only on closed bars:

StrateScript
indicator "Cross alert" { overlay: true }
len = input.int("Length", 20, min: 1)
avg = sma(close, len)
plot(avg, #e8c15a, title: "SMA")
cross = crossover(close, avg)
alert(cross and bar.confirmed, "Close crossed above the SMA", every: 30m)
marker(cross and bar.confirmed, shape: "triangle_up", location: "below")

Alerts from events#

alert belongs to the bar it is called on. To alert on an order-flow event, record the event in a state variable inside the handler, then raise the alert from the body:

StrateScript
indicator "Large print alert" { overlay: true }
minSize = input.int("Min size", 100, min: 1)
state biggest = 0
on trade(t) {
  if t.size > biggest { biggest = t.size }
}
alert(biggest >= minSize, "Print of " + str(biggest) + " contracts")
biggest = 0
STRATE / PRODUCT SCREENSHOT

Actual platform screenshot.