Skip to main content

Alerts

Declare each alert name at top level, so users can pick it when they create an alert, then fire it from onBar():

declareAlert("breakout");

export function onBar(): void {
if (!isNewBar()) return;
if (src.close[0] > ta.highest(src.high, 20)[1]) {
alert("breakout", "{{ticker}} broke the 20-bar high at {{close}}");
}
}

Fire alerts on closed bars (isNewBar()) unless you want them to trigger intrabar, possibly more than once per bar.

Default message​

declareAlertMessage(name, template) declares the alert and gives it a default message. The alert dialog prefills its Message field with the template, like the message of Pine's alertcondition. Placeholders are kept as written and filled in when the alert fires.

declareAlertMessage("breakout", "{{ticker}} broke the 20-bar high at {{close}}");

Message placeholders​

PlaceholderValue
{{ticker}}Symbol, for example BINA_USDT_BTC
{{exchange}}, {{base}}, {{quote}}Parts of the symbol
{{interval}}Chart timeframe in minutes, or D
{{time}}Bar open time, ISO 8601
{{timenow}}Current time, ISO 8601
{{open}}, {{high}}, {{low}}, {{close}}, {{volume}}The current bar
{{plot("name")}}The value of a plot, as plotted earlier in the same run

Unknown placeholders are left as written, so a typo stays visible. {{plot("name")}} only sees plots made before the alert call on the same bar.

Order alerts​

Alert conditions can also match the strategy's orders. An order alert's payload carries the entry price (for limit entries), the take-profit prices and the stop loss, so it can drive an Altrady signal bot directly without a hand-written JSON message.