Skip to content

alert() - Pine Script Function

Use alert() inside an indicator or strategy to fire a TradingView alert the moment a realtime condition occurs. The function runs only on the last, realtime bar; historical bars do not trigger the alert, so it won’t spam your log when the script loads.

alert(message, freq) → void
NameTypeDescription
messageseries stringText payload for the alert notification.
freqconst stringAlert frequency constant (see alert.freq_*).
  • Works only on the realtime bar; historical bars are ignored.
  • The script must have an active alert created via Create Alert → Any alert() function call.
  • Alert frequency constants include alert.freq_once_per_bar, alert.freq_once_per_bar_close, and alert.freq_all.
//@version=5
indicator("alert() example", overlay=true)
maLen = input.int(14, "MA length")
ma = ta.sma(close, maLen)
crossUp = ta.crossover(close, ma)
if barstate.isrealtime and crossUp
alert(
"Price (" + str.tostring(close, format.mintick) +
") crossed above MA (" + str.tostring(ma, format.mintick) + ").",
alert.freq_once_per_bar)
plot(ma, "MA")
plotshape(crossUp, title="Cross up", style=plot.shape.triangleup, location=location.belowbar)