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

2nd market order executing before first order finishes, entry per direction is 1

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

    2nd market order executing before first order finishes, entry per direction is 1

    I have my algo set to entry per direction to 1. And I'm using market orders.

    All within 1 second, I had a "Buy to Cover" start and before it could be Status = Filled/change to flat, another "Buy to Cover" with the same signal name happened and I then was long 1 contract instead of being Flat.

    I tried to use what was written in https://ninjatrader.com/support/help...rderupdate.htm but don't know if I have implemented it correctly.

    I wasn't sure if something like this would work:

    if(myOrder.OrderState == OrderState.Submitted && myOrder.OrderState != OrderState.Filled)

    {

    return;

    }
    Please let me know what the best practice is to avoid such a situation.

    #2
    Hello tony_28217,

    Thank you for your post.

    You mentioned that both of the buy to cover orders had the same signal name; what order type was this order? (for example, market, stop market, limit, etc)

    Additionally, I am not exactly sure what you are trying to achieve with the snippet you provided from OnOrderUpdate(). Do you have exit orders that are being submitted after that return statement? For a full example of using the OnOrderUpdate() and OnExecutionUpdate() methods to submit protective orders, please see the reference sample here:


    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hey Emily,

      All the orders I'm using are Market orders.

      Thanks for the example. I'll look at it closely.

      And yes I see the code I posted is illogical. I think I may have resolved my issue with something slightly different but even more simple.

      HTML Code:
      if((myOrder != null && myOrder.Filled == 0))​
      I just put that above my logic so that (using the myOrder assignment from OnOrderUpdate) I can't get a second order to send before the first fills.

      Comment


        #4
        Hi Emily,

        So I am having the same situation re-occur.

        Essentially In the order process (as seen in logs) of Submitted > Accepted > Working > Filled, I get a duplicate of the same order (a market order) that fires when the previous one is "working"

        I do have tick replay on but have the above code in OnMarketData just in case.

        Do you have any advice?

        Comment


          #5
          Hello tony_28217,

          Thank you for your patience.

          If you are using the Unmanaged Approach, then EntriesPerDirection will not apply to your strategy. If you are using the Managed Approach, the internal order handling rules that are meant to prevent unwanted positions are not able to apply to market orders:


          You could consider adding a boolean to your logic. Is the Buy to Cover order an exit order? Your bool could be something like exitSubmitted that defaults to false. Your condition to submit an exit order should also check that exitSubmitted == false. Once your exit order is submitted, set exitSubmitted to true. That way your exit logic won't be fired again because the condition exitSubmitted == false won't be met. Next, you could have another condition that checks once the position is flat and sets exitSubmitted back to false again.

          Please let me know if I may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment


            #6
            Huh. Interesting to see that market orders are exempt. I supposed I'll just add a "reasonable" buffer to my limit orders to make sure they execute.

            The managed approach is far better for what I've experimented on so I'll stick with that.

            Thank you for outlining a simple boolean logic. The nature of it is not difficult but the trade logic was much more important to me.

            Tthanks!

            Comment


              #7
              Hi Emily,

              I am having the same issue multiple times a week. I understand the logic behind the bool you explained above, but I am using the managed approach and I don't know where to find "exit submitted."

              Would the following work?

              Click image for larger version

Name:	image.png
Views:	91
Size:	34.0 KB
ID:	1271092

              Comment


                #8
                Hello thaboushca,

                Thanks for your notes.

                When using the Strategy Builder you could check if you are in a flat market position in your condition to place the entry order.

                The image you shared would be the correct way to check if you are in a flat market position.

                By doing this, the entry order would only be submitted when you are in a flat market position. When you are in a long or short market position, the entry order would not be submitted again since the market position is not flat.
                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by itrader46, Today, 10:22 AM
                0 responses
                12 views
                0 likes
                Last Post itrader46  
                Started by NM_eFe, Today, 10:13 AM
                0 responses
                3 views
                0 likes
                Last Post NM_eFe
                by NM_eFe
                 
                Started by hdge4u, Yesterday, 12:23 PM
                1 response
                10 views
                0 likes
                Last Post hdge4u
                by hdge4u
                 
                Started by 1001111, Today, 09:45 AM
                0 responses
                11 views
                0 likes
                Last Post 1001111
                by 1001111
                 
                Started by DTSSTS, 01-28-2024, 12:07 PM
                11 responses
                559 views
                0 likes
                Last Post bmo111
                by bmo111
                 
                Working...
                X