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

Clarification re: Multiple Order Entries within the Same Bar

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

    Clarification re: Multiple Order Entries within the Same Bar

    Hello,

    I am trying to get clarification as to what is supposed to happen when for example...

    > an EntryLong() is issued
    > then an EntryShort() is issued within the Same Bar, and before the 1st order is complete.

    The result is that the 1st Order is filled, however I would have thought that the 2nd Order would have cancelled the 1st and the 2nd would have been the one filled. Can you please help me understand what is supposed to happen?

    I have attached an excerpt from a Log that my strategy creates which details what is happening at every OnOrderUpdate().

    Note: The above example is on Historical data.
    Note: Entries Per Direction = 1
    Note: Entry Handling = All Entries

    Thank you.
    Attached Files

    #2
    Hello Montana,

    Thank you for your post.

    This is going to fall under the Internal Order Handling Rules for the Managed Approach.
    Since, the first order is still "Working" the second order will get cancelled for the opposite side.
    I confirmed this with the Trace Orders
    Code:
    5/15/2014 4:01:00 PM Entered internal PlaceOrder() method at 5/15/2014 4:01:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='long1' FromEntrySignal=''
    5/15/2014 4:01:00 PM Entered internal PlaceOrder() method at 5/15/2014 4:01:00 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='short1' FromEntrySignal=''
    5/15/2014 4:01:00 PM Cancelled pending entry order on opposite side of the market: BarsInProgress=0: Order='NT-00001/Backtest' Name='short1' State=Working Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='TestStrategy' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='bdbf5e8f0cd942dfb8766ad822b6a153' Gtd='12/1/2099 12:00:00 AM'
    Your strategy followed the correct procedure for the handling of these orders.

    You can view these rules at the link below -
    http://www.ninjatrader.com/support/h...d_approach.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Cal, thanks for the response.

      Just so that I am clear, could you expand on the meaning of "Working"? Does this mean the exchange is about to fill my order? I assume that once it reaches a "Working" condition that it is beyond the point of Canceling.

      If the order I sent had been a limit order instead, and the limit had not yet been reached, would the status instead come back as "Accepted", then turn into a "Working" order once the limit at the exchange is reached?

      Thanks.

      Comment


        #4
        Montana,

        The "Working" state means that the order is at the Exchange and working. It does not necessarily mean that its about to get filled, however since these are markets orders we can expect it to get almost instantly filled. You can cancel an order in a Working state at any time.

        Correct, the Accepted state lets you know the order has been received and is waiting to hit the limit price. Once that price is hit you would see the working state appear before getting filled.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Cal, in your reply, you write "You can cancel an order in a Working state at any time". That seems to contradict what happens in my example. Does that not happen in my example because it is working with Historical data? Or with Historical data, would the order have been cancelled issuing a CancelOrder prior to the Order Fill on the first order?

          Just trying to make this crystal clear as to not run into an order issue.

          Comment


            #6
            Montana,

            Does your code submit a cancel order before the EnterShort() is submitted?

            Additionally, remember these are market orders and are almost guaranteed to get filled immediately when submitted and the "Under the hood" settings recognize this.

            I can tell from the text file you gave, both orders were submitted at the same time. The first one is going to remain while the second one will either get cancelled or ignored due to the Internal Order Handling as these are opposite side orders and conflict with the rules.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Cal,

              No, in my code example, I am not issuing a Cancel Order before the EnterShort(). Would that have made a difference?

              Understood that if this is a market order, if would likely be filled immediately.

              Correct that both orders were issued at the same time.

              I've read through the "Under The Hood" settings and I'm not sure how I can obtain the results I want. This is simply what I am trying to do...

              > Place an EntryLong() or EnterLongLimit() Order for 1 contract which also has a target and stop loss attached to it via the SetStopLoss() and SetProfitTarget() methods.

              Then at some later time I may want to go Short by either...

              > A. If I am now holding a long position, Reverse my position
              > B. If the order has not been filled, I would like to be sure all outstanding Long orders are cancelled, and then enter into a short position using EnterLong() or EnterLongLimt() with target and stop losses attached to it.

              What am I missing? Do I just need to explicitly Cancel any open orders prior to issuing the 2nd order? I thought the Managed Approach would address this for me but as the Under the hood settings say, this may not be the case. What is the minimal amount of commands I need to include to address the above scenario and not have "unnecessary" communication with the exchange?

              Comment


                #8
                Hello Montana,

                Let me try to word this a different way. You would not be able to place a EnterLong() and EnterShort() order on the same OnBarUpdate() call, the "under-the-hood" handling will prevent this. When you are working on Historical Data you would see NinjaTrader cancel out this order automatically with no need to cancel out the order, this is the benefit of the "under-the-hood" handling.

                If you are in a long position and "EnterShort()" is called then NinjaTrader will automatically submit an order to close your position, cancel any working/accepted orders and then enter you in a Short position for you. This is another benefit to the "under-the-hood" handling.

                The only thing that you will want to avoid is calling "EnterLong" and "EnterShort" in the same OnBarUpdate() call. You will want to do either one but never both.

                Let me know if that helps or if you have any further questions.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Got it. That makes more sense. Thank you.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, 04-17-2024, 06:40 PM
                  6 responses
                  49 views
                  0 likes
                  Last Post algospoke  
                  Started by arvidvanstaey, Today, 02:19 PM
                  4 responses
                  11 views
                  0 likes
                  Last Post arvidvanstaey  
                  Started by samish18, 04-17-2024, 08:57 AM
                  16 responses
                  61 views
                  0 likes
                  Last Post samish18  
                  Started by jordanq2, Today, 03:10 PM
                  2 responses
                  9 views
                  0 likes
                  Last Post jordanq2  
                  Started by traderqz, Today, 12:06 AM
                  10 responses
                  21 views
                  0 likes
                  Last Post traderqz  
                  Working...
                  X