Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I execute a CancelOrder and enter a new order at the same time?

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

    Can I execute a CancelOrder and enter a new order at the same time?

    I think I know the answer to this but want to make sure from you that know it all. I'm developing a strategy and within it there is a situation where I need to cancel one entry stop order and enter a new one in the opposite direction. Ideally I would do those at the same time within OnBarUpdate(). Though I've not seen it explicitly stated, I get the impression I need to execute the CancelOrder() and wait until OnExecutionUpdate() indicates that order has successfully executed before I can execute the new entry order command. I'd rather not have to have that latency but if it's the only way I can do it, such is life. So the question is, can I only execute at most one order for each iteration through OnBarUpdate() and have to wait for confirmation within OnExecutionUpdate(), or is there a way to execute two orders within the same iteration of OnBarUpdate() as long as they aren't conflicting.

    #2
    Hello dweems,

    This would depend on the script.

    If this is the unmanaged approach, you can cancel or submit orders any time.

    If this is the managed approach, it takes time for actions to happen and you may end up violating the internal order handling rules if the order is not yet fully cancelled by the time you try and place the new order.
    If you cancel an order, I recommend to detect the order.OrderState is OrderState.Cancelled in OnOrderUpdate(), before sending a new order.

    OnExecutionUpdate() only runs when there is an execution (order fill). This will not run when an order changes OrderState like OrderState.Cancelled.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks NinjaTrader_ChelseaB for the reply. I am using the managed approach, so I'll implement the check for cancel in OnOrderUpdate() as you suggest. Or I may look harder at the unmanaged approach to see if that can work. I gather with the managed approach there is a latency issue as I have to wait for the replies for each order method to come across the internet whereas with the unmanaged approach you handle the sequence in house and therefore won't have those latency issues. Is that correct?

      Comment


        #4
        Hi NinjaTrader_ChelseaB, seems I was confused about the difference between managed and unmanaged approach. Seems I've always used the managed approach but thought the "Advanced Ordering Methods" was referencing the unmanaged approach, which I now realize is incorrect. My apologies. I have always used the managed approach and doubt I will ever use the unmanaged approach. But irrespective, is my question about latency correct?

        Comment


          #5
          Hello dweems,

          The unmanaged approach sets IsUnmanaged to true and submits all orders with SubmitOrderUnmanaged().
          The managed approach submits orders with Entry, Exit, and Set methods, like EnterLongLimit(), ExitLongStopMarket(), SetStopLoss().

          What are you meaning by latency issue?

          Orders have to be accepted, working, then filled, and then the position has to update. This means you need to wait for the order or position to update in OnOrderUpdate() or OnPositionUpdate() before working with that order or position.

          As an example, calling ExitLong() and EnterShort() at the same time will result in the position becoming double when it reverses.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            The latency issue is that I have to send a cancel order, then wait for the reply about that cancellation before continuing with the order reversal. I don't exactly have high speed internet, so there's the time to send the cancel order, you have to process that cancel order then send the reply back across the internet. I then have to receive the reply, and then again go across the internet as I send the next entry order for the reversal. That's a fair amount of latency, meanwhile the market has continued to move. I was hoping that having one order in place to enter in one direction and placing another entry order in the opposite direction would be an OCO type of event that would be handled all on your server, thereby reducing the latency issue. But from what others there have told me, that's not an option. Wish it was......

            Comment


              #7
              Hello dweems,

              Yes, if your internet is experiencing high latency, it will take longer for order and position information to be received and update in NinjaTrader.

              OCO is available from the unmanaged approach.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

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