Sidechair

strategy.order()

Browse the reference

Places a buy or sell order that adds to or reduces the net position, ignoring pyramiding and reversal rules.

Try it in the editor

strategy.order(id, direction, qty) sends a raw order. Unlike strategy.entry, it is not an instruction to open a trade in one direction: it moves the net position by qty. A sell of 2 against a long of 3 leaves a long of 1, and a sell of 5 against a long of 3 ends as a short of 2.

It fills like any order: a market order at the next bar's open, a limit or stop order along the bar's price path. It ignores the pyramiding setting, so it can pile up as many same-direction orders as you send.

Syntax

Pine Script
strategy.order(id: series string, direction: series strategy_direction, qty: series int/float (optional), limit: series int/float (optional), stop: series int/float (optional), oca_name: series string (optional), oca_type: input string (optional), comment: series string (optional), alert_message: series string (optional), disable_alert: series bool (optional)) -> void

Arguments

NameTypeDefaultDescription
idseries stringrequiredA name for the order, used by strategy.exit(), strategy.close() and strategy.cancel() to find it and shown on the chart and in the trade list.
directionseries strategy_directionrequiredThe side of the order: strategy.long to buy or strategy.short to sell.
qtyseries int/floatthe strategy's default quantityHow many contracts, shares or units to trade. When na or left out, default_qty_type and default_qty_value from the strategy() header decide.
limitseries int/floatnaA limit price: a buy fills at this price or lower, a sell at this price or higher.
stopseries int/floatnaA stop price: a buy triggers when the price rises to it, a sell when the price falls to it.
oca_nameseries stringan empty stringThe name of an OCA (one cancels all) group. Orders sharing a name are linked as oca_type says.
oca_typeinput stringstrategy.oca.noneHow orders in the group interact: strategy.oca.cancel cancels the others when one fills, strategy.oca.reduce shrinks the others by the filled size, strategy.oca.none leaves them independent.
commentseries stringan empty stringText shown next to the order on the chart and in the list of trades.
alert_messageseries stringan empty stringText sent as {{strategy.order.alert_message}} in an alert created on the strategy when this order fills.
disable_alertseries boolfalseWhen true, an alert on the strategy does not fire for this order's fill.

Returns

Nothing.

Remarks

  • strategy.exit() and strategy.close() find trades by the id they were opened with, whether it came from strategy.entry() or strategy.order(). Use strategy.order() when you want to size positions yourself and track them with your own variables.
  • Replacing a pending order works the same as with strategy.entry: the same id modifies the order that is waiting.
  • Only available in strategy scripts.

Example

Pine ScriptScale in, scale outOpen in editor
//@version=6
strategy("Scale in and out", overlay = true, pyramiding = 3)
rsi = ta.rsi(close, 14)
if rsi < 30
    strategy.order("Buy", strategy.long, qty = 1)
if rsi > 70 and strategy.position_size > 0
    strategy.order("Trim", strategy.short, qty = 1)
plot(strategy.position_size, "Position", color.orange)

See also

Runs on Sidechair