Skip to main content

Class: Order

Fluent builder for an order group with multiple entry legs and/or multiple take-profit legs: the full model the backtester supports. Chain legs, then call .submit(). For the common single-market-entry case prefer strategy.long/short. weight is each leg's fraction of the group's qty.

strategy.order("breakout", Side.Long) .limitEntry(close * 0.99, 0.5).limitEntry(close * 0.98, 0.5) .takeProfit(close * 1.02, 0.5).takeProfit(close * 1.05, 0.5) .stopLoss(close * 0.97).qtyPercentEquity(100).submit();

Exit legs take an optional exitId: legs sharing an id form one exit (one-cancels-other) for weight of the position, amendable later with strategy.edit(groupId). Without an id a take profit closes its weight and the stop loss / trailing stop covers whatever remains.

Constructors​

Constructor​

new Order(groupId, side): Order

Parameters​

groupId​

string

side​

Side

Returns​

Order

Methods​

alertMessage()​

alertMessage(text): Order

Text of this order's fill alert: {{strategy.order.alert_message}} (Pine alert_message).

Parameters​

text​

string

Returns​

Order


cancelOnTpBeforeFill()​

cancelOnTpBeforeFill(value?): Order

Cancel still-pending entry legs if price hits a TP before they fill.

Parameters​

value?​

bool = true

Returns​

Order


comment()​

comment(text): Order

Signal name shown in the backtest trade list.

Parameters​

text​

string

Returns​

Order


disableAlert()​

disableAlert(value?): Order

Fills of this order fire no order-fill alert (Pine disable_alert).

Parameters​

value?​

bool = true

Returns​

Order


entry()​

entry(limit?, stop?, weight?): Order

Entry leg from optional prices (Pine strategy.entry(limit=, stop=)): market when both are na, else limit, stop-market or stop-limit.

Parameters​

limit?​

f64 = NaN

stop?​

f64 = NaN

weight?​

f64 = 1.0

Returns​

Order


limitEntry()​

limitEntry(price, weight?): Order

Parameters​

price​

f64

weight?​

f64 = 1.0

Returns​

Order


marketEntry()​

marketEntry(weight?): Order

Parameters​

weight?​

f64 = 1.0

Returns​

Order


netPosition()​

netPosition(): Order

Net against the open position (reduce it, then open the excess) instead of close-and-reverse; not counted for pyramiding (Pine strategy.order).

Returns​

Order


qtyFixed()​

qtyFixed(value): Order

Parameters​

value​

f64

Returns​

Order


qtyPercentEquity()​

qtyPercentEquity(value): Order

Parameters​

value​

f64

Returns​

Order


qtyQuote()​

qtyQuote(amount): Order

Size in quote currency (e.g. 1000 USDT).

Parameters​

amount​

f64

Returns​

Order


qtyRiskBased()​

qtyRiskBased(riskPct): Order

Parameters​

riskPct​

f64

Returns​

Order


stopLimitEntry()​

stopLimitEntry(stop, limit, weight?): Order

Parameters​

stop​

f64

limit​

f64

weight?​

f64 = 1.0

Returns​

Order


stopLoss()​

stopLoss(price, weight?, exitId?): Order

Parameters​

price​

f64

weight?​

f64 = 1.0

exitId?​

string = ""

Returns​

Order


stopLossDistance()​

stopLossDistance(dist, weight?, exitId?): Order

Stop loss dist (price units) behind the average entry, re-derived on every fill.

Parameters​

dist​

f64

weight?​

f64 = 1.0

exitId?​

string = ""

Returns​

Order


stopMarketEntry()​

stopMarketEntry(stop, weight?): Order

Entry that becomes a market order once price trades through stop.

Parameters​

stop​

f64

weight?​

f64 = 1.0

Returns​

Order


submit()​

submit(): void

Returns​

void


takeProfit()​

takeProfit(price, weight?, exitId?): Order

Parameters​

price​

f64

weight?​

f64 = 1.0

exitId?​

string = ""

Returns​

Order


takeProfitDistance()​

takeProfitDistance(dist, weight?, exitId?): Order

Take profit dist (price units) beyond the average entry, re-derived on every fill.

Parameters​

dist​

f64

weight?​

f64 = 1.0

exitId?​

string = ""

Returns​

Order


trailingStop()​

trailingStop(offsetPct, activation?, weight?, exitId?): Order

Trailing stop at offsetPct percent from the best price since entry. activation (a price) delays trailing until price reaches it. The stop only tightens. Combine with .stopLoss(...) for the initial stop.

Parameters​

offsetPct​

f64

activation?​

f64 = NaN

weight?​

f64 = 1.0

exitId?​

string = ""

Returns​

Order


trailingStopDistance()​

trailingStopDistance(offset, activationPrice?, activationDistance?, weight?, exitId?): Order

Trailing stop offset (price units) behind the best price. Arms at activationPrice, or activationDistance beyond the average entry, or on the first fill when both are na.

Parameters​

offset​

f64

activationPrice?​

f64 = NaN

activationDistance?​

f64 = NaN

weight?​

f64 = 1.0

exitId?​

string = ""

Returns​

Order