Exit

[[exit]] manages exits for an open position by creating price-based orders. It can place a take profit, a stop loss, and a trailing stop. Orders remain pending until they are filled or cancelled.

For the overall sizing logic and the difference between absolute quantity, equity percentage, and position percentage, see Position sizing, margin, and leverage. This page only describes the [[exit]] block semantics.

When the block is evaluated again with the same order_id, Whale‑E updates the existing orders. When a parameter is no longer set, the corresponding order is cancelled.

If no exit level is defined (profit, limit, loss, stop, trail_price, trail_points), the block does not place any new order and cancels existing exit orders associated with order_id.

By default, after placing, updating or cancelling orders, the block validates on the current candle and control moves to the next block immediately. The wait_candles key only delays this transition; it does not change how orders are executed.

Block declaration

A strategy can contain multiple [[exit]] blocks. The order_id field identifies the exit orders managed by the block.

Examples

Take profit and stop loss

This example places a take profit and a stop loss using tick distances from the entry price.

[[exit]]
id       = "exit_main"
order_id = "exit_main"
profit   = 120
loss     = 80

Partial exit

This example closes 25% of the current position when the profit target is reached.

[[exit]]
id          = "take_partial"
order_id    = "take_partial"
qty_percent = 25
profit      = 100

Trailing stop

This example creates a trailing stop with activation and trailing distances defined in ticks.

[[exit]]
id           = "trail"
order_id     = "trail"
trail_points = 200
trail_offset = 100

Targeting a specific entry

This example applies the stop loss only to the entry whose order_id is add.

[[exit]]
id         = "exit_add"
order_id   = "exit_add"
from_entry = "add"
loss       = 60

Exit armed before a pending entry fills

This example arms a bracket on the same candle as an already submitted limit entry. If the main entry fills later, Whale-E then creates the exit orders using the levels evaluated when the arm_exit block ran.

[[entry]]
id            = "place_limit_entry"
order_id      = "main"
direction     = "long"
limit         = "close * 0.995"
wait_candles  = 0
next_block_id = "arm_exit"

[[exit]]
id            = "arm_exit"
order_id      = "main_exit"
from_entry    = "main"
profit        = 250
loss          = 150
wait_candles  = 0
next_block_id = "next_step"

Cancelling exit orders

This example cancels existing exit orders for exit_main by omitting all exit levels.

[[exit]]
id       = "cancel_exit"
order_id = "exit_main"

No delay

This example keeps the same exit levels but chains to the next block immediately.

[[exit]]
id           = "instant_exit"
order_id     = "instant_exit"
profit       = 50
loss         = 50
wait_candles = 0

Block parameters

ParameterDescription
id
 Text
 Required
Unique identifier for the block.
next_block_id
 Text
 Required
Identifier of the next block to execute.
order_id
 Text
 Required
Identifier of the exit orders managed by the block. Re-evaluating the block with the same order_id updates the existing orders.
from_entry
 Text
 Optional
When set, the block only applies to entries opened by a [[entry]] block whose order_id matches. It cannot target a [[order]] block.
Whale-E can also arm that exit before the actual fill of an already submitted pending entry.
In that case, exit parameters are evaluated when the [[exit]] block runs, and the exit orders are materialized when the targeted entry is actually filled.
Re-evaluating the same order_id replaces the existing deferred intent.
When omitted, the block applies to all open legs and remains active for new legs opened later on the same side while the position stays open.
qty
 Decimal or Text
 Optional
Fixed quantity to close. Number of contracts, shares, or units to exit. The quantity is rounded down to respect the market minimum contract size.
qty_percent
 Decimal or Text
 Optional
Percentage of the current position to close. In [[exit]], qty_percent always means a percentage of position, never a percentage of equity. Default value: 100.
profit
 Decimal or Text
 Optional
Take-profit distance, expressed in ticks from the entry price.
limit
 Decimal or Text
 Optional
Take-profit limit price. If both profit and limit are set, Whale‑E keeps the level closest to the entry price.
loss
 Decimal or Text
 Optional
Stop-loss distance, expressed in ticks from the entry price.
stop
 Decimal or Text
 Optional
Stop-loss stop price. If both loss and stop are set, Whale‑E keeps the level closest to the entry price.
trail_price
 Decimal or Text
 Optional
Trailing stop activation level, expressed as a price.
trail_points
 Decimal or Text
 Optional
Trailing stop activation distance, expressed in ticks from the entry price.
trail_offset
 Decimal or Text
 Optional
Trailing distance, expressed in ticks. Whale‑E only creates a trailing stop when an activation level (trail_price or trail_points) and trail_offset are both set.
oca_name
 Text
 Optional
OCA (One Cancels All) group name for the exit orders created by this block. When one order is filled, Whale‑E reduces the remaining size of the other orders in the group accordingly. When empty, Whale‑E uses an internal isolated group.
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.
comment_profit
 Text
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script comment_profit parameter. It does not affect the Signal column.
comment_loss
 Text
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script comment_loss parameter. It does not affect the Signal column.
comment_trailing
 Text
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script comment_trailing parameter. It does not affect the Signal column.
alert_message
 Text
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script alert_message parameter.
alert_profit
 Text
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script alert_profit parameter.
alert_loss
 Text
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script alert_loss parameter.
alert_trailing
 Text
 Optional
This parameter has no effect on backtests. It is only used to set the Pine Script alert_trailing 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 value: false.
wait_candles
 Integer
 Optional
Number of candles to wait before validating the block and moving to the next one. Use 0 to disable the delay. This delay does not change order execution.
Default value: 0