Constants for strategy settings and orders: direction, position sizing type, commission type, OCA group behaviour and allowed trade direction.
strategy.long and strategy.short are the direction argument of strategy.entry and strategy.order. strategy.fixed, strategy.cash and strategy.percent_of_equity go in strategy()'s default_qty_type: the default order size is a number of contracts, an amount of currency, or a percentage of equity. strategy.commission.percent, strategy.commission.cash_per_order and strategy.commission.cash_per_contract go in commission_type and say how commission_value is read.
strategy.direction.long, strategy.direction.short and strategy.direction.all go in strategy.risk.allow_entry_in and restrict which side may open a position. strategy.oca.cancel, strategy.oca.reduce and strategy.oca.none go in the oca_type argument of order functions: when one order in a group fills, the others are cancelled, reduced by the filled quantity, or left alone.
Constants
| Name | Value | Description |
|---|---|---|
strategy.cash | Order size is a fixed amount of account currency. | |
strategy.commission.cash_per_contract | Commission is a currency amount per contract traded. | |
strategy.commission.cash_per_order | Commission is a currency amount per order. | |
strategy.commission.percent | Commission is a percentage of the order's value. | |
strategy.direction.all | Allow entries in both directions. | |
strategy.direction.long | Allow only long entries. | |
strategy.direction.short | Allow only short entries. | |
strategy.fixed | Order size is a fixed number of contracts. | |
strategy.long | The long direction for an order. | |
strategy.oca.cancel | When one order fills, cancel the others in the group. | |
strategy.oca.none | The order does not belong to an OCA group. | |
strategy.oca.reduce | When one order fills, reduce the others by the filled quantity. | |
strategy.percent_of_equity | Order size is a percentage of current equity. | |
strategy.short | The short direction for an order. |
Remarks
- Orders created on a bar fill on the next bar, at its open, unless process_orders_on_close is true. Sizing and commission settings come from the strategy() call.
- With
strategy.commission.percent, commission_value = 0.1 means 0.1 percent of each order's value, charged on the entry and again on the exit.
Examples
//@version=6
strategy("Constants in use", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
strategy.entry("Short", strategy.short)
plot(fast, "Fast", color.blue)
plot(slow, "Slow", color.orange)//@version=6
strategy("Costs and limits", overlay = true, commission_type = strategy.commission.percent, commission_value = 0.05)
strategy.risk.allow_entry_in(strategy.direction.long)
if ta.crossover(ta.sma(close, 10), ta.sma(close, 30))
strategy.entry("Long", strategy.long, oca_name = "pair", oca_type = strategy.oca.cancel)
plot(ta.sma(close, 10), "Fast", color.blue)See also
Runs on Sidechair