ScriptingAlerts and automationAlerts

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) → void

alert 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) → void

alertcondition 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

alertalertcondition
Where you may call itanywhere, including inside a branchtop level only
Messageseries string, may change from bar to barconst string, fixed at compile time
Titlenoneoptional const string
What it doesraises an alert as the script runsproduces a declaration, not an event
When it actsrealtime bars only, at most once a bar, and only in alert modewhen 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.

Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade