Support Board
Date/Time: Thu, 28 Nov 2024 12:33:51 +0000
sc.CancelOrder() cancelling *ALL* filled orders ALSO?
View Count: 293
[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
|
[2023-05-05 21:09:57] |
Sierra_Chart Engineering - Posts: 17201 |
You need to look at the Trade >> Trade Activity Log and find out what is canceling those orders you are referring to. : Trade Activity Log Analysis: Determining the Origin of a New/Modified Order Also an order that has filled can no longer be canceled and if you attempt to cancel it is not going to do any harm. Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2023-05-11 21:33:32] |
User133994 - Posts: 80 |
Support, Thanks so much for your quick response and debugging idea. It worked. It turns out sc.CancelOrder() doesn't cancel existing positions like I thought. Instead, the opposite occurred: I exited the existing positions then called sc.CancelOrder(). "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." -- must be an incorrect statement. Debugging fun, I'm sure you've been there. Appreciate your help. Always encouraged by the SC staff. Date Time Of Last Edit: 2023-05-11 21:35:14
|
To post a message in this thread, you need to log in with your Sierra Chart account: