Sidechair

strategy.* constants

Browse the reference

Constants for strategy settings and orders: direction, position sizing type, commission type, OCA group behaviour and allowed trade direction.

Try it in the editor

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

NameValueDescription
strategy.cashOrder size is a fixed amount of account currency.
strategy.commission.cash_per_contractCommission is a currency amount per contract traded.
strategy.commission.cash_per_orderCommission is a currency amount per order.
strategy.commission.percentCommission is a percentage of the order's value.
strategy.direction.allAllow entries in both directions.
strategy.direction.longAllow only long entries.
strategy.direction.shortAllow only short entries.
strategy.fixedOrder size is a fixed number of contracts.
strategy.longThe long direction for an order.
strategy.oca.cancelWhen one order fills, cancel the others in the group.
strategy.oca.noneThe order does not belong to an OCA group.
strategy.oca.reduceWhen one order fills, reduce the others by the filled quantity.
strategy.percent_of_equityOrder size is a percentage of current equity.
strategy.shortThe 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

Pine ScriptStrategy header with constantsOpen in editor
//@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)
Pine ScriptCommission, direction and OCAOpen in editor
//@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