¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

need help with stoploss of bracket order


 

Hello
?
We are trying to send a bracket order via API. We are encountering a problem with the stop loss part of the order. it doesn¡¯t seem to work properly and do not execute the stop order at the price we set.

We tried many different ways and objectives and all gave the same results ¨C no execution.

1.?What do we have to send in order to fix this problem? In order to execute the stop loss as intended.
2.?How does the stop loss order works? Is it triggered only by last trade price or can it be triggered by quotes as well? For example, we set the stop at 30. The price of the asset now is 20 bid ¨C 21 ask, last trade is still at 40. Should the stop order triggered? Or?wont triggered until last trade would be 30 or less?

?


Contract contract = new()

? ? ? ? ? ? {

? ? ? ? ? ? ? ? Symbol = closestContract.Symbol,

? ? ? ? ? ? ? ? SecType = closestContract.SecType,

? ? ? ? ? ? ? ? Exchange = closestContract.Exchange,

? ? ? ? ? ? ? ? Currency = closestContract.Currency,

? ? ? ? ? ? ? ? LastTradeDateOrContractMonth = closestContract.LastTradeDateOrContractMonth,

? ? ? ? ? ? ? ? LocalSymbol = closestContract.LocalSymbol,

? ? ? ? ? ? ? ? Strike = strike,

? ? ? ? ? ? ? ? Right = tickerType == Enumerators.Calls ? "C" : "P",

? ? ? ? ? ? ? ? Multiplier = closestContract.Multiplier,

? ? ? ? ? ? };

?

?

? ?{

? ? ? ? ? ? //TWS API

? ? ? ? ? ? //This will be our main or "parent" order

? ? ? ? ? ? Order parent = new Order();

? ? ? ? ? ? parent.OrderId = parentOrderId;

? ? ? ? ? ? parent.Action = action;

? ? ? ? ? ? parent.OrderType = "LMT";

? ? ? ? ? ? parent.TotalQuantity = quantity;

? ? ? ? ? ? parent.LmtPrice = limitPrice;

? ? ? ? ? ? parent.AuxPrice = stopLossPrice;

? ? ? ? ? ? parent.Tif = "GTC";

? ? ? ? ? ? //The parent and children orders will need this attribute set to false to prevent accidental executions.

? ? ? ? ? ? //The LAST CHILD will have it set to true,?

? ? ? ? ? ? parent.Transmit = false;

?

? ? ? ? ? ? Order takeProfit = new Order();

? ? ? ? ? ? takeProfit.OrderId = parent.OrderId + 1;

? ? ? ? ? ? takeProfit.Action = action.Equals("BUY") ? "SELL" : "BUY";

? ? ? ? ? ? takeProfit.OrderType = "LMT";

? ? ? ? ? ? takeProfit.TotalQuantity = quantity;

? ? ? ? ? ? takeProfit.LmtPrice = takeProfitLimitPrice;

? ? ? ? ? ? takeProfit.ParentId = parentOrderId;

? ? ? ? ? ? takeProfit.Transmit = false;

? ? ? ? ? ? takeProfit.Tif = "GTC";

?

? ? ? ? ? ? Order stopLoss = new Order();

? ? ? ? ? ? stopLoss.OrderId = parent.OrderId + 2;

? ? ? ? ? ? stopLoss.Action = action.Equals("BUY") ? "SELL" : "BUY";

? ? ? ? ? ? stopLoss.OrderType = "STP";?

? ? ? ? ? ? stopLoss.AuxPrice = stopLossPrice;

? ? ? ? ? ? stopLoss.TotalQuantity = quantity;

? ? ? ? ? ? stopLoss.ParentId = parentOrderId;?

? ? ? ? ? ? stopLoss.Transmit = true;

? ? ? ? ? ? stopLoss.Tif = "GTC";

?

? ? ? ? ? ? List<Order> bracketOrder = new List<Order>();

? ? ? ? ? ? bracketOrder.Add(parent);

? ? ? ? ? ? bracketOrder.Add(takeProfit);

? ? ? ? ? ? bracketOrder.Add(stopLoss);

? ? ? ? ? ? return bracketOrder;

? ? ? ? }

is there any issue with bracketorder ?


 

If I understand correctly, Daniel, the stop order is executed, just not at the price you are looking for?

You might want to read for more detail. The document stats with:

A Stop order is an instruction to submit a buy or sell market order if and when the user-specified stop trigger price is attained or penetrated. A Stop order is not guaranteed a specific execution price and may execute significantly away from its stop price.

The document also touches on the Trigger Methods used for Stop orders. The has a field where you may be able to select one of six different trigger methods. If you do not set that field, an instrument type specific trigger method is used (such as "last trade" or "double ask/bid").

´³¨¹°ù²µ±ð²Ô


On Thu, Jan 26, 2023 at 08:42 AM, Daniel Gitman wrote:

Hello
?
We are trying to send a bracket order via API. We are encountering a problem with the stop loss part of the order. it doesn¡¯t seem to work properly and do not execute the stop order at the price we set.

We tried many different ways and objectives and all gave the same results ¨C no execution.

1.?What do we have to send in order to fix this problem? In order to execute the stop loss as intended.
2.?How does the stop loss order works? Is it triggered only by last trade price or can it be triggered by quotes as well? For example, we set the stop at 30. The price of the asset now is 20 bid ¨C 21 ask, last trade is still at 40. Should the stop order triggered? Or?wont triggered until last trade would be 30 or less?

?

...

is there any issue with bracketorder ?