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

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:
    Paul H.NinjaTrader Customer Service

    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.
        Paul H.NinjaTrader Customer Service

        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 Jon17, Today, 04:33 PM
          0 responses
          1 view
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          4 views
          0 likes
          Last Post Javierw.ok  
          Started by timmbbo, Today, 08:59 AM
          2 responses
          10 views
          0 likes
          Last Post bltdavid  
          Started by alifarahani, Today, 09:40 AM
          6 responses
          40 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          19 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Working...
          X