Skip to content

Blog · TradingView · Article · updated 2026-09-25

Pine strategy alerts: {{strategy.order.action}} and friends explained

How TradingView strategy alerts fire, what {{strategy.order.action}} and {{strategy.market_position}} contain, and how to automate a Pine strategy with correct sizing.

Key takeaways

  1. 1Strategy alerts fire on each simulated fill of a Pine strategy.
  2. 2{{strategy.order.action}} is buy or sell; {{strategy.market_position}} is the position after the fill.
  3. 3Real order size comes from your TensorTrader policy, so match the strategy’s default order size.

What fires a strategy alert

A Pine strategy runs a simulated account: when its logic calls strategy.entry, strategy.exit or strategy.close, TradingView simulates a fill. A strategy alert fires on each of those simulated fills, in real time as new bars arrive. So a strategy alert is not a signal in the indicator sense; it is a report that the strategy just traded.

That makes strategies convenient for automation. Entries, exits, reversals and stop logic all live in the script, and one alert per token and timeframe carries all of them.

The strategy placeholders

{{strategy.order.action}}
buy or sell for the fill that triggered the alert
{{strategy.order.contracts}}
Quantity of that simulated fill
{{strategy.order.price}}
Simulated fill price
{{strategy.order.id}}
The order id from the script (for example "Long")
{{strategy.market_position}}
long, short or flat after the fill
{{strategy.market_position_size}}
Position size after the fill
{{strategy.prev_market_position}}
Position before the fill, useful to detect reversals

Turning fills into real orders

TensorTrader's strategy_v6 template maps these placeholders to its own actions. A buy that leaves you long opens or adds to a long; a sell that leaves you flat closes it; a sell that leaves you short from long is a reversal. Real order sizes come from your TensorTrader policy, not from the simulated contracts, so the strategy's Default order size should match the size you intend to trade. The extension's Strategy Properties card pre-fills it.

Strategy Properties that matter

Initial capital
Pre-filled from the exchange so percent-of-equity sizing matches
Default order size
Fixed USD size; also the total for DCA margin
Pyramiding
Extra pyramids + 1; how many entries in one direction the strategy allows
Commission
0.03 by default, so the simulation is not fee-free
Run mode
ALERT

Who manages the exits

With a strategy you choose how risk is handled. "Use strategy defaults" lets the script's own exits drive closes. "TensorTrader dynamic SL/TP" lets the engine manage stops and targets after the fill. "Fail-safe brackets only" keeps the strategy in charge but places protective brackets on the exchange in case an exit alert never arrives. The last option is a good default when you trust the strategy but not the plumbing.

Pitfalls

  1. 1Repainting: strategies that use future data or unconfirmed bars fire alerts that the chart later "changes its mind" about. Use bar-close logic.
  2. 2Order size mismatch: a strategy that sizes in contracts while your policy sizes in USD can produce surprising quantities. Align them.
  3. 3Too many pyramids: each extra entry pays fees; keep pyramiding modest.
  4. 4Backtest vs live: the simulated fill price is not your real fill price; slippage exists.

Reading a reversal

Reversals are where strategy alerts need care. When a strategy goes from long to short in one step, TradingView reports one fill with {{strategy.order.action}} = sell, {{strategy.prev_market_position}} = long and {{strategy.market_position}} = short. TensorTrader's template reads the before and after positions together, so it closes the long and opens the short instead of treating the sell as a plain exit. If your strategy uses strategy.close followed by a separate strategy.entry, you get two alerts instead; both work, but the single-step reversal costs one fewer round trip.

Frequently asked questions

Does a strategy alert fire on backtest trades?
No. It fires on new simulated fills as live bars arrive after the alert is created.
Is {{strategy.order.action}} always buy or sell?
Yes. Combine it with {{strategy.market_position}} to tell entries, exits and reversals apart.
Do strategy alerts include exits?
Yes, every simulated fill fires one, entries and exits alike.

Keep reading

Not financial advice. Performance figures are TensorTrader testnet or backtest results with the method stated; past results do not predict future returns.

All guides · Start on paper · Pricing