Functions

Alerts

Define configurable notifications with alert() and alertcondition().

Alerts let a script notify you about a crossover, level break, regime change, or any other boolean condition. The script defines what happened and the message to send. You decide whether the configured alert fires Once or Every time and which delivery channels it uses.

There are two ways to expose an alert from a script:

  • alert(...) defines a condition with a dynamic message. A script containing one or more calls adds alert() triggers to the alert condition menu.
  • alertcondition(...) defines a named condition that appears separately in the alert condition menu.

Neither function sends a notification merely because you own, open, or run the script. Create an alert from the Alerts sidebar and select the condition you want to monitor.

alert()

alert(message, condition) defines a tick-based alert trigger.

ArgumentTypeDescription
messagestringThe alert text. Build it dynamically with format(...) to include live values.
conditionbooleanThe call becomes active when this changes from false to true.
//@version=3
define(title="MA cross alert", position="onchart", axis=true)

timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange)
timeseries fast = sma(source=trade.close, period=9)
timeseries slow = sma(source=trade.close, period=21)

var goldenCross = crossover(seriesA=fast, seriesB=slow)
alert(message=format("Golden cross at {0}", trade.close), condition=goldenCross)

plotLine(value=fast, colors=["#16a34a"], width=2, label=["Fast"], desc=["9-bar SMA"])
plotLine(value=slow, colors=["#dc2626"], width=2, label=["Slow"], desc=["21-bar SMA"])

To receive this alert:

  1. Open the Alerts sidebar.
  2. Create an alert for the script.
  3. Choose alert() triggers from the condition menu.
  4. Choose Once or Every time and your delivery channels.

One alert() triggers configuration covers every alert() call in the script. Each qualifying call keeps its own message. If several calls become true on the same tick, they are delivered in source order.

The function accepts exactly these two arguments. Use the Alerts sidebar's Once / Every time control for recurrence.

alertcondition()

alertcondition(condition, title, message) declares a named, tick-based alert condition.

ArgumentTypeDescription
conditionbooleanThe condition becomes active when this changes from false to true.
titlestringThe name shown in the alert condition menu.
messagestringThe default notification message.
//@version=3
define(title="RSI overbought", position="offchart", axis=true)

timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange)
var r = rsi(source=trade.close, period=14)

// Exposes "Overbought" as a selectable alert condition.
alertcondition(condition=r > 70, title="Overbought", message="RSI above 70")

plotLine(value=r, colors=["#7c3aed"], width=2, label=["RSI"], desc=["14-bar RSI"])

Create an alert for this script and choose Overbought from the condition menu.

Once and Every time

Both functions use the recurrence setting from the Alerts sidebar:

  • Once delivers all qualifying calls from the first triggering tick, then completes the configured alert.
  • Every time keeps the configured alert active for future false-to-true transitions.

Each condition follows the same edge-triggered behavior:

  • If it is already true when you create or manually resume the alert, it fires immediately.
  • It stays silent while it remains true, even across new candles.
  • A false tick re-arms it.
  • The next false-to-true transition fires it again when Every time is selected.

For alert() triggers, this state is tracked independently for every alert() call site.

Safety pause

Configured alert() and alertcondition() alerts can deliver at most 10 logical fires in a rolling 60-second window. This limit is shared by the eligible call sites and named conditions in one configured alert.

The first 10 fires are delivered. If an 11th fire occurs within the window:

  • the 11th fire is suppressed;
  • the configured alert is automatically paused;
  • a warning toast tells you why it was paused;
  • the Alerts sidebar shows Paused — too many triggers.

The alert does not resume automatically. Review the script or condition, then select Resume in the Alerts sidebar. Resuming clears the previous rate window and evaluates the current conditions immediately.

Above and Below price or output conditions do not use this safety counter.

Both, side by side

This script exposes one combined alert() triggers choice and one named Overbought choice:

alerts_fire.ks
//@version=3
define(title="RSI alerts", position="offchart", axis=true)

timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange)
var r = rsi(source=trade.close, period=14)

alert(message=format("RSI crossed 60 at {0}", r), condition=crossover(seriesA=r, seriesB=60))
alert(message=format("RSI crossed 70 at {0}", r), condition=crossover(seriesA=r, seriesB=70))
alertcondition(condition=r > 70, title="Overbought", message="RSI above 70")

plotLine(value=r, colors=["#7c3aed"], width=2, label=["RSI"], desc=["14-bar RSI"])

Choose alert() triggers to monitor both dynamic alert() calls, or choose Overbought to monitor only the named alertcondition().