> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Alerts

> The two ways a script can raise an alert, alert and alertcondition, where each may be called, and when each acts.

A script can offer a condition for an alert (`alertcondition`) or raise an alert from its own logic (`alert`). Neither takes a
frequency argument.

| | `alert(message)` | `alertcondition(condition, title, message)` |
| - | - | - |
| Where it may be called | anywhere: top level, `if`, loops, functions | top level only |
| `message` | any `series string`, may change by bar | `const string`, optional, fixed |
| `condition` | none | a `bool` series, required |
| `title` | none | `const string`, optional |
| What it does | raises an alert while the script runs | declares a condition the user can choose when creating an alert |
| When it acts | only on realtime bars, only when the script runs as an alert, at most once per bar | the condition is evaluated on every bar |

## alert

Call `alert` where the event happens. Its message may be built from data. On historical bars it does nothing.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Breakout alert", overlay=true)
top = talib.highest(high, 20)
if close > top[1] {
    alert("Breakout at " + str.tostring(close))
}
plot(top, title="20-bar high")
```

`alert` returns no value (`x = alert("a")` is refused: Cannot assign void value.).

On a forming bar the bar's one alert is raised on the first tick that asks for it, with that tick's price. To alert on the closed bar, write `if barstate.isconfirmed and condition` (see [How to avoid a result that changes after the bar closes](https://gocharting.com/docs/scripting/how-to/avoid-a-result-that-changes-after-the-bar-closes.md)).

## alertcondition

Declare the condition once, at the top level, with a fixed title and message:

```lipi wrap theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Cross condition")
avg = talib.sma(close, 20)
alertcondition(talib.crossover(close, avg), title="Close above average", message="Close crossed above the 20-bar average")
plot(avg, title="Average")
```

The condition must be boolean (`alertcondition(close)` is refused: The `condition` argument of `alertcondition()` must be a boolean series.)
and the message is `const`: a series string there (`str.tostring(close)`) is refused as in [qualifiers](https://gocharting.com/docs/scripting/language/qualifiers.md).

Inside an `if`, `alertcondition` is refused like `plot`: `alertcondition()` must be called in the global scope. Put the test in the
`condition` argument.

Use `alert` when the message or the moment depends on what the script worked out on this bar. Use `alertcondition` for a named
condition that the user turns into an alert. For delivery, see [Webhooks](https://gocharting.com/docs/scripting/automation/webhooks.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.