From a Pine strategy fill to an Autoview command
When a Pine Script strategy fills an order, TradingView can post an alert to your Autoview webhook. The alert's Message field is your Autoview command. Before TradingView sends it, it swaps each placeholder for a value from the order that just filled. This page lists the strategy placeholders, where each one goes in a command, and six commands you can copy. What each placeholder holds comes from TradingView's article on variable values in alerts. What Autoview does with the result comes from a read of its command parser.
TradingView is one alert source. Any system that can send a webhook can send Autoview the same command text.
How a fill turns into an order
- Your strategy calls
strategy.entry(),strategy.close(),strategy.exit()orstrategy.order(), and TradingView's simulated broker fills the order. - You created an alert on the strategy with order fills included, and the Message field holds a command with placeholders in it. Pine Script strategy alerts walks through the Create Alert dialog.
- TradingView fills in the placeholders and posts the text to your webhook URL.
- Autoview reads each line as
key=valuepairs. Keys can be any case, and a key it does not know is dropped, with an "Unknown parameter ignored" line in your log.
Two defaults matter for strategy alerts. A command with no t= is a limit order, so write t=market when you want a market order. A command with no q= uses 100% of your balance, so always send a size.
Placeholder map
| Placeholder | What TradingView puts there | Where it goes |
|---|---|---|
{{strategy.order.action}} | buy or sell for the order that filled | b=. Autoview reads buy as the buy side and sell as the sell side, in any case. |
{{strategy.order.contracts}} | The number of contracts in that order | q=. A plain number goes to the exchange in its own order unit (Autoview calls this u=contracts, the default). Make sure your strategy's size means the same thing there. |
{{strategy.order.price}} | The price the order was executed at | fp=, the exact price of a limit order. On Tradovate, price= instead (see the Tradovate command reference). |
{{close}} | The close of the bar the alert fired on | fp= or price=, the same way as the order price. |
{{strategy.order.alert_message}} | The alert_message argument of the Pine call | The whole command. Write it in Pine, one per order call. See Pine Script alert_message. |
{{strategy.order.comment}} | The comment argument of the Pine call | Part or all of a command. The comment is also the trade's label on the chart, which is why alert_message is usually the better place for command text. |
{{strategy.order.id}} | The ID you gave the order in Pine (its first argument) | Not a value Autoview needs. It is your name for the order, not an exchange order ID. |
{{strategy.market_position}} | long, flat or short, the position after the fill | Rarely b=. long and short work as sides and also mark the order as a margin trade. flat turns the line into c=all, which only Tradovate carries out. |
{{strategy.prev_market_position}} | long, flat or short, the position before the fill | No parameter. Useful in a note, not in a command. |
{{strategy.position_size}}, {{strategy.market_position_size}}, {{strategy.prev_market_position_size}} | The strategy's own position size (the last two as an absolute value) | Usually nowhere. That is the strategy's position, which can differ from what your exchange holds. To exit, c=position closes what the exchange holds. |
{{ticker}} | The chart symbol's ticker | s=, only when the chart ticker is written the way your exchange writes the symbol. Typing the symbol out is safer. |
Placeholders only work in the Message field of the alert. TradingView's alerts documentation says they cannot be used inside the alert_message argument. Build those values in Pine with str.tostring() instead.
Six commands
Each command below is what goes in the alert's Message field, unless it says Pine. Test every one with d=1 first (example 6).
1. Market order that follows every fill
s=BTCUSDT b={{strategy.order.action}} q={{strategy.order.contracts}} t=marketEvery fill, entry or exit, becomes a market order with the same side and size. If your strategy closes a 1 BTC long, TradingView sends b=sell q=1 for that fill. That is an exit on a spot pair. On a futures or margin account, check that a sell of that size closes the position rather than opening a new one, or use example 2 for exits.
2. Close the position
In Pine, give the close its own command:
strategy.close("Long", alert_message="s=BTCUSDT c=position")and set the Message field to {{strategy.order.alert_message}}. c=position closes the open position on s=, whatever its size. Add q=50% to close half: on a close, q= is a share of the position, not of your balance. This works on exchanges that hold positions. Close or reverse, by exchange lists which ones do.
3. Entry with a stop-loss and take-profit (OANDA)
s=EUR_USD b=long q=1000 t=market & sl=-1% tp=2%On OANDA this buys 1,000 units of EUR_USD and attaches a stop-loss 1% below the current price and a take-profit 2% above it. The part after & is read together with the part before it. Autoview adds each offset to the price exactly as written, so for b=short write sl=1% tp=-2%. Brackets work differently on each exchange: check your exchange's command reference, and the stop-loss and take-profit guide.
4. Size as a percent of your balance
s=BTCUSDT b=buy q=5% t=marketq=5% sizes the order at 5% of your available balance on the exchange, not the strategy's contract count. On a Kraken spot buy, for example, that is 5% of the quote currency you have available, turned into coins at the current price, and on a sell it is 5% of the coin you hold. Add y=equity to measure against your full balance instead of what is available. Bybit and OANDA also multiply by your leverage, so check your exchange's command reference before you size a live order this way.
5. Limit order at the strategy's fill price
s=BTCUSDT b={{strategy.order.action}} q={{strategy.order.contracts}} t=limit fp={{strategy.order.price}}fp= sets the limit price to the price TradingView's simulated broker filled at. If the market has moved on by the time the alert arrives, an order at that price may not fill right away, or at all.
6. Dry run with d=1
s=BTCUSDT b={{strategy.order.action}} q={{strategy.order.contracts}} t=market d=1With d=1, Autoview builds the order and writes it to your log without sending it to the exchange. Only the value 1 turns it on. Compare the logged side and size with the trade in TradingView's strategy report, then remove d=1. Without an active subscription for the exchange, Autoview runs every command this way.
Common questions
Which TradingView placeholder goes in b=?
{{strategy.order.action}}. TradingView fills it with buy or sell for the order that filled, and Autoview reads buy as the buy side and sell as the sell side.
Which TradingView placeholder goes in q=?
{{strategy.order.contracts}}, the size of the order that filled. Autoview passes a plain number to the exchange in that exchange's own order unit, so the strategy's size has to make sense there.
Why did my strategy alert place a limit order instead of a market order?
Autoview's default order type is limit. Add t=market to the command if you want a market order.
What happens if my alert sends b=flat?
Autoview turns b=flat into c=all, which cancels orders and closes positions. Only the Tradovate connector carries out c=all. On other exchanges the alert stops with an unsupported feature error, so close with c=position instead.
Do I need TradingView to send these commands?
No. Any system that can send a webhook can send Autoview the same command text. The placeholders on this page are TradingView's, filled in by TradingView before it sends the alert.
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.