Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 MSerag, 05-06-2024, 11:52 PM
            4 responses
            25 views
            0 likes
            Last Post MSerag
            by MSerag
             
            Started by TraderCro, Today, 12:13 AM
            0 responses
            2 views
            0 likes
            Last Post TraderCro  
            Started by Skifree, Yesterday, 11:47 PM
            0 responses
            7 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Started by Skifree, Yesterday, 11:41 PM
            0 responses
            6 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Started by Skifree, Yesterday, 11:38 PM
            0 responses
            4 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Working...
            X