Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 04:45:26 +0000



Post From: Advanced Study: using both Attached Orders and BuyExit/SellExit

[2014-03-26 18:24:25]
User24178 - Posts: 4
Hi,
I need a code example on using BuyExit (SellExit) to close a position with Attached Orders. I am trying to do something like this:


if (sc.SetDefaults)
{
sc.SupportAttachedOrdersForTrading = true;
sc.CancelAllWorkingOrdersOnExit = true;
}

... // enter a trade with attached stop/target orders - SC shows entry executed and attached orders in effect

// now, need to force-exit the trade:
s_SCNewOrder order;
order.InternalOrderID = trade.GetEntryOrderId();
order.OrderType = SCT_ORDERTYPE_MARKET;
order.OrderQuantity = trade.GetSize();

int quantity = trade.IsLong() ? sc.BuyExit(order) : sc.SellExit(order);

Always get -1 with the same log message, e.g. "SellExit signal is ignored because Short position quantity does not exist or there are already working exit orders that will flatten the position. Current Position quantity with working exit orders: 0. Current Position quantity with exit market orders: 0 ".

Tried many variations of the above code (e.g. specifying OrderQuantity 0, not specifying InternalOrderId), with the same result.

Please help. Thank you!