Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with CancelOrder()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem with CancelOrder()

    Hi, I am now trying to cancel my stoploss orders with CancelOrder(), but it can not cancel it and those stoploss order are still alive. the below link is methold with CancelOrder(), however, it can not work.the stoploss order is still in working status, if I change the stoploss price, it would be filled. the following is related code, it could print all the information

    if (myEntryOrder != null)
    {
    Print($"Debug - Order Name: {myEntryOrder.Name}, State: {myEntryOrder.OrderState}");
    Print($"Debug - Is Working: {myEntryOrder.OrderState == OrderState.Working}");
    Print($"Debug - Is Accepted: {myEntryOrder.OrderState == OrderState.Accepted}");

    bool shouldCancel = myEntryOrder.OrderState == OrderState.Working ||
    myEntryOrder.OrderState == OrderState.Accepted;

    Print($"Debug - Should cancel order: {shouldCancel}");

    if (shouldCancel)
    {
    CancelOrder(myEntryOrder);
    Print("cancel order 123");
    }
    }​
    Last edited by steinberg123; 11-08-2024, 02:38 AM.

    #2
    Hello steinberg123,

    Thank you for your post.

    This code is showing some logic for cancelling the entry order - are you trying to cancel your entry order and then the associated stop loss, or only the stop loss order?

    What kind of order are you using for your stop loss? An exit order, SetStopLoss()?

    If using the unmanaged approach, have these orders been tied via OCO?

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Hello steinberg123,

      Thank you for your post.

      This code is showing some logic for cancelling the entry order - are you trying to cancel your entry order and then the associated stop loss, or only the stop loss order?

      What kind of order are you using for your stop loss? An exit order, SetStopLoss()?

      If using the unmanaged approach, have these orders been tied via OCO?
      First, it is not to cancel the entry order but only the stop loss order. Secondly, it is just SetStopLoss(), but not an exit order. Of course, it is OCO linked with another profittarget order.
      Last edited by steinberg123; 11-10-2024, 07:41 PM.

      Comment


        #4
        from Chatgpt, it seems that the SetStopLoss() can not be cancelled??

        Comment


          #5
          Hello steinberg123,

          Can you please provide that code you are using to cancel the stop loss order then? The code posted is for canceling the entry order.

          Note that SetStopLoss() with SetProfitTarget() ties the entry to the exit, so canceling your stop loss order would also cancel your profit target because they are submitted as OCO.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          41 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          64 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X