strategy.entry() in Pine Script creates simulated entry orders and can reverse an existing position. strategy.exit() creates price-based exits such as stops and targets, while strategy.close() creates a market exit for an entry ID. strategy.order() creates a basic order whose filled quantity changes the net position. These commands operate in TradingView's broker emulator; an order fill alert is a separate route to an external execution service.

Strategy order functions at a glance
As of 25 September 2026, TradingView documents these distinctions.[1] The Pine Script library connects simulated orders to alert timing and message construction.
Scroll horizontally to read every column.
| Command | Main purpose | Important behaviour |
|---|---|---|
strategy.entry() |
Enter or reverse a position | Automatic reversal sizing; same-direction entries are subject to pyramiding. |
strategy.order() |
Place a basic order | Ignores pyramiding; filled quantity adds to or subtracts from the net position. |
strategy.exit() |
Create price-based exits | Can create a stop and target together; exit quantities can reserve position portions. |
strategy.close() |
Request a market exit | Its id is an entry ID, not a new exit ID. |
Which arguments control entry, exit and close?
The Pine Script v6 Reference Manual lists these complete signatures, as of 25 September 2026. Every command returns void; the effect is an order in the simulation.[10]
strategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, disable_alert)strategy.order(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, disable_alert)strategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, comment_profit, comment_loss, comment_trailing, alert_message, alert_profit, alert_loss, alert_trailing, disable_alert)strategy.close(id, comment, qty, qty_percent, alert_message, immediately, disable_alert)
The arguments that most often cause confusion:[10]
-
qtyinstrategy.entry()is the size of the resulting open trade. Instrategy.order()it is the quantity to trade. Whenqtyisna, both use thedefault_qty_typeanddefault_qty_valueof thestrategy()declaration. -
limitandstopin entry and order calls are prices. With neither, the command creates a market order that executes on the next tick. -
from_entryinstrategy.exit()links the exit to an entry ID. The default empty string generates exits for all open trades until the position closes. A value matching no trade in the position creates no exit orders.[1] -
idinstrategy.close()is the entry identifier of the open trades to close. With several entries sharing that ID, the close applies to all of them, starting from the first open trade. The defaultqty_percentis 100. -
immediatelyinstrategy.close()defaults to false. When true, the closing order executes on the same tick the strategy places it. -
disable_alert, when true as the command creates an order, stops that order's fill from triggering an alert.
TradingView's own reference examples place strategy.entry() calls inside if ta.crossover(...) and if ta.crossunder(...) blocks. The ta.crossover() and ta.crossunder() guide explains when those conditions are true.[10]
Trade allocation is a separate detail. The default close_entries_rule is "FIFO", so exits from strategy.exit() and strategy.close() start with the first open trade, even when the specified ID belongs to a different open trade. The maximum exit size still depends on the trades with that ID.[10]
Worked example: reversal size versus resulting position
Illustrative quantities, not recommended sizes. Start each case with a simulated long position of 10 units. Assume the commands are allowed and the resulting market orders fill.
Automatic reversal transaction size = existing opposite position size + requested new position size
| Request | Filled transaction | Resulting position |
|---|---|---|
strategy.entry(), short, qty = 4
|
Sell 10 + 4 = 14 units | Short 4 units |
strategy.order(), short, qty = 4
|
Sell 4 units | Long 10 − 4 = 6 units |
strategy.close() for the sole entry ID |
Sell 10 units | Flat: 10 − 10 = 0 |
For strategy.order(), use signed quantities: resulting position = existing position + filled order quantity. A sell larger than an existing long can therefore cross through zero. The command does not add the old position size automatically.[1]

Are stop and limit prices or distances?
For strategy.exit(), stop and limit are absolute prices. loss and profit are distances from the entry in chart-symbol ticks, not currency amounts or PineConnector pips.[1]
Long target price = entry price + profit × minimum tick
Long stop price = entry price − loss × minimum tick
Illustrative: an entry at 100 with minimum tick 0.25, profit = 20 and loss = 10 gives a target of 100 + 20 × 0.25 = 105 and a stop of 100 − 10 × 0.25 = 97.50. These are trigger levels, not promises about fill prices.[1]
In current v6, supplying both relative and absolute parameters for the same exit selects the level expected to trigger first. With that entry, profit = 20 implies 105, while limit = 103 places the target at 103. The December 2024 release notes document this change.[3]
The same argument names have different combinations. strategy.entry() or strategy.order() with both stop and limit creates one stop-limit order. strategy.exit() with both creates two exit orders: a stop loss and a take profit.[1]
How do pyramiding and OCA groups affect orders?
Pyramiding limits successive same-direction entries through strategy.entry(); it does not impose the same limit on strategy.order(). The strategy() declaration defaults pyramiding to 0, which allows only one entry order in the same direction.[2] TradingView also documents a caveat: multiple price-based entry orders created on one tick can fill beyond the pyramiding limit if price triggers them.[1]
One-Cancels-All (OCA) groups link what happens to other orders after one fills. strategy.oca.cancel cancels the others, strategy.oca.reduce reduces their sizes by the filled quantity, and strategy.oca.none leaves them independent. Entry and order calls default to the independent type.[1]
Orders from strategy.exit() use an OCA reduce group by default. Within a bracket, the first triggered exit fills and the competing exit is cancelled. Separate exit calls also reserve quantities: one call cannot exit a portion reserved by an earlier call.[1]
Illustrative reservation: a take-profit-only exit reserves 8 units of a 10-unit position. A later, separate stop-only exit requesting 10 can cover only the remaining 10 − 8 = 2 units. The two calls do not create full stop protection for all 10 units.
When does an order fill become an alert?
Calling an order function creates an order in the simulation; it is not itself a fill. By default, the earliest fill is the next available tick. For a strategy calculating at bar close, a market order normally fills at the next bar's open. Price-based orders can wait longer or remain unfilled.[1]
The current declaration reference distinguishes calc_on_every_tick for realtime updates from calc_on_every_history_tick for available historical ticks. calc_on_order_fills adds executions after fills. These settings change script calculation, while historical detail and order delay are separate choices.[2]
Illustrative sketch; not compiled or tested. The Pine Editor is the destination for this sketch. Arbitrary bar indices stage the events; they are not trading rules. Quantity 2 means two chart-symbol units, and profit/loss use chart-symbol ticks. The messages are plain notifications.
//@version=6
strategy("Order event examples", overlay = true)
if bar_index == 100
strategy.entry("L", strategy.long, qty = 2, alert_message = "Entry filled")
strategy.exit("Bracket", "L", profit = 20, loss = 10, alert_message = "Bracket exit filled")
if bar_index == 110
strategy.close("L", alert_message = "Market exit filled")
The bracket may close the simulated entry before the later market-close condition, leaving that close call with no matching open trade. Events on historical bars do not send alerts. The sketch illustrates order messages; it does not demonstrate realtime alert delivery.[1][5]
For a notification-only inspection, leave the Webhook URL field empty. Do not route these plain text messages as PineConnector instructions.
In Create Alert, select the strategy's order fill events. Put {{strategy.order.alert_message}} in the alert's Message field to use each order's alert_message. If an order-generating call omits that argument, the placeholder becomes empty for its fill.[4]
Dynamic values in alert_message are evaluated when the simulated order executes. TradingView's other alert placeholders belong in the alert's Message field, not nested inside the alert_message argument. Running alerts use a saved copy of the strategy and inputs; replace the affected alert after a configuration change.[4][5]
Two other Message-field placeholders matter: {{strategy.order.action}} reports buy or sell, and {{strategy.order.contracts}} reports the executed order quantity.[5] A sell can close a long, open a short or do both. In the reversal example it reports a sale of 14, not a final short position of 4.
The TradingView alert syntax guide covers message formatting. alert() calls and order fill alerts are separate event routes; including both can produce messages at different stages.[4]
What changes when orders are routed through PineConnector?
PineConnector's converter documentation describes messages added to supported entries and full exits, following simulated fills. It also states that the integration does not reproduce TradingView position sizing or automatically place its simulated stops and targets as protective broker orders.[6]
PineConnector's syntax reference gives broker-volume and stop/target units.[7] A chart's contract quantity is not a broker-lot conversion. Broker protection added through the converter operates separately and can close a position before TradingView's exit; the adapter does not resynchronise their positions.[6]
Before creating any executable PineConnector test alert, verify that every account sharing the chosen License ID is a demo account. Choose your own exact broker symbol, permitted volume and exit rules. A chart-contract count must not be substituted for broker lots without a verified conversion.[8]
Keep the chain distinct: order condition, simulated fill, alert trigger, webhook delivery, PineConnector processing, EA order request, broker acceptance, deal and resulting position. The demo test guide checks processing separately from the broker outcome.[8] MT5's order, deal and position definitions remain separate from the emulator.[9]
Which assumptions need a separate check?
- Simultaneous eligibility: inspect the emulator's price path, order types and documented OCA rules. The order of sentences in a rule description does not establish command precedence.
- Entry ID versus trade allocation: check the actual Trades records, including FIFO allocation, rather than inferring which entry closed from the message alone.
- Protection and position state: inspect the broker's accepted protective levels, resulting deals and remaining volume. A stop's activation is not proof of a completed close.
- Different execution clocks: intrabar recalculation, bar-close processing and external delivery can diverge. A simulated same-tick fill does not establish a same-price broker fill.
Frequently asked questions
What is the difference between strategy.entry() and strategy.order()?
strategy.entry() has automatic reversal sizing and observes the strategy's pyramiding rules for same-direction entries. strategy.order() ignores pyramiding and changes the position by the quantity it fills. Starting long 10 units, a short entry of 4 sells 14 to end short 4; a short order of 4 leaves long 6.
What is the difference between strategy.exit() and strategy.close()?
strategy.exit() creates price-based orders such as stop losses, take profits and trailing stops. strategy.close() creates a market exit associated with an entry ID. A close request is not a fill on the same calculation by default. Both operate in TradingView's broker emulator, not directly in an MT5 account.
Are strategy.exit() profit and loss values measured in money?
In strategy.exit(), profit and loss are distances in chart-symbol ticks from the simulated entry price. The corresponding absolute-price parameters are limit and stop. With entry 100 and tick size 0.25, a long's 20-tick target is 105. Broker lots and PineConnector pips use separate unit definitions.
Does a strategy order fill alert confirm an MT5 fill?
No. A strategy order fill alert records an event in TradingView's broker emulator. Webhook delivery, PineConnector processing, the EA's request and the broker's resulting deal still need verification. A strategy-only stop is also different from a protective stop accepted by the broker. Check the actual account's order history and position.
Reviewed 25 September 2026. Facts were checked against the linked sources on that date. Nothing in this article was tested on a trading account and no code was compiled.
Related reading
- Pine Script guide and function library
- Pine Script alert mechanisms
- TradingView alert syntax for automation
- Pine Script v5 versus v6
Sources
- TradingView – Strategies, accessed 25 September 2026.
- TradingView – Pine Script v6 reference: strategy() declaration, accessed 25 September 2026.
- TradingView – Release notes: December 2024 exit behaviour, accessed 25 September 2026.
- TradingView – Alerts: order fill events, accessed 25 September 2026.
- TradingView – Strategy alerts and placeholders, accessed 25 September 2026.
- PineConnector – Pine Script converter, accessed 25 September 2026.
- PineConnector – PineConnector Syntax, accessed 25 September 2026.
- PineConnector – Test your setup, accessed 25 September 2026.
- MetaQuotes – Basic principles: orders, deals and positions, accessed 25 September 2026.
- TradingView – Pine Script v6 Reference Manual: strategy.entry(), strategy.exit(), strategy.close() and strategy.order(), accessed 25 September 2026.
PineConnector executes the instructions you send it. It does not select trades, manage money, or hold funds. Trading carries risk, and past performance of any strategy does not indicate future results.