Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancelling order by its OrderId

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

    Cancelling order by its OrderId

    Hello,
    I have a multi-instrument strategy. I want to cancel an order by its OrderId (e.g. 'a001257ee0f1422f810a5cef1f1be612'):

    public void CancelMyOrder(String orderId)
    {
    foreach (IOrder ord in Orders)
    {
    if (String.Equals(ord.OrderId, orderId, StringComparison.Ordinal))
    {
    CancelOrder(ord);
    break;
    }
    }
    }

    But it doesn't cancels the order. Moreover, after the first attempt to call this function, it becomes unable to send new orders. I don't see any error in Output window, and nothing related to the cancel attempt in the Log tab.

    Please advise

    #2
    Hello Velox,

    Thank you for your post.

    I would run a print statement to ensure that the correct OrderId is being called and the correct IOrder object as well.

    Additionally, custom are not support with NinjaTrader so it's hard to say what the expected outcome of this is right now.

    You can create your own IOrder objects and use those to call for the CancelOrder() instead of running a loop.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Cal View Post
      Hello Velox,

      Thank you for your post.

      I would run a print statement to ensure that the correct OrderId is being called and the correct IOrder object as well.

      Additionally, custom are not support with NinjaTrader so it's hard to say what the expected outcome of this is right now.

      You can create your own IOrder objects and use those to call for the CancelOrder() instead of running a loop.
      Cal,
      I see. I can keep the orders in a local Dictionary. I'm using IOrder order = SubmitOrder() approach. But is there a unique ID at this stage? Documentation says that OrderID may change, but I see that it changes only from Initialized to PendingSubmit status.

      Or should I put those orders in a List<IOrder> and loop over it?
      Thank you

      Comment


        #4
        How many active orders are you going to have?

        If its just the one, you won't need to store it in a list but rather check it with OnOrderUpdate() and use it that way.

        http://www.ninjatrader.com/support/h...rderupdate.htm
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          I may have several orders in parallel.

          Comment


            #6
            Velox,

            You will want to take a look at sample reference below on using a list for your order tracking -
            http://www.ninjatrader.com/support/f...ead.php?t=5790

            Let me know if I can be of further assistance.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Cal View Post
              Velox,

              You will want to take a look at sample reference below on using a list for your order tracking -
              http://www.ninjatrader.com/support/f...ead.php?t=5790

              Let me know if I can be of further assistance.
              Cal,
              Yes, please help me to find a workaround. The problem I'm working on is connection of software called bookmap (bookmap.com) to NinjaTrader. So, this Ninja script Strategy is not a standard NT strategy, but a visualization tool.
              It means, I need to track and visualize all user's orders even if they were sent from NinjaTrader and not by my strategy. I hope this is not something impossible. Using 'OnOrderUpdate()' I'm able to track the orders, and save them in an internal Dictionary<string, IOrder> where string is order's Token. I'm also able to cancel them. But I don't receive updates about other orders, that were sent not by my script.
              So, I tried a different approach.
              protected override void OnStartUp()
              {
              ... omitted code
              account.OrderStatus += new OrderStatusEventHandler(order_status);
              }

              protected override void OnTermination()
              {
              ... omitted code
              account.OrderStatus -= new OrderStatusEventHandler(order_status);
              }

              and implemented:
              private void order_status(object sender, OrderStatusEventArgs os)
              {
              IOrder order = (IOrder)os.Order;
              }
              In this case I do receive updates on external orders, but I cannot and store these orders "os.Order" in a local Dictionary, and cannot cancel them when needed.
              This casting doesn't work:

              Please advise
              Last edited by velox; 02-11-2014, 01:18 PM.

              Comment


                #8
                Here is a much simpler description of the problem. I need to be able to cancel the orders, that were sent not by the strategy. To do so, I need one of the two solutions:

                1) How to receive OnOrderUpdate(IOrder) on orders that was sent not by the strategy

                2) How to access to IOrder object from the:
                private void order_status(object sender, OrderStatusEventArgs os)
                where order_status() is a callback for:
                account.OrderStatus += new OrderStatusEventHandler(order_status);

                Thank you

                Comment


                  #9
                  You may want to look into this thread below on how to access the account positions but please note that this is unsupported territory -
                  http://www.ninjatrader.com/support/f...ad.php?t=62525
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Cal View Post
                    You may want to look into this thread below on how to access the account positions but please note that this is unsupported territory -
                    http://www.ninjatrader.com/support/f...ad.php?t=62525
                    It describes tracking position, but I need the orders for a single account. Is this unsupported?

                    Comment


                      #11
                      Hello velox,

                      This would also be unsupported. Unfortuantely, I do not have a sample or thread to provide for this unsupported item.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      662 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      376 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      110 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      575 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      580 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X