Order

[[order]] places a “raw” buy (long) or sell (short) order. Unlike the standard entry block, it does not include automatic position management logic and simply executes the requested volume instruction.

Chaining after an Order block

An [[order]] block submits an order request. That request is then processed by the engine through its order pipeline, and the position state is updated on the next candle cycle. Depending on when the strategy evaluates the next block, some position information may not be up to date yet.

You control when the [[order]] block chains to the next block with the wait_candles key:

  • With wait_candles = 1, after a signal on a candle, the engine waits for the next candle before evaluating the next block, so position data (position, average price, and related fields) is up to date.
  • With wait_candles = 0, the next block is evaluated on the same candle as the signal, making the chaining immediate.

By default, wait_candles is 1.

In all cases, wait_candles does not change how the order is executed. It only shifts when the strategy moves on to the next block.

Differences with the Entry Block

While both blocks can be used to open a position, the Order block is characterized by a much more permissive and manual behavior:

FeatureEntry BlockOrder Block
PyramidingRespects the global limit. Entry is blocked if the maximum number of positions is reached.Ignores the limit. Allows adding volume even if the pyramiding limit is exceeded.
Opposite DirectionAutomatic Reversal: Closes the entire opposite position before opening the new one.Additive Reduction: Simply reduces the opposite position by the requested amount (or partially reverses).
Recommended UseRecommended for 99% of strategies.Expert use (complex leg management, specific hedging).

In most cases, prefer [[Entry]]: it respects pyramiding and handles reversals cleanly. [[order]] is for advanced use and requires precise exposure control.

Order type

The order type depends on whether limit and stop are provided. Without limit or stop, the block submits a market order. With limit only, it submits a limit order. With stop only, it submits a stop market order. With both limit and stop, it submits a stop-limit order. The stop level is the trigger. Once that level is reached, the order becomes a limit order at the limit price.

Block declaration

A strategy can contain multiple [[order]] blocks.

Examples

Minimal order

This example places a basic long order with a fixed quantity and then moves to monitor_exit.

[[order]]
id            = "buy_order_1"
order_id      = "buy_1"
direction     = "long"
qty           = 1
next_block_id = "monitor_exit"

Stop-limit order

This example places a long stop-limit order. When the market reaches stop, Whale-E activates a limit order at the limit price, then the strategy moves to next_step.

[[order]]
id            = "breakout_long"
order_id      = "long_bk"
direction     = "long"
stop          = "high + 10"
limit         = "high + 10"
next_block_id = "next_step"

OCA group across multiple orders

In this example, the two [[order]] blocks create two distinct orders that belong to the same OCA group. If one order is filled, the other is cancelled. An OCA group therefore links multiple distinct orders. It is not the association between limit and stop inside a single block.

[[order]]
id            = "breakout_long"
order_id      = "long_bk"
direction     = "long"
stop          = "high + 10"
oca_name      = "breakout_grp"
oca_type      = "cancel"
next_block_id = "next_step"

[[order]]
id            = "breakout_short"
order_id      = "short_bk"
direction     = "short"
stop          = "low - 10"
oca_name      = "breakout_grp"
oca_type      = "cancel"
next_block_id = "next_step"

Block Parameters

ParameterDescription
id
 Text
 Required
Unique identifier for the block within the strategy flow.
order_id
 Text
 Required
Identifier specific to this order. It is used to identify the orders emitted by this block, in particular when a [[cancel]] block needs to cancel the corresponding pending orders. It is not used by [[close]]. It is also not used by the from_entry filter of [[exit]], which can only reference an entry created by a [[entry]] block. When from_entry is omitted, [[exit]] applies to the open position without distinguishing whether it comes from [[entry]] or [[order]].
next_block_id
 Text
 Required
Identifier of the next block to execute.
direction
 Text
 Optional
Order direction: "long" (buy) or "short" (sell).
Default: "long"
qty
 Decimal or Text
 Optional
Absolute quantity (number of contracts/shares). Overrides global settings.
qty_percent
 Decimal or Text
 Optional
Percentage of equity. This parameter replaces the global sizing for that order. Note: qty and qty_percent cannot be used in the same block.
limit
 Decimal or Text
 Optional
Limit price for the order. Without stop, this parameter creates a limit order. With stop, it defines the limit price of a stop-limit order.
stop
 Decimal or Text
 Optional
Stop price for the order. Without limit, this parameter creates a stop market order. With limit, it defines the trigger price of a stop-limit order.
oca_name
 Text
 Optional
Name of an OCA group shared by multiple distinct orders.
oca_type
 Text
 Optional
Action applied to the other orders in the same OCA group: "cancel", "reduce", or "none".
Default: "cancel"
comment
 Text
 Optional
Populates the Signal column in the trade list when provided; otherwise order_id is used. Also exported as the Pine Script comment. No impact on backtest calculations.
alert_message
 Text
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script alert_message parameter.
disable_alert
 Boolean
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script disable_alert parameter.
Default: false
wait_candles
 Integer
 Optional
Number of candles to wait before moving to the next block. This delay only affects the transition; it does not change order execution.
Default: 1

Local sizing priority

In [[order]], the engine always follows the same priority:

  1. if qty is defined, that absolute quantity is used
  2. otherwise, if qty_percent is defined, that equity percentage is used
  3. otherwise, the engine falls back to the global [backtest] configuration

In other words, qty and qty_percent make the global sizing inactive for that order.

Meaning of qty_percent

In [[order]], qty_percent always means a percentage of equity.

When qty_percent is present, [[order]] is treated as a percent_of_equity order, even if [backtest].default_qty_type is fixed or cash.

For details about sizing price versus execution price, refer to Using Margin and Leverage in Whale‑E.