cTrader

AlgoWay Blog

Guides, manuals and platform references.

Core
JSON & Alerts
MT5 / Expert Advisors
Errors
Integrations
Other Publications
AlgoWay Strategy Lab

TradingView Order Actions: Why a Sell Can Be an Exit

Published December 1, 2026

A sell order branching into a long exit and a new short position

A sell notification can mean that a strategy closed a long trade. It can also mean that it opened a short trade, reduced a long position, or reversed from long to short. The word tells you the side of the transaction. It does not, by itself, tell you the purpose.

This distinction matters when TradingView alerts become automated orders. Before adapting a strategy to AlgoWay's TradingView automation workflow, identify what each fill is supposed to do. Treating every sell as a fresh short entry can turn an intended exit into new exposure.

Read order side alongside position state

TradingView defines {{strategy.order.action}} as the executed order's buy or sell side. It also provides previous and current strategy-position placeholders, plus order quantity. These describe the strategy's simulated state, not a confirmation from your connected broker. The definitions are in TradingView's strategy-alert reference.

For a diagnostic record, compare these fields:

  • {{strategy.order.action}}: the transaction side.
  • {{strategy.order.contracts}}: the quantity traded by that order.
  • {{strategy.prev_market_position}} and {{strategy.prev_market_position_size}}: the earlier direction and absolute size.
  • {{strategy.market_position}} and {{strategy.market_position_size}}: the resulting direction and absolute size.

This is a reading checklist, not a ready-to-send broker payload. Execution messages must use the destination's supported format and sizing rules.

Four sells, four different outcomes

Consider a simple strategy with one net position and quantities measured in the same units. The following are arithmetic illustrations, not recorded trades:

  • Long 6, sell 6, flat: the whole long position has been closed.
  • Long 6, sell 2, long 4: the strategy has taken a partial exit.
  • Flat, sell 3, short 3: the strategy has opened a short position.
  • Long 6, sell 9, short 3: six units close the long and three establish the short.

All four transactions have the same side. Their position transitions are different. The mirror image applies to buys: buying can open a long, reduce a short, close a short, or reverse a short into a long.

Now suppose a manual action has already closed the broker's long 6 while the strategy still thinks it holds that position. Replaying a sell quantity of 6 cannot be assumed to reproduce the simulated exit. The correct execution depends on the connector's command semantics and the account's actual state. See what a TradingView strategy knows about manual closes before trying to repair a mismatch with another signal.

Reversal quantity is not the final position size

By default, an opposite-direction strategy.entry() can reverse a position. TradingView adds the existing position size to the requested new size so that the transaction can close one side and establish the other. See the official reversal explanation.

In the long-6-to-short-3 illustration, the transaction is 9 but the final exposure is 3 short. A receiver expecting a transaction quantity and a receiver expecting a target position size would need different interpretations. Do not copy one number into a sizing field merely because both fields contain the word “size.”

Make entry and exit intent explicit where supported

If you control the Pine code, order-generating calls can supply custom alert_message text. The fill alert's Message field must include {{strategy.order.alert_message}} to use it. If a filled order has no custom message, that placeholder expands to an empty string. TradingView documents this in its order-fill alert guide.

Prepare supported entry and exit messages separately, including partial exits and reversals. Custom text is not automatically a valid execution command. For the Pine-side choice between market closes and price-based exits, read strategy.close versus strategy.exit.

Before enabling live routing, inspect a realtime demo example of every transition the strategy can produce. Compare the alert message, the intended action, the accepted order and the remaining account position. A successful entry proves only the entry path. The exit deserves its own examination.

Last updated: December 1, 2026