Pine Script alert troubleshooting

TradingView alertcondition: Compile Error or No Alert?

A valid alertcondition() call in a TradingView strategy does not cause a compilation error merely because it is in a strategy. It has no effect for creating alerts. If compilation fails, inspect scope and argument types: alertcondition() belongs at global scope, and its title and message require const strings. For strategy alerts, use alert() calls or order fill events.

Review My Alert Script

A decision tree for alertcondition problems

Start with the actual compiler result. A missing alert option and a compiler error need different fixes. Do not infer the error from the search phrase alone.

Observed resultCheckNext action
Compilation fails at an indented alertcondition()Is it inside an if, loop, or function?Move the call to global scope and pass a globally accessible boolean condition.
Compilation reports an argument type mismatchcondition needs bool; title and message need const string.Use a constant message with placeholders, or alert() for a runtime message.
Strategy compiles; named alert condition is unavailableDoes the script use strategy()?Choose alert() events or simulated order fill events instead.
Indicator condition is available but no notification arrivesIs the alert active, and does the condition occur on a realtime bar?Check the alert log, frequency, expiry, runtime errors, and notification destination.

Fix local scope without changing the signal

Keep alertcondition() unindented at the top level. Put conditional behavior in its first argument. A variable declared only inside a local block is not accessible outside that block; define the signal in global scope as this example does. The same restriction applies inside a user-defined function.

Complete v6 indicator: one named alert for a confirmed EMA crossoverpinescript
//@version=6
indicator("Confirmed EMA crossover", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
crossUp = ta.crossover(fast, slow)
confirmedCross = crossUp and barstate.isconfirmed
plot(fast, "Fast EMA", color = color.blue)
plot(slow, "Slow EMA", color = color.orange)
alertcondition(confirmedCross, "EMA cross up", "EMA cross up on {{ticker}} at {{close}}")

Fix const string messages and plot placeholders

const describes when a value is known, not whether it was written as one literal. Concatenating two constant strings is valid. Appending str.tostring(close) produces a series string, which alertcondition() cannot accept. An input.string() value is also not const. The title follows the same qualifier rule. Use alert() when you need arbitrary runtime text.

  • {{close}} supplies the triggering bar price; {{ticker}} supplies the symbol name. Use {{exchange}}:{{ticker}} when you need the exchange as well.
  • {{plot_0}} refers to the first plot output, not a variable named plot_0. Plot placeholders address the first 20 outputs, indexed 0 through 19.
  • A named placeholder such as {{plot("RSI")}} uses the exact plot title. It avoids changing the reference when you reorder plots.
Complete v6 indicator: a constant message with a runtime RSI valuepinescript
//@version=6
indicator("RSI alert placeholder")
rsi = ta.rsi(close, 14)
crossUp = ta.crossover(rsi, 50)
plot(rsi, "RSI", color = color.purple)
hline(50, "Midline")
const string prefix = "RSI crossed 50: "
alertcondition(crossUp and barstate.isconfirmed, "RSI above 50", prefix + '{{plot("RSI")}} on {{exchange}}:{{ticker}}')

Use alert() for signals and order alerts for fills

The example sends a signal message when a confirmed crossover submits an order. The order fill notification is a separate event from the broker emulator. With default strategy settings, a market order normally fills on the next available tick, often the next bar open. The close in the signal text is therefore not a promised fill price.

  • For signal messages, create a strategy alert that includes alert() function calls. For fills, select order fill events; choose both only if you want both event types.
  • For custom order messages, keep {{strategy.order.alert_message}} in the alert dialog Message field. The annotation above supplies that default.
  • alert.freq_once_per_bar_close governs alert() calls, not order fill alerts. Waiting for a chart bar close does not resolve every source of repainting.
Complete v6 strategy: distinct signal and simulated fill messagespinescript
//@version=6
//@strategy_alert_message {{strategy.order.alert_message}}
strategy("EMA alert events", overlay = true)
fast = ta.sma(close, 14)
slow = ta.sma(close, 28)
enterLong = ta.crossover(fast, slow)
exitLong = ta.crossunder(fast, slow)
plot(fast, "Fast SMA", color = color.blue)
plot(slow, "Slow SMA", color = color.orange)

if enterLong and barstate.isconfirmed and strategy.position_size == 0
    alert("Long signal: " + syminfo.tickerid + " close=" + str.tostring(close), alert.freq_once_per_bar_close)
    strategy.entry("Long", strategy.long, alert_message = "Long entry filled")

if exitLong and barstate.isconfirmed and strategy.position_size > 0
    alert("Exit signal: " + syminfo.tickerid + " close=" + str.tostring(close), alert.freq_once_per_bar_close)
    strategy.close("Long", alert_message = "Long exit filled")

Verify the running alert after fixing the code

Use this as a manual verification procedure. A successful syntax check does not prove that TradingView delivered a notification or that a webhook receiver processed it.

  • Save and add the final script to the intended symbol and timeframe. For an indicator, select its named condition in Create Alert and choose the desired frequency.
  • Create a new alert after changing the code, inputs, symbol, or timeframe. An existing alert continues using its saved snapshot.
  • Wait for a new realtime trigger. Historical chart markers do not send retrospective notifications.
  • Check the alert log first. If an event appears there but no notification arrives, inspect the selected destination. If no event appears, check condition logic, frequency, active status, expiry, and runtime errors.
Where Pineify fits

Pine Script AI Coding Agent

Bring the full script and exact compiler message to the coding agent to review scope, message types, and the intended alert event.

Also useful: Pine Script Error Lab. Look up other Pine Script compiler errors and repair patterns.

Review My Alert Script

Frequently asked questions

These examples explain alert programming, not a trading recommendation. Syntax validation does not establish profitability, live notification delivery, or broker execution. Verify the full alert workflow before connecting it to order execution.

Sources and verification