Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to avoid "Double Trades" when swapping positions with managed approach?

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

    How to avoid "Double Trades" when swapping positions with managed approach?

    How to avoid "Double Trades" when swapping positions with managed approach? ( I work only with the startegy builder, unfortunately I am not a programmer...)


    I am trying now since days to solve the issue with the strategy builder so hopefully someone can help me here...

    I am facing an issue with my automated futures strategy when testing live (does not occur in the historic backtest) when swapping positions from long to short or vice versa.

    So in my strategy I have 4 Sets:

    1. Conditions A --> go long
    2. Condidions B --> exit long
    3. Contidions C --> go short
    4. Conditions D --> exit short

    The problem only occurs when condition (B and C) or (D and A) both apply on the same bar. Then instead of exiting one position and going in the other direction he creates a "close position" trade first and then goes in the other direction, what results in having 2 positions instead of just one.

    In my research i have read a lot about that this has to do with the managed approach and NT does not yet have the Information that the exit occured yet.

    Is there a simple way realizable with the strategy builder to let NT know that this exit happened (in Condition B or D, so he does not have to "close Positions from NT side" additionally when swapping sides) in the same bar? For example with Variables or so? Or any other solution to avoid that?

    I new here, so excuse me if the question if its silly ;-) Thnx and best regards
    Last edited by Coral; 12-17-2020, 03:22 AM.

    #2
    Hello Coral,

    Thanks for your post and welcome to the NinjaTrader forums!

    The issue that you are having is that the Entry methods will automatically detect and close a position in the opposite direction. Here is what happens, for example, if you are in a long position and the strategy issues EnterShort(), the EnterShort() method will first issue a sell order (called "Close Position") to close the long position, it will then issue a sell short order to leave the strategy in the short direction as intended.

    When you have an exit order occurring at the same time as an entry order, depending on the actual event timing you can indeed end up with additional orders. With reference to the preceding example, we now add in ExitLong() which itself will issue a sell order which would be intended to close the position however the entry method already closed the long position so indeed now the example would be 2 contracts short.

    The solution is simple, you do not need the exit conditions, assuming your strategy is intended to be always in (always long or short).

    If you prefer that the exit conditions work and you do not want to automatically enter in the other direction, a solution then would be to add a check of the market position being flat as an entry condition (in addition to what you have now). So to enter a new position, the strategy must be flat. Here is a link to the Strategy builder help guide on using market position: https://ninjatrader.com/support/help...ionComparisons

    Finally, here is a link to the managed approach that will also help clarify what is involved in the managed approach: https://ninjatrader.com/support/help...d_approach.htm



    Comment


      #3
      Thank You very much Paul for your answer!

      The strategy should not always be in (long or short) and therefor I cannot just delete the exit condition sets. (Sometimes she is long, short or flat).

      Actually the Strategy should only sometimes flatten a position but in other scenarios (when additional criteria are matching) the strategy should swap positions and exactly there comes the problem that I endup with 2 contracts. (Because he takes the "flattening set" as well as the posittion swap set and the adds the "close position").

      I tried already adding the "market position check strategy is flat" option before swapping the positions but that would lead into the swap being done one bar later as the flattening and I'd lose a lot of profitability.

      There lies the problem... I assume because this 2 criteria fullfill in the same bar (exit as well as position swap).

      --> So I'd need only for these cases (where he swaps positions) to cancel or ignore the exit /entry (flattening) condition set so I'll not end up in having 2 contracts and this happening in the same bar.

      Any way or workaround this might be possible?


      Comment


        #4
        Hello Coral,

        Thanks for your reply.

        Now that you understand the functionality of the Entry methods and the issue of using Entry and exit at the same time, you will need to work on your logic for when to use the Exits versus when to allow it to reverse. I cannot help you with the design of your logic. You will need to develop the conditions that allow the strategy to make those decisions and likely can control through the use of Bool (true or False) type variables.

        Comment


          #5
          Thank you for the hint in regards of the bool variables Paul.

          Will try to figure it out with these ;-)

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X