Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Empty Bracket Orders w/o Open Position on Automated Strategy

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

    Empty Bracket Orders w/o Open Position on Automated Strategy

    Hello -

    I'm running an automated strategy that is occasionally creating a situation where there are a take-profit and stop-loss order bracket pair submitted to the market, but there's no open position to go along with it -

    The strategy has an entry trigger for longs which buys one contract with a fixed take-profit and stop-loss as an OCO pair; the strategy also has an entry trigger for shorts, which sometimes triggers while a long trade is still open, before hitting either TP or SL - this usually seems to close the open long and initiates a new short with its own TP and SL bracket order - but is it possible there's something happening where the new short position is not being opened, but only closing the long that's currently open? Because in this case, when a new short trigger comes, then the strategy goes short for two contracts, which is not what's intended.

    Is there a way to ensure that when a new short is triggered, that any open longs are closed and a new short is opened? (same vice versa when going from short to long) - this is my first time running an automated strategy, so I wonder if there's something basic I'm missing -

    Thanks very much -

    P.S. This is the logic in the strategy builder for trade management -


    Click image for larger version

Name:	Screen Shot 2022-06-08 at 6.46.58 PM.png
Views:	205
Size:	18.0 KB
ID:	1204403Click image for larger version

Name:	Screen Shot 2022-06-08 at 6.47.15 PM.png
Views:	163
Size:	17.7 KB
ID:	1204404

    #2
    Hi Daveman0, thanks for writing in. Depending on the connection/account you are using, the order/execution/position updates that the strategy relies on to reverse and submit new stops can be out of sync. The Interactive Brokers and Rithmic connections have this limitation, so the position must be exited with the ExitLong() or ExitShort() methods. I attached some screenshots on how to check for the current market position. The entry and exit conditions () can be anything, this is just for the demonstration. The screen shots demonstrate how to check the current strategy position.

    Kind regards,
    -ChrisL

    Attached Files

    Comment


      #3
      Great - this is super helpful, thank you NinjaTrader_ChrisL

      In this example, does the "exit long" command close all remaining contracts in the current position regardless of how many contracts remain open (ie if the position was originally 5 contracts, but 2 have hit TPs for example, does "exit long" know to close the 3 remaining contracts)?

      Comment


        #4
        Hi Daveman0, The ExitLong()/ExitShort commands take a Quantity parameter where you can specify a quantity. You will need to use Position.Quantity in that field to close out the remaining open quantity.

        Kind regards,
        -ChrisL

        Comment


          #5
          Understood - is there a "flatten all" command in that case? Or a way to feed the number of contracts open into the ExitLong quantity parameter?

          Thanks for your help -

          Comment


            #6
            Hi Daveman0, There is no flatten all command but you would use Position.Quantity to exit the remaining position in ExitLong e.g.

            ExitLong(Position.Quantity);

            Comment


              #7
              Yes, great - just found this myself - thanks Chris!

              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