Pine Script strategy alerts for Autoview

Autoview · Guide · Updated September 30, 2026

If you've followed the automate TradingView alerts guide, you've already hand-written a command like s=BTCUSDT b=buy q=1 t=market into an alert's message box. That works fine for a fixed alert. A Pine Script strategy() is different: its buy/sell side and its size can change bar to bar, so a hard-coded message goes stale the moment your logic does. This page covers the other path: having TradingView fill the command in for you.

A minimal strategy

Here's a complete script, small enough to read in one pass, that opens and closes a position on a moving-average cross:

//@version=6
strategy("MA Cross Example", overlay=true, process_orders_on_close=true)

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

if ta.crossover(fastMA, slowMA)
    strategy.entry("Long", strategy.long, comment="b=long")
if ta.crossunder(fastMA, slowMA)
    strategy.close("Long", comment="b=long c=position")

process_orders_on_close=true is deliberate here, not the default: TradingView's own strategy documentation is explicit that without it, a strategy's earliest possible fill is the next bar's open, not the bar the crossover happened on, since a script recalculates only after each bar closes by default. Setting process_orders_on_close fills at the current bar's close instead, which matters below when this script's alert timing is compared against the caveats section.

The piece that makes this work: strategy placeholders

TradingView's alert message box accepts placeholders wrapped in double braces, and it substitutes the real value the instant the alert fires. These are TradingView's substitutions, not Autoview's. Autoview only ever sees the final text after TradingView has already filled it in. Two matter here:

  • {{strategy.order.action}} resolves to buy or sell, lowercase, for whichever order your strategy.entry()/strategy.close() call just placed.
  • {{strategy.order.contracts}} resolves to the size of that same order, as a plain number.

Autoview's parser lowercases every value it reads before matching it, so buy/sell land correctly either way. Drop them straight into the command in place of the values you'd otherwise type by hand:

s=BTCUSDT b={{strategy.order.action}} q={{strategy.order.contracts}} t=market

Set this as the alert's message when you create the alert on your strategy with its order fills included (the step-by-step below shows the exact Condition option). Every time the strategy enters or exits a position, TradingView fires the alert with that message, already filled in for the trade that just happened, and posts it to your Autoview webhook.

Creating the alert, step by step

With the strategy added to your chart:

  1. Click Alert (the clock icon) in the right-hand toolbar, or right-click the chart and choose Add Alert.
  2. In the Condition dropdown, pick your strategy's name, then Order fills only. Each strategy.entry()/strategy.close() call in the script above creates an order fill event when TradingView's broker emulator fills it, and that event is what fires the alert. If your strategy also makes its own alert() calls and you want those sent too, choose Order fills and alert() function calls instead. Don't pick an option that covers only alert() function calls: this script has no alert() calls, so that alert would never fire. TradingView's Pine Script alerts FAQ names both order fill options.
  3. Leave Expiration on Open-ended alert if you want it to keep running indefinitely.
  4. Paste the command with placeholders, s=BTCUSDT b={{strategy.order.action}} q={{strategy.order.contracts}} t=market, into the Message box.
  5. Under Notifications, turn on Webhook URL and paste your Autoview webhook URL into that field.
  6. Click Create.

That's the same alert-creation flow automate TradingView alerts and the functions guide use; the only strategy-specific parts are the Condition option and the message content.

What the payload looks like for entry, exit, and flat

After TradingView substitutes the placeholders, this is the literal text Autoview receives for each case, using the sample strategy above:

Trade eventResolved payload
Entry (long)s=BTCUSDT b=buy q=2 t=market
Exit (closing that same position)s=BTCUSDT b=sell q=2 t=market c=position
Flatten, step 1: cancel resting orders on the symbols=BTCUSDT c=order
Flatten, step 2: close the open position on the symbols=BTCUSDT c=position

The entry and exit rows come straight from {{strategy.order.action}} and {{strategy.order.contracts}} resolving against a live order; c=position on the exit line tells Autoview to close the existing position rather than open a new one. Flattening isn't a placeholder-driven case, since it isn't tied to one specific order. It's a separate pair of alerts you set up on a condition of your own choosing (a stop-all button, a risk-limit breach, end of session): one carrying c=order to cancel working orders, one carrying c=position to close the position, both covered in the command reference. On Tradovate, c=all does both in one command. Other exchanges do not support c=all and return a "not implemented" error, so send c=order and c=position as two alerts there.

Confirming the order actually landed

Everything above shows what Autoview parses. Whether the exchange accepted and filled the order is a separate check, and you make it in three places after an alert fires. TradingView's alert log shows the message the alert sent. Your Autoview log shows the command that arrived and what Autoview did with it. Your exchange's order history shows the fill itself. Start with d=1 in the message, as the dry-run step below explains, then remove it and let one small order through before you size up.

Repainting, slippage, and same-bar fills

Three caveats matter for a strategy alert specifically, on top of the general dry-run advice below:

  • Fill timing. By default, a Pine Script strategy recalculates only when a bar closes, so the earliest a market order can fill is the next bar's open, not the bar where the crossover happened. process_orders_on_close=true (used in the script above) changes that to fill at the current bar's close instead. Know which one your strategy is set to before you read too much into how fast a signal turns into a fill.
  • Repainting. calc_on_every_tick=true makes a strategy recalculate on every realtime price update instead of only at bar close. That can produce different entries and exits between a historical backtest and live/realtime running of the exact same script, which is what "repainting" means for a strategy specifically. Leave it off unless you have a specific reason to want intrabar recalculation, and understand that a backtest run with it on doesn't represent what live trading will actually do.
  • Slippage. strategy() takes a slippage argument, in ticks, applied to market and stop orders (for example slippage=3). It's a backtest-realism setting inside Pine Script, separate from whatever slippage the live exchange itself introduces on the actual fill; setting it doesn't reduce real-world slippage, it only makes the strategy's own backtest account for some.

These three are only part of what shapes a backtest. How to backtest a strategy in TradingView covers the rest of the Properties tab, Bar Magnifier, and how to read the strategy report before you turn the alert on.

Symbol still needs a human check

TradingView also offers {{ticker}} for the instrument, but don't reach for it automatically. It returns the exchange's raw concatenated symbol, and that format doesn't match every exchange Autoview supports. OANDA is the sharp case: {{ticker}} returns EURUSD, but Autoview's OANDA parser requires the underscored form, EUR_USD. A command built from {{ticker}} against a forex chart fails silently at the exchange, not at Autoview. Safer default: hardcode s= to the exact symbol your webhook is meant to trade, and only reach for a dynamic ticker once you've confirmed the resolved format matches what your specific exchange expects. The command reference lists the format per exchange.

Layer on risk management the same way

Once the entry/exit side and size are wired up, the rest of the command works exactly like a hand-written one. Stops, targets, and trailing stops attach with the same parameters covered in stops, targets, and trailing, and if your strategy needs to pass a value through that Pine Script computes at the time of the signal (a level, a distance, anything numeric), the custom variables page covers plugging that into the equation side of a parameter without touching the strategy code that generates the alert.

Advanced: passing full commands and computed values through Pine

{{strategy.order.action}} and {{strategy.order.contracts}} cover side and size. Some strategies need more than that in one alert, either a full set of parameters or a number Pine just calculated, like a target price. TradingView has a placeholder for each case.

A whole command, via comment()

strategy.entry(), strategy.exit(), and strategy.order() all take an optional comment argument, a string you write in the Pine code. TradingView exposes that string back to you in an alert message as {{strategy.order.comment}}. Because you control the string, you can put real Autoview syntax in it instead of a plain label:

strategy.entry("Long", strategy.long, comment="b=long")
strategy.exit("Exit", "Long", comment="b=long c=position")

Set the alert message to {{strategy.order.comment}} alone, or mixed into a larger command:

s={{ticker}} {{strategy.order.comment}} t=market q={{strategy.order.contracts}}

Whatever you wrote as comment= lands in the message verbatim, and Autoview parses it the same as any other key=value pair. That makes it the tool for a strategy that needs to swap out more than one parameter per trigger, not just the side.

The catch is that comment is also the label the chart and Strategy Tester show for each order, so your command text ends up on every trade. The purpose-built alternative is the alert_message argument on the same calls, sent with {{strategy.order.alert_message}}; Pine Script alert_message covers it, including separate messages for a take-profit and a stop-loss.

A computed number, via plot()

Pine strategies often calculate a level, a take-profit price, a stop-loss price, anything numeric, and TradingView can hand that number straight to Autoview. Plot it, name the plot, then reference that name in the alert with {{plot("Name")}}:

ftp = close + close * 0.01
fsl = close - close * 0.01
plot(ftp, "Take-Profit")
plot(fsl, "Stop-Loss")
ftp={{plot("Take-Profit")}} fsl={{plot("Stop-Loss")}}

ftp and fsl (Fixed Take Profit and Fixed Stop Loss) are ordinary Autoview parameters; the placeholder just supplies the number instead of you hardcoding it.

Sequencing a split take-profit and stop-loss

Not every exchange accepts a take-profit and a stop-loss at the same moment it opens a position. When a venue won't take both at once, open the position first, then send the take-profit and stop-loss as their own follow-up commands against c=position, and use delay= to hold until the position exists before either one attaches:

s={{ticker}} {{strategy.order.comment}} t=market q={{strategy.order.contracts}}
delay=1
s={{ticker}} {{strategy.order.comment}} c=position t=market ftp={{plot("Take-Profit")}}
s={{ticker}} {{strategy.order.comment}} c=position t=market fsl={{plot("Stop-Loss")}}

The first line opens the position. delay=1 holds for a second so the position exists before the next lines run. c=position tells Autoview this command targets an existing position rather than opening a new one; carrying ftp= or fsl= on that same line turns it into a conditional order, take-profit or stop-loss, attached to that position instead of an immediate close. {{strategy.order.comment}} repeats on every line because Autoview still needs the book (b=long/b=short) to match the follow-up command to the right side of the position. See the delay page for how the pause itself works, and stops, targets, and trailing for sl/tp, the plain (non-computed) versions of the same idea.

Test before you trust it

A strategy alert is still a webhook post, so the same rule applies: dry-run first. Add d=1 to the message, let a few signals fire, and read the log. Did the side and size match what your strategy just did? Did the symbol resolve the way you expected? Confirm both before removing d=1. The automate TradingView alerts guide's dry-run step covers the full round trip if you haven't run through it yet.

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 your first alert