Places a buy or sell order that adds to or reduces the net position, ignoring pyramiding and reversal rules.
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
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)) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | series string | required | A 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. |
| direction | series strategy_direction | required | The side of the order: strategy.long to buy or strategy.short to sell. |
| qty | series int/ | the strategy's default quantity | How many contracts, shares or units to trade. When na or left out, default_qty_type and default_qty_value from the strategy() header decide. |
| limit | series int/ | na | A limit price: a buy fills at this price or lower, a sell at this price or higher. |
| stop | series int/ | na | A stop price: a buy triggers when the price rises to it, a sell when the price falls to it. |
| oca_name | series string | an empty string | The name of an OCA (one cancels all) group. Orders sharing a name are linked as oca_type says. |
| oca_type | input string | strategy. | How 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. |
| comment | series string | an empty string | Text shown next to the order on the chart and in the list of trades. |
| alert_message | series string | an empty string | Text sent as {{strategy.order.alert_message}} in an alert created on the strategy when this order fills. |
| disable_alert | series bool | false | When true, an alert on the strategy does not fire for this order's fill. |
Returns
Nothing.
Remarks
strategy.exit()andstrategy.close()find trades by the id they were opened with, whether it came fromstrategy.entry()orstrategy.order(). Usestrategy.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
//@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