Skip to content

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

Raises 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.

ParameterDefaultDescription
message
series string
The alert's text, which can be built per bar.
freq
input string
alert.freq_once_per_baralert.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.

NameWhat it means
alert.freq_allEvery call fires.
alert.freq_once_per_barA call fires once per bar.
alert.freq_once_per_bar_closeA 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) → void

Declares 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.

ParameterDescription
condition
series bool
When to fire.
title
const string
The condition's name, which picks it when you create an alert.
message
const string
The alert's text.

See also ​

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.