Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Double order created by stop right before cancel

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

    Double order created by stop right before cancel

    I ran an automated strategy that just so happened to have conditions where the strategy tried to execute a reversal (sell to exit; then sell to enter a new short) just as my long was getting stopped. So I get this sequence of events:

    -Enter long
    -Submit market orders for two shorts, one to close the long, and one to enter the next trade
    -Before step two is fully processed, Long's stop is filled (I'm guessing this is what happened. I guess I don't know for sure).
    -The Close Position's order is filled, but now it's entering a new trade because there's no longer a position to close
    -The short that was supposed to open this position now opens a second position. This one had no stop!

    Is there a way to prevent this? Or recognize it and back out of the second position? I'm worried that if the strategy submits the order before the first position is closed, it might not realize it's entering twice. And I can't recreate the problem to test in Playback assuming it's an internet lag issue.

    Thanks
    Last edited by krpkevin; 11-30-2017, 06:17 PM.

    #2
    Hello krpkevin,

    Thanks for your post and welcome to the NinjaTrader forums!

    You can prevent by testing to see if you are already in a position before placing an order.

    For example, as part of your entry conditions you could use:

    if (Position.MarketPosition == MarketPosition.Flat && (your entry conditions...))

    Reference:

    Comment


      #3
      Thanks, but I don't think that would work. The issue isn't with placing the order; it's with completing the order.

      Let's ignore the entry and just focus on closing the Long. How do I close the Long position when it's about to get stopped?

      The Long is open. The strategy submits a close position order, but before it gets across the internet, or whatever it's doing, the Long is stopped. Then, the close order "arrives", but there's nothing left to close, so it opens a short (since a Long close is really just a Short).

      Now I'm short when I should be flat.

      How do I handle this?

      Comment


        #4
        Hello krpkevin,

        Thanks for your reply.

        The prevention means would be your code evaluating current price to your stop price and close conditions price and allow one or the other to operate but not both. In other words, maintain a larger price difference between where the stop exists and where the close condition is.

        Comment


          #5
          Yep I'm with you. That was my thought as I kept thinking about this more. Thanks for the confirmation!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          53 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X