Appearance
Alerts
How do you make a script raise an alert? Call alert with a message on the bars where it should fire, or declare alertcondition with a condition, a title and a message. The terminal's alert rules run your script on closed bars and raise what these calls ask for. A chart's own run raises nothing.
pine
//@version=6
indicator("Cross alerts", overlay = true)
float ma = ta.sma(close, 50)
bool crossUp = ta.crossover(close, ma)
alertcondition(crossUp, "Cross up",
"{{ticker}} closed above its 50-bar average at {{close}}")
if crossUp
alert("Close crossed above the 50-bar average",
alert.freq_once_per_bar_close)
plot(ma, "SMA 50")alert
pine
alert(message, freq) → voidRaises an alert with message on the bar it runs on, when an alert rule is running the script.
Every bar an alert rule reads has closed, so alert.freq_once_per_bar and alert.freq_once_per_bar_close both fire once per bar for each call. alert.freq_all fires on every call, so a call inside a loop can fire many times on one bar.
| Parameter | Default | Description |
|---|---|---|
messageseries string | The alert's text, which can be built per bar. | |
freqinput string | alert.freq_once_per_bar | alert.freq_all, alert.freq_once_per_bar or alert.freq_once_per_bar_close. |
alert.freq_*
Values for alert's freq.
Each is a const string.
| Name | What it means |
|---|---|
alert. | Every call fires. |
alert. | A call fires once per bar. |
alert. | A call fires once per bar, at its close. On the closed bars an alert rule reads, the same as once per bar. |
alertcondition
pine
alertcondition(condition, title, message) → voidDeclares a condition an alert rule can watch: on each bar where condition is true, it raises an alert with title and message.
The message can hold TradingView's placeholders, filled from the bar that fired: {{ticker}}, {{open}}, {{high}}, {{low}}, {{close}}, {{volume}}, {{time}}, {{timenow}} and {{interval}}. A placeholder it doesn't know stays as written.
| Parameter | Description |
|---|---|
conditionseries bool | When to fire. |
titleconst string | The condition's name, which picks it when you create an alert. |
messageconst string | The alert's text. |