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

Strategy "exited a short position" twice, therefore entering a long position...?

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

    Strategy "exited a short position" twice, therefore entering a long position...?

    My Strategy "exited a short position" twice, and therefore enetered a long position on the 2nd "exit", since the order size is only 1. How do I prevent my strategy from "exiting twice" and thus falsely entering trades..? Is this a known glitch that occurs if you don't write your entries and exits some specific way, or is my instance just being buggy maybe?

    Thanks

    Click image for larger version

Name:	image.png
Views:	24
Size:	21.6 KB
ID:	1300498

    #2
    Hello agclub,

    Thank you for your post.

    Are you perhaps calling an exit order and an entry order on the same pass of OnBarUpdate? This can lead to the strategy position entering the opposite position with double the quantity or will result in an Overfill.

    When calling an entry method in the opposite direction of your position this will cause your position to be reversed. NinjaTrader will automatically submit an order to close your existing position and then enter an order to enter you into the opposite position.

    If you exit and then call an entry method in the same run of OnBarUpdate, the OnPositionUpdate() will not have yet run and NinjaTrader will not have known that your position is closed. This will cause both actions to complete and end up sending 3 orders. The first order is the exit position from your exit method, the second order is to close the position from NinjaTrader automatically reversing your position, the third order is to enter you into the opposite position.

    The result is that either the script will double the quantity when it reverses or it will cause an overfill and stop the script.

    This is discussed further in this post: https://forum.ninjatrader.com/forum/...16#post1036616

    Please let us know if this doesn't guide you in the right direction.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Hello agclub,

      Thank you for your post.

      Are you perhaps calling an exit order and an entry order on the same pass of OnBarUpdate? This can lead to the strategy position entering the opposite position with double the quantity or will result in an Overfill.

      When calling an entry method in the opposite direction of your position this will cause your position to be reversed. NinjaTrader will automatically submit an order to close your existing position and then enter an order to enter you into the opposite position.

      If you exit and then call an entry method in the same run of OnBarUpdate, the OnPositionUpdate() will not have yet run and NinjaTrader will not have known that your position is closed. This will cause both actions to complete and end up sending 3 orders. The first order is the exit position from your exit method, the second order is to close the position from NinjaTrader automatically reversing your position, the third order is to enter you into the opposite position.

      The result is that either the script will double the quantity when it reverses or it will cause an overfill and stop the script.

      This is discussed further in this post: https://forum.ninjatrader.com/forum/...16#post1036616

      Please let us know if this doesn't guide you in the right direction.
      Hi Gaby. Thanks for the reply.

      ...and I see... Hmmm, so what is the typical solution to this? I need to have multiple runs of OnBarUpdate ?? Like, 1 section for entries and a separate 1 for exits? Or I need to look into using OnOrderUpdate?

      Thanks

      -mike
      Last edited by agclub; 04-22-2024, 09:40 PM.

      Comment


        #4
        Originally posted by agclub View Post

        Hi Gaby. Thanks for the reply.

        ...and I see... Hmmm, so what is the typical solution to this? I need to have multiple runs of OnBarUpdate ?? Like, 1 section for entries and a separate 1 for exits? Or I need to look into using OnOrderUpdate?

        Thanks

        -mike
        you should have a bool to check if you're in 1 position long or short, then another check to see if you're flat and if there are any pending orders. This eliminated my overfill issues.

        Comment


          #5
          Hello agclub,

          If you want to simply reverse the position, call an entry order in the opposite direction of the position without calling an exit method first. For example if the position is long, then call EnterShort(). You don't need to call ExitLong() to reverse the position.

          Please let us know if you have any further questions.
          Gaby V.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by pechtri, 06-22-2023, 02:31 AM
          11 responses
          134 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by ageeholdings, 05-01-2024, 05:22 AM
          4 responses
          27 views
          0 likes
          Last Post ageeholdings  
          Started by hdge4u, 04-29-2024, 12:23 PM
          4 responses
          22 views
          0 likes
          Last Post NinjaTrader_RyanS  
          Started by z679Gju, Today, 02:37 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by mintos, 04-02-2024, 08:22 PM
          11 responses
          48 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X