Declares a named alert condition that can be picked when creating an alert on an indicator.
alertcondition(condition, title, message) adds an entry to the alert dialog for the script. It does not fire anything by itself; you create an alert from it and the alert fires on each bar where condition is true.
The message may include placeholders in double braces, such as {{ticker}}, {{close}} and {{interval}}, which are filled in when the alert fires.
Syntax
alertcondition(condition: series bool, title: const string (optional), message: const string (optional)) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| condition | series bool | required | The series bool that triggers the alert on bars where it is true. |
| title | const string | an empty title | The name that appears in the alert dialog. |
| message | const string | an empty message | The text sent when the alert fires. Placeholders such as {{ticker}} and {{close}} are replaced. |
Returns
Nothing.
Remarks
- It must be called at the top level of an indicator, not inside an if, a loop or a function, and it is not available in strategies. Use alert() when you need either.
- title and message must be constant text. They cannot depend on values calculated per bar.
- Each alertcondition() adds one entry to the script's alert list, so declare one per signal you want to be able to pick. The same script can offer a long and a short condition side by side.
Example
//@version=6
indicator("RSI condition")
r = ta.rsi(close, 14)
plot(r, "RSI")
hline(70)
hline(30)
alertcondition(ta.crossover(r, 70), "RSI above 70", "{{ticker}} RSI crossed above 70")See also
Runs on Sidechair