Alerts
Lipi has two alert functions, and they answer different questions. alertcondition declares, at the top level of your script, a condition the platform can offer to the reader. alert raises one from inside your own logic while the script runs.
alert
alert(series string message) → voidalert takes one argument, the message, and it is required. The message is a series string, so it can differ from bar to bar.
alert may be called inside a condition. It is the one output-shaped function with no top-level rule, and that is what makes “alert me when this happens” expressible at all. Every chart-output function has to be called at the top level of the script, and calling one inside a branch, a loop or your own function is rejected with a named error. alert carries no such rule.
alert fires at most once per bar. It fires only on realtime bars, and only when the script is running as an alert. On historical bars it does nothing, so nothing is raised while the script works through history.
indicator("Session open alert")
if session.isfirst {
alert("A new session has started")
}
plot(close)alertcondition
alertcondition(series bool condition, const string title, const string message) → voidalertcondition takes a condition and, optionally, a title and a message. The condition is a series bool. The title and the message are const string: they are fixed when the script is compiled and cannot change from bar to bar. Left out, both are na.
alertcondition must be called at the top level of the script, in the same way the chart-output functions must.
It raises nothing by itself. It declares a condition that the platform can then offer to the reader.
indicator("Session open condition")
alertcondition(session.isfirst, "New session", "A new session has started")
plot(close)Choosing between the two
alert | alertcondition | |
|---|---|---|
| Where you may call it | anywhere, including inside a branch | top level only |
| Message | series string, may change from bar to bar | const string, fixed at compile time |
| Title | none | optional const string |
| What it does | raises an alert as the script runs | produces a declaration, not an event |
| When it acts | realtime bars only, at most once a bar, and only in alert mode | when the script declares itself |
Use alert when the message or the moment depends on what your own code worked out on this bar. Use alertcondition when you want to hand the reader a named condition and let them decide what to do with it.
Where an alert goes
Raising an alert is the whole of the language’s part. Delivery beyond that is configured on the platform, outside the script. See Webhooks for algo trading.