Pine Script Alerts & Automation

Pine Script alertcondition: Complete Syntax, Placeholders, and Strategy Guide

In Pine Script, alertcondition() creates available trigger conditions in TradingViews Create Alert dialog for indicator scripts. It takes condition, title, and message arguments and supports dynamic placeholders such as {{plot_0}} and {{close}}. However, alertcondition() is strictly forbidden in strategy() scripts, where calling it causes a compiler error; strategies must use the alert() function instead.

Build Alert Scripts with AI Agent

alertcondition() syntax and parameters in Pine Script v6

The alertcondition() function enables an indicator to offer predefined alert events directly inside TradingViews native alert creation dialog. When a user right-clicks a chart and selects "Add Alert", any alertcondition registered by your script appears in the Condition dropdown menu. It requires a boolean series condition and optional display labels.

ParameterTypeDescriptionExample
conditionseries boolThe logical expression that triggers the alert when trueta.crossover(fastEma, slowEma)
titleconst stringThe short name displayed in the TradingView alert dropdown"Bullish Crossover"
messageconst stringThe default notification text or webhook JSON payload"Buy signal triggered on {{ticker}} at {{close}}"

Dynamic message placeholders list for TradingView alerts

TradingView supports special string replacement placeholders inside the message argument of alertcondition() and alert(). When the condition triggers, TradingView replaces each token with current bar values before transmitting notifications or webhooks.

Placeholder tokenOutput descriptionSample generated value
{{ticker}}The exchange-qualified symbol of the current chartNASDAQ:AAPL or BINANCE:BTCUSDT
{{close}}The close price of the bar when the alert fired185.42
{{open}}, {{high}}, {{low}}Open, High, and Low prices of the triggering bar184.20, 186.10, 183.90
{{volume}}The trade volume recorded on the bar4521000
{{time}}Timestamp of the triggering bar in UTC format2026-09-10T14:30:00Z
{{interval}}Current chart timeframe resolution60 or 1D
{{plot_0}}, {{plot_1}}Numeric value of the 1st or 2nd plot() call in your script183.15 (e.g. 20 EMA value)

Why alertcondition in strategy causes a compile error and how to fix it

One of the most frequent compiler errors encountered by Pine Script developers is "The function alertcondition cannot be called in a strategy". TradingViews compiler restricts alertcondition() strictly to indicator() scripts because strategies use a distinct order-simulation engine. To send alerts from a strategy, replace alertcondition() with the alert() function or utilize strategy alert configurations.

Pine Script v6: Correct alert() implementation inside a strategypinescript
//@version=6
strategy("Strategy Alert Master [v6]", overlay = true)

fastMa = ta.sma(close, 14)
slowMa = ta.sma(close, 28)

plot(fastMa, "Fast MA", color = color.blue)
plot(slowMa, "Slow MA", color = color.orange)

longCondition = ta.crossover(fastMa, slowMa)

if longCondition
    strategy.entry("Long", strategy.long)
    // alert() is valid inside strategy blocks; alertcondition() is not!
    alert("Strategy Long Entry executed for " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)

Combining alertcondition with barstate.isconfirmed to prevent alert spam

If an alertcondition evaluates true on an unconfirmed bar, TradingView may dispatch notification emails, push notifications, or webhook payloads on every intra-bar price tick if "Once Per Bar" or "Every Tick" is selected. To protect against notification flood and false triggers, enforce bar close confirmation in your condition.

Pine Script v6: Non-spamming indicator alertcondition with barstate.isconfirmedpinescript
//@version=6
indicator("Clean Alerts [v6]", overlay = true)

rsiVal = ta.rsi(close, 14)
oversoldThreshold = input.int(30, "Oversold Level")

// Raw condition
isOversold = ta.crossunder(rsiVal, oversoldThreshold)

// Guard with barstate.isconfirmed so alert condition only fires when candle finishes
safeAlertCondition = isOversold and barstate.isconfirmed

plot(rsiVal, "RSI", color = color.purple)
hline(oversoldThreshold, "Threshold", color = color.gray)

alertcondition(safeAlertCondition, 
               title = "RSI Oversold Alert", 
               message = "RSI on {{ticker}} dropped to {{plot_0}} at close: {{close}}")
Where Pineify fits

Pine Script AI Coding Agent

Generate TradingView alertcondition scripts, fix strategy alert compilation errors, and configure webhook JSON payloads with the AI Coding Agent.

Also useful: Pine Script Error Lab. Diagnose and solve common TradingView alert errors, placeholder formatting issues, and version 6 syntax changes.

Build Alert Scripts with AI Agent

Frequently asked questions

Technical programming documentation for Pine Script alert implementation. Network connectivity, webhook latency, and third-party alert dispatch failures can impact real-time execution timing.

Sources and verification