Skip to main content

Cancel and Bracket

Overview

The CANCELANDBRACKET command atomically replaces all working orders on an instrument with a new take-profit and/or stop-loss bracket (OCO pair). The typical use case is a strategy signal that needs to move stops or targets without leaving the position unprotected between the cancel and the new bracket placement.

This is a common problem with the traditional two-step approach of sending a CANCELORDERS followed by a PLACE for the new bracket. In the gap between those two commands, the position has no protective orders. If the market moves sharply during that window, there's nothing to limit your loss. CANCELANDBRACKET eliminates that gap by handling both steps internally with built-in safety checks.

info

CancelAndBracket requires the XT Add-On v1.12.0+ connected to your account. It is not classified as an opening order — trade windows and "closing only" mode will not block it.


How It Works

At a high level, CANCELANDBRACKET does three things: it cancels every working order on the instrument, waits briefly for the broker to process those cancellations, and then places your new bracket orders.

Before any of that happens, the command runs through the same safety checks as a normal order. If you're using Strategy Lock, ownership is verified. A different strategy cannot move the stops on a position it doesn't own. Opposing Position Protection is also checked to make sure the new bracket won't create a conflict.

The add-on automatically reads your live position size and clamps the bracket quantity to match. If you send QTY=5 but you're only holding 3 contracts, the bracket is placed for 3. This prevents an oversized bracket from accidentally opening a position in the opposite direction.

There's also a built-in safety net for the cancel window itself. If a stop-loss fills during the brief gap between canceling old orders and placing new ones — meaning the position goes flat — the add-on detects this and aborts the bracket placement entirely. Without this check, your new bracket orders would become naked entries in the opposite direction. See Cancel Window Safety for details.


Webhook Fields

FieldRequiredDescription
COMMANDYesCANCELANDBRACKET
KEYYesYour CrossTrade secret key
ACCOUNTYesTarget account name (e.g., Sim101)
INSTRUMENTYesInstrument name (e.g., ES 09-25, NQ1!)
ACTIONYesThe position side being protected: BUY = you are long, SELL = you are short. The add-on inverts this to determine exit direction.
QTYYesBracket quantity. Automatically clamped to the live position size if larger.
TAKE_PROFITNoLimit price for the take-profit leg. Supports %, $, tick, and point offsets if a quote is available.
STOP_LOSSNoStop price for the stop-loss leg (StopMarket). Same offset support as take-profit.
OCO_IDNoCustom OCO ID to link the bracket legs. Auto-generated if omitted.
STRATEGY_TAGNoStrategy tag for position locking.
warning

At least one of TAKE_PROFIT or STOP_LOSS must be provided — otherwise the command cancels all working orders and places nothing, which is just a CANCELORDERS.


Action Field Behavior

The ACTION field in CANCELANDBRACKET works differently than in PLACE. Here, it describes the position you are protecting, not the order you are submitting.

ACTION valuePosition you holdExit orders placed as
BUYLongSell
SELLShortBuy to Cover

This design lets you use a single, consistent alert payload — your strategy always sends ACTION=BUY when it's long and ACTION=SELL when it's short. The add-on handles the inversion internally.

info

NinjaTrader's standard API defines "Action" as the order direction (e.g., "Buy to Cover"). CrossTrade's CANCELANDBRACKET intentionally departs from this convention so that the action always matches the position side being protected, which is more intuitive for alert-based workflows.


Example Payloads

Replacing a bracket on a long position

You're long 2 ES and want to move your stop and target:

key=your-secret-key;
command=CancelAndBracket;
account=Sim101;
instrument=ES 06-26;
action=BUY;
qty=2;
take_profit=6620;
stop_loss=6580;

This cancels all working orders on ES 09-25 in Sim101, then places a new Sell Limit at 5620.00 (take-profit) and a Sell StopMarket at 5580.00 (stop-loss), linked as an OCO pair.

Replacing a bracket on a short position

key=your-secret-key;
command=CancelAndBracket;
account=Sim101;
instrument=NQ 06-26;
action=SELL;
qty=1;
take_profit=24400;
stop_loss=24100;

Using offset-based prices

Instead of absolute prices, you can use tick, percentage, dollar, or point offsets. These are resolved server-side against the current quote before being sent to the add-on.

key=your-secret-key;
command=CancelAndBracket;
account=Sim101;
instrument=ES 06-26;
action=BUY;
qty=2;
take_profit=40 ticks;
stop_loss=20 ticks;

warning

Offset-based values are resolved against the current market quote at the time the command is processed. They are not recalculated from fill price the way PLACE bracket offsets are. If you need fill-price-relative brackets, use PLACE or FLATPLACE with take_profit and stop_loss offsets instead.

One-sided bracket (stop-loss only)

Both TP and SL are optional individually — you can place just one leg if needed:

key=your-secret-key;
command=CancelAndBracket;
account=Sim101;
instrument=ES 06-26;
action=BUY;
qty=2;
stop_loss=6580;

With Strategy Lock

key=your-secret-key;
command=CancelAndBracket;
account=Sim101;
instrument=ES 06-26;
action=BUY;
qty=2;
take_profit=6620;
stop_loss=6580;
strategy_tag=momentum;


Quantity Clamping

The bracket quantity is automatically clamped to the live position size to prevent unintended entries. This happens twice:

  1. Before the cancel phase — the position is read and the quantity is clamped if needed.
  2. After the cancel phase — the position is re-read. If a working order filled during the cancel window (e.g., a partial fill), the quantity is re-clamped to the new position size.

For example, if you send QTY=5 but the account is only long 3 contracts, the bracket is placed for 3 contracts. If during the cancel window a stop fills 1 contract, bringing the position to 2, the bracket is re-clamped to 2.

This only applies if there is an existing underlying position. CANCELANDBRACKET can still be used for order entry with no underlying position present, if you choose.


Cancel Window Safety

The most critical edge case CANCELANDBRACKET handles is what happens if the position is lost during the cancel window. For example, a stop-loss fills in the brief moment between canceling the old orders and placing the new bracket.

If the add-on detects that the position was open before the cancel phase but is now flat afterward, it aborts bracket placement entirely. Without this check, the new bracket orders would become naked exit orders that open a new position in the opposite direction.

When this abort path is triggered, the response looks like:

"Position flattened during cancel window (was 2, now flat). Bracket orders not placed to prevent unintended entry."

This is a safety feature, not an error. Your position was closed by a protective order doing its job. No further action is needed from the strategy. The next signal can open a fresh position normally.


Key Differences from PLACE Bracket Orders

BehaviorPLACE with TP/SLCANCELANDBRACKET
Cancels existing orders firstNoYes, all working orders on the instrument are canceled before bracket placement
Order type for stop-lossStopMarket or StopLimit (stop_loss_limit)StopMarket only
Offset resolutionOffsets are calculated from fill priceOffsets are resolved from current quote at command time
Opens a new positionYesNo, it protects an existing position. If no position exists, only the cancel phase runs.
Blocked by trade windowsYes (opening order)No, not classified as an opening order
Quantity behaviorUses the requested quantity directlyClamped to the live position size if larger

Important Notes

  • The stop-loss leg is always a StopMarket order. There is no STOP_LOSS_LIMIT / StopLimit support in CANCELANDBRACKET. If you need stop-limit exits, use PLACE with stop_loss_limit.
  • When both TP and SL are provided, they are OCO-linked automatically. If one fills, the other is canceled.
  • If neither TAKE_PROFIT nor STOP_LOSS is provided, the command still cancels all working orders but places no new orders.
  • CANCELANDBRACKET respects Opposing Position Protection and Strategy Lock. If either check fails, the entire operation is blocked before any orders are canceled.