Pine Script alert_message: one command per strategy order

Autoview · Guide · Updated September 26, 2026

Every order-placing call in a Pine Script strategy takes an optional alert_message string. When that order fills, TradingView drops the string into your alert. Put a full Autoview command in it and every order your strategy places carries its own instructions, written right next to the logic that placed it. Everything on this page is checked against TradingView's Pine Script v6 reference and its alerts documentation. If you haven't built a strategy alert before, start with Pine Script strategy alerts, which covers the placeholder approach this page builds on.

Which calls accept it

Five strategy commands take alert_message in v6:

  • strategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, disable_alert)
  • strategy.order(...), with the same comment, alert_message, disable_alert tail as strategy.entry()
  • strategy.close(id, comment, qty, qty_percent, alert_message, immediately, disable_alert)
  • strategy.close_all(comment, alert_message, immediately, disable_alert)
  • strategy.exit(...), which also adds alert_profit, alert_loss, and alert_trailing (covered below)

The reference describes it the same way on each: custom text for the alert that fires when the order fills, used wherever the alert's Message field contains the {{strategy.order.alert_message}} placeholder. Leave it out and it defaults to an empty string.

The two halves: the argument and the placeholder

alert_message only does anything when both halves are in place. In the script, give each order its command:

//@version=6
strategy("alert_message example", overlay=true)

fastMA = ta.sma(close, 10)
slowMA = ta.sma(close, 30)

if ta.crossover(fastMA, slowMA)
    strategy.entry("Long", strategy.long, alert_message="s=BTCUSDT b=buy q=1 t=market")
if ta.crossunder(fastMA, slowMA)
    strategy.close("Long", alert_message="s=BTCUSDT c=position")

Then, when you create the alert on the strategy, include its order fill events and set the Message field to the placeholder on its own:

{{strategy.order.alert_message}}

TradingView's docs are explicit that the placeholder is required: without it in the Message field, the alert_message text is never used. With it, the entry fill sends s=BTCUSDT b=buy q=1 t=market to your Autoview webhook and the close fill sends s=BTCUSDT c=position. c=position closes the open position on that line's symbol, the same scoping the cancel and close page describes.

alert_message or comment?

The strategy alerts guide shows a related trick: put Autoview syntax in an order's comment and send it with {{strategy.order.comment}}. That works, but comment has a second job. The reference says a non-empty comment is what the Strategy Tester and the chart show for the order, so your command text ends up as the label on every trade. alert_message exists only for the alert, which keeps the chart readable and leaves comment free for a human-friendly name.

Building the command from live values

alert_message is a series string, so you can assemble it from anything your script calculates. The one rule that catches people: other TradingView placeholders don't work inside it. The alerts documentation says placeholders like {{close}} can go in the Create Alert Message field but cannot be used in the alert_message argument. Convert the value in Pine instead:

if ta.crossover(fastMA, slowMA)
    strategy.entry("Long", strategy.long,
         alert_message="s=BTCUSDT b=buy q=1 t=limit p=" + str.tostring(close))

TradingView's docs also note that variables in alert_message are evaluated when the order is executed, which is when the alert fires. For an order that waits several bars to fill, like a stop or limit entry, keep that in mind when you read the value that arrives.

Separate messages for a take-profit and a stop-loss

strategy.exit() can create a take-profit, a stop-loss, and a trailing stop from one call, and each can carry its own text:

  • alert_profit applies to the take-profit orders (from profit or limit).
  • alert_loss applies to the stop-loss orders (from loss or stop).
  • alert_trailing applies to the trailing stop orders.

For any order where the matching alert_* argument is present, strategy.exit() ignores the general alert_message. So you can set a shared default with alert_message and override just the one leg that needs different text:

strategy.exit("Exit", "Long", profit=200, loss=100,
     alert_profit="s=BTCUSDT c=position",
     alert_loss="s=BTCUSDT c=position")

Keep in mind what triggers these alerts: the fill of TradingView's own simulated exit order. In this example Autoview receives a market close for the position when TradingView's strategy decides the target or stop was hit, not a resting order placed ahead of time. If you'd rather attach a stop or target to the order Autoview places, the stop-loss and take-profit guide covers the parameters for that.

Silencing one order with disable_alert

If an order shouldn't reach Autoview at all, pass disable_alert=true on that call. The strategy then doesn't trigger an alert when that order fills. It defaults to false, and it accepts a series value, so you can decide per bar which orders alert.

The empty-message trap

When the Message field holds only {{strategy.order.alert_message}} and some of your order calls have no alert_message, TradingView replaces the placeholder with an empty string for fills from those calls. The alert still fires, with nothing in it. Either give every order-placing call its own alert_message, or mark the ones that shouldn't alert with disable_alert=true.

Test it with a dry run first

Add d=1 to each alert_message while you test, so Autoview logs what it would have done without placing anything, then read the log against the order your strategy just made. Testing and debugging shows how to force a strategy entry so you don't have to wait for a real signal. Remove d=1 from each message only once the dry runs read the way you meant.

A note on what Autoview is. Autoview is an execution tool, not a trading or investment advisor. It places the orders your own strategy and alerts tell it to; it doesn't generate signals or make any claim about results. Trading carries risk of loss, and you're responsible for the strategy you automate. See our disclosures.

Set up a strategy alert