Aug 12, 2025 • 16 min read

Pine Script v6 Alerts: alertcondition(), alert(), and Reliable Triggers

Everything you need to ship dependable TradingView alerts: indicator vs strategy alerts, once-per-bar vs once-per-bar-close, MTF confirmations, and test workflows.

The alert toolbox in Pine v6

  • alertcondition(cond, title, message) declares alert-able conditions for indicators.
  • alert(message) fires a one-off alert in code when the script is used in an alert.
  • Strategies can trigger alerts when you set the alert on the strategy and select execution options.
  • Alert frequency is set in the UI: once, once-per-bar, once-per-bar-close.

Core example: clean indicator alerts

//@version=6
indicator("EMA Crossover Alerts", overlay=true)

fastLen = input.int(20, "Fast EMA")
slowLen = input.int(50, "Slow EMA")

emaFast = ta.ema(close, fastLen)
emaSlow = ta.ema(close, slowLen)

longCond = ta.crossover(emaFast, emaSlow)
shortCond = ta.crossunder(emaFast, emaSlow)

plot(emaFast, color=color.new(color.teal, 0))
plot(emaSlow, color=color.new(color.orange, 0))

// Declare alert-able conditions with templated message tokens
alertcondition(longCond, title="Bullish Cross", message="{{ticker}} {{interval}} Bullish cross @ {{close}}")
alertcondition(shortCond, title="Bearish Cross", message="{{ticker}} {{interval}} Bearish cross @ {{close}}")

// Optional: UI previews using plotshape
plotshape(longCond, title="Long", style=shape.triangleup, color=color.new(color.teal, 0), location=location.belowbar)
plotshape(shortCond, title="Short", style=shape.triangledown, color=color.new(color.orange, 0), location=location.abovebar)

Create the alert from the chart: “Add alert” → Condition: this indicator → choose title → set frequency. Messages can use TradingView placeholders like {{ticker}}, {{interval}}, {{close}}.

Strategy alerts and order fills

Strategies don’t use alertcondition(). Instead, you set alerts on the strategy instance and let entries/exits generate signals. For webhook workflows, encode order side/size in the message template.

//@version=6
strategy("Strategy Alerts Template", overlay=true)

long = ta.crossover(ta.ema(close, 20), ta.ema(close, 50))
short = ta.crossunder(ta.ema(close, 20), ta.ema(close, 50))

if long
    strategy.entry("L", strategy.long)
if short
    strategy.entry("S", strategy.short)

// In the alert dialog for this strategy, set the webhook URL and a JSON message template
// Example JSON: {"symbol":"{{ticker}}","tf":"{{interval}}","side":"{{strategy.order.action}}","price":"{{close}}"}

Frequency: once-per-bar vs once-per-bar-close

  • Once-per-bar-close is the safest: no intra-bar flicker; signal evaluated on the final bar state.
  • Once-per-bar triggers on the first time the condition becomes true during a bar; can fire earlier and then reverse.
  • For MTF filters, prefer bar-close alerts or explicit barstate.isconfirmed gating to avoid repaint-like behavior.

MTF alert pitfalls and fixes

  • Use request.security() with barmerge.lookahead_off and gate actions on confirmed HTF bars.
  • Label and plot the HTF state on your LTF to visually verify timing before enabling alerts.
  • Avoid conflicting frequency settings; prefer bar-close when in doubt.

Deep dive: MTF Strategy Design andRepaint Pitfalls.

Using alert() for custom one-offs and webhooks

alert() emits a message immediately from code when the script is attached to an active alert. Useful for multi-signal payloads or complex routing. Avoid spamming by guarding with edge detection.

//@version=6
indicator("Custom Alert() Example", overlay=false)

cond = ta.crossover(ta.rsi(close, 14), 50)
fired = ta.barssince(cond) == 0

if fired
    alert("RSI crossed 50 on {{ticker}}/{{interval}} @ {{close}}")

Testing workflow

  • Validate visually with plotshape() where alerts should occur.
  • Use bar replay to confirm the alert would have fired at the intended bar timing.
  • Send alerts to a test webhook endpoint to inspect payloads before going live.

FAQ

Why is my alert not firing?

Ensure the condition actually becomes true on new bars, the alert is attached to the correct indicator/strategy instance, and the frequency (bar vs bar-close) matches your signal logic.

Can I backfill alerts on historical bars?

No, alerts notify in real time going forward. Use bar replay and visual markers to validate expected historical triggers.