Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Managing Orders

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

    Managing Orders

    Hi all,

    After recoding strategies with the OnOrderUpdate and OnExecution I was woudering what I can do to solve the problem that has to do with the NT Handling Order rules.

    I have a strategies that at times will send two orders one long and one short. For example EnterShortLimit 996.00, EnterLongLimit 990.00.
    The problem is that if my short order is active the long order will be ignored because of the handling Order rules. That makes no sense to me !

    After refactoring my strategies to manage my orders through OnOrderUpdate and OnExecution methods , is there a way I could cancel the farthest order from the market so that only the closer one would be send. Obviously I would have to reissue these orders on a bar basis.

    Could someone help me on this issue with code example if possible


    Thank you very much

    Bernard

    #2
    Bernard,

    The reason you can't submit both at the same time is because of the way those orders work. They attach "Close position" orders when they see a position in the opposite direction. When you run both at the same time it doesn't know how to attach these "Close position"s.

    To go about this you can just check your long and short prices against Close[0]. If the price is closer to the long, submit the long order. If it moves closer to the short, cancel the long via CancelOrder() and then submit the short after you receive cancel confirmation on the long from OnOrderUpdate(). Vice versa case would be true too.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh you are giving me hopes !

      I need a code example though because I am a bit lost.

      Here how it works :

      At the beginning of OnBarUpdate methods I have my buys and sells :

      if(BuyOrders){
      if (entryOrder == null)
      entryOrder = EnterLongLimt(....);
      }

      if(SellOrders){
      if(entrySOrder == null)
      entrySOrder = EnterShortLimit(...);
      }

      Now in my OnOrderUpdate I have :

      if(entryOrder != null && entryOrder.Token == order.Token)
      {
      if(order.OrderState == Order.State.Cancelled && order.Filled == 0)
      entryOrder = null;
      }

      Same thing for the short ...


      Now where do I cancelOrder() and reissue Orders after cancel confirmation by OnOrderUpdate...


      Bernard

      Comment


        #4
        Bernard,

        In OnBarUpdate() you need to run the necessary checks to determine if you should be sending a buy order or a sell order. Then from there you can submit the necessary one.

        If one of your IOrders is not null and then you know you have an active order there. If you need to switch it up you would then call CancelOrder() in OnBarUpdate(). In OnOrderUpdate() you wait for Cancel confirmation, reset the original IOrder to null, place the new order in the opposite direction.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh

          Actually I have gone this way :

          In OnBarUpdate :

          if(BuyOrders) {
          if(entryOrder == null)
          entryOrder = EnterLongLimit(...);

          if(Close[0] - BuyOrders > SellOrders - Close[0])
          CancelOrder(entryOrder);
          }


          if(SellOrders){
          if (entrySOrder == null)
          entrySOrder = EnterShortLimit(...);

          if(Close[0] -BuyOrder < SellOrders - Close[0])
          CancelOrder(entrySOrder);
          }



          Where I am not sure in OnOrderUpdate :

          if(entryOrder != null && entryOrder.Token == order.Token)
          {
          if(order.OrderState == OrderStae.Cancelled && order.Filled == 0)
          entryOrder = null;
          }


          With that code it still doesn't work. What's wrong ?


          Bernard

          Comment


            #6
            In OnOrderUpdate() you never submit the order in the opposite direction. You need to place the EnterShortLimit in there somewhere.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sjsj2732, Yesterday, 04:31 AM
            0 responses
            38 views
            0 likes
            Last Post sjsj2732  
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            287 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            289 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            134 views
            1 like
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            95 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Working...
            X