Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting Order object to IOrder, or cancelling user-made orders strategically

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

    Converting Order object to IOrder, or cancelling user-made orders strategically

    Hi,

    I have finally found a strategy that I think can work for me, but there is one issue I need to resolve in order to complete the code. I would need to be able to search for any pre-existing stop orders that the user might have sent before the strategy was turned on, and take control of them and cancel them, but my attempt to do so produced an error message saying that I couldn't convert an Order object into an IOrder object. Here's an example of the code:

    if(Account.Orders!= null)
    {
    OrderCollection acctOrders = Account.Orders;
    foreach (Order ord in acctOrders)
    {
    if(ord.Instrument.MasterInstrument.Name == Instrument.MasterInstrument.Name && ord.OrderType == OrderType.Stop && ord.OrderState == OrderState.Accepted)
    {
    IOrder orderToCancel = ord; <- This line here won't be accepted because it's converting Order to IOrder implicitly
    CancelOrder(orderToCancel);
    }

    }
    }

    Once I can know a way to grab and cancel orders that were not created by the strategy I will be ready to roll. Does anyone know what I'm missing? Thank you!

    #2
    Hi RunnrX,

    Is setting this to a variable necessary?

    Does CancelOrder(ord) not work?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for replying - but it seems that CancelOrder() only cancels IOrder objects and 'ord' is an Order object. I originally used CancelOrder(ord) and it gave me a compiler error making that distinction between IOrder and Order.

      Comment


        #4
        To update, I've found a workaround for the strategy that doesn't solve my original problem, but will make do. I'd still love to know if there is a solution to the original question if anyone can help. Thanks!

        Comment


          #5
          Hello ,

          Thanks for your reply.

          I understand the issue, the Order object class cannot be cast as an IOrder object.

          Using this method of looping through the account orders is not supported by NinjaTrader to do, also using the Order object is also not supported.

          I did some looking around to see if anyone else has accomplished this, but it seems this may not be possible.

          Below is a thread where this is discussed.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by RunnrX View Post
            To update, I've found a workaround for the strategy that doesn't solve my original problem, but will make do. I'd still love to know if there is a solution to the original question if anyone can help. Thanks!
            You would need to write a TypeConverter, or just a conversion method() for that matter.

            Comment


              #7
              Thank you ChelseaB and koganam. I can stop at this point because I've made a sufficient workaround, but yes some day it would be great to know how to strategically cancel pre-existing orders.. so far we can get information about them but can't manipulate them, and it would be important for when a strategy has to restart or in my case if an order was user-made. In any case, I'm ok going forward and I appreciate the help from both of you!

              If I knew how to write a converter myself.. I'd love to be able to do that kind of thing.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              656 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              371 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              574 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              579 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X