¿ªÔÆÌåÓý

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 ?

Join [email protected] to automatically receive all group messages.