Login Page - Create Account

Support Board


Date/Time: Thu, 28 Nov 2024 12:34:42 +0000



Post From: sc.CancelOrder() cancelling *ALL* filled orders ALSO?

[2023-05-05 18:42:19]
User133994 - Posts: 80
Support,

Please assist with understanding why all the orders (working and filled) are cancelled and flattened when only sending sc.CancelOrder(OrderID5) which refers to only 1 working order?

Context: I have 5 brackets created at various distances from the close of the bar. Sometimes price action will trigger all 5, sometimes 4, sometimes 2, etc. So after a wait, I need to cancel the remaining working orders that haven't been filled. But, I don't want the existing filled orders to be cancelled, only the 5th order (in this example), because orders 1-4 were filled and are still waiting on their stop/target to exit. Yes, this is in sim mode...not a good thing to develop an algorithm w/live money.

Here is the function that verifies the order is not filled, and then cancels it:

void CheckAndCancelOrder(SCStudyInterfaceRef &sc, int orderID, SCString &r_lastDebugString, int whichone) {
s_SCTradeOrder ExistingOrderDetails;
SCString DebugString;
if (sc.GetOrderByOrderID(orderID, ExistingOrderDetails)) {
// If original submitted order is still working.
if (IsWorkingOrderStatus(ExistingOrderDetails.OrderStatusCode)) {
   DebugString.Format("helper: cancelled working order # %d.", whichone);
   sendDebugOnce(sc, DebugString, r_lastDebugString);
// Cancel the order
sc.CancelOrder(orderID);
}
}
}

Here is the many calls to the above function:

CheckAndCancelOrder(sc, pSO->Parent1InternalOrderID, r_lastDebugString, 1);
   if (pSO->Parent2InternalOrderID > 0)
   CheckAndCancelOrder(sc, pSO->Parent2InternalOrderID, r_lastDebugString, 2);
   if (pSO->Parent3InternalOrderID > 0)
   CheckAndCancelOrder(sc, pSO->Parent3InternalOrderID, r_lastDebugString, 3);
   if (pSO->Parent4InternalOrderID > 0)
   CheckAndCancelOrder(sc, pSO->Parent4InternalOrderID, r_lastDebugString, 4);
   if (pSO->Parent5InternalOrderID > 0)
   CheckAndCancelOrder(sc, pSO->Parent5InternalOrderID, r_lastDebugString, 5);


Problem line: sc.CancelOrder(orderID); in the CheckAndCancelOrder function. It works as expected, but then does more than expected.

Relevant line in the Message log:
Chart: Replay 2.00X: NQM23_FUT_CME[M]/MNQM23_FUT_CME [CV][M] 88 Trades #7 | Study: SELL array bot v 0.09 | helper: cancelled working order # 5. | 2023-05-05 13:52:11.230

Note: the helper debug line does *NOT* appear for orders 1-4 because those parent orders aren't working anymore--they already got filled.

But, simultaneously when that line posts in the Message log the filled orders (#1-4) also get flattened? There aren't any other "sc.CancelOrder()" function calls or even flatten or other functions. The stop/targets for the other 4 orders are 50+ ticks away from the current price when this message is posted in the log also--so no chance a stop/target got hit.

Thanks in advance for your assistance.
Date Time Of Last Edit: 2023-05-05 18:44:43