Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancelling and placing order in other direction

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

    Cancelling and placing order in other direction

    I am familiar with the internal order handling rules, so I have developed a channel breakout strategy which only has a EnterLongStop or EnterShortStop at any one time. I monitor whether the market is closer to the long or short breakout point, and attempt to cancel one and create the other as appropriate. I have CalculateOnBarClose=true and don't use advanced order handling. The Stop orders are generated in each OnBarUpdate and in therory expire at the end of each bar.

    However, when I change from a LongStop to a ShortStop or vice versa, NT simply cancels the active order in the current OnBarUpdate and only creates the opposite order on the next bar, this leaving a 15 minute gap (on a 15 minute chart) when there is NO order working.

    Do I have to use CancelOrder() or advanced order handling or CalculateOnBarClose=false or something else?

    Thanks
    Peter

    #2
    Hi Peter, how do you change to the other side? With an input and restarting the strategy? You would need to combine both into one set and monitor in the strategy when which order needs to be send, then CancelOrder() the opposite one. It's also advisable to work with IOrders to get confirmation the order has been cancelled - http://www.ninjatrader-support.com/H...V6/IOrder.html

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hi Peter, how do you change to the other side? With an input and restarting the strategy? You would need to combine both into one set and monitor in the strategy when which order needs to be send, then CancelOrder() the opposite one. It's also advisable to work with IOrders to get confirmation the order has been cancelled - http://www.ninjatrader-support.com/H...V6/IOrder.html
      I take your point that I probably need to explicitly CancelOrder() and check that the cancellation has been performed before placing a new order. Would this achieve any better outcome than my simple solution which presumably allows the existing order to expire at the end of the current bar, and only places a new order at the end of the NEXT bar, not THIS bar?

      If I implement CancelOrder() and check whether the order has, in fact, been cancelled, should I process these on a tick by tick basis, or is end of bar still going to be adequate?

      My code is (relevant bits only):


      protectedoverridevoid Initialize()
      {
      CalculateOnBarClose = true;
      }
      protectedoverridevoid OnBarUpdate()
      {
      /*...*/
      if (Close[0] >= (upperChannel+lowerChannel)/2)
      {
      EnterLongStop(DefaultQuantity, upperChannel,
      "LBO");
      }

      if (Close[0] < (upperChannel+lowerChannel)/2)
      {
      EnterShortStop(DefaultQuantity, lowerChannel,
      "SBO");
      }

      Thanks
      Peter

      Comment


        #4
        Peter,

        The approach you have outlined may work, but there may also be factors outside of any of our hands that may also make it not work. If your brokerage just does not return a cancelled state back to us you would end up submitting an invalid order when a new bar closes. This is why Bertrand suggested you use CancelOrder() and wait for cancel confirmation. You do not need to switch to CalculateOnBarClose = false with such an approach either. You can just call CancelOrder() on your order and then in OnOrderUpdate() wait for the cancelled order state to submit your new order.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X