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

Early Exit for multiple positions

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

    Early Exit for multiple positions

    the strategy executes many different orders on the same instrument / bar and I am looking for the best way to do a general “early exit” for all of them. any suggestions to the best approach would be great.

    #2
    I would like to add that it is Multiple exits with unique exit names, but without unique entry names.

    Comment


      #3
      Hello thehammer,

      Thank you for your post.

      What are you referring to as an "early exit" for this scenario? For example, what would be the condition(s) to trigger the exit and what is the desired behavior you are after when the condition is met?

      I look forward to your reply.
      Emily C.NinjaTrader Customer Service

      Comment


        #4
        Hello! I have actually been working on some strategies and solutions with the original poster above so I wanted to post some additional comments.

        The issue we are having (especially with live trading only) is where (on bar index 0) we have multiple entries... Such as "My Long", "My Long 1", "My Long 2", "My Parabolic Long", "My Parabolic Long Two" etc...

        At the moment this works great for entries... but there are various configurations within the strategy that allow for an early exit, such as if maybe stochastics or RSI met a certain condition... maybe if the PNL was already a certain amount it would choose to exit etc...

        So at the moment, we loop through all potential names and do something like :

        ExitLong(ParabolicDCAOneQuantity, "Early Exit Minimum DCA PNL", "Epic Long Parabolic One");

        Then after all of the exit's we kind of do a "catch all" exit of ExitLong(), which should cover any of the other exits if there are any. The problem here is that on live trading with live account, it exits the positions, but then actually puts the trade in reverse, by closing more ExitLong() than quantity, perhaps because it didnt' exit fast enough with the orders above... So you end up short. Within NinjaTrader if you are flat and you ExitLong() its basically the same thing as EnterShort().

        So, I suppose I could keep an arraylist of orders (I am sure there are some code samples of users who did that?)... The problem is, how do we get notified when the specific profit target or stop loss gets hit? The name shows just "profit" or just "stop loss"? We would need to be able to have some way of pulling that in to remove it from the open orders arraylist?

        What would be ideal (but doesn't seem possible with the overloaded functions for ExitLong) would be if you could provide simply a unique exit name, that would handle/cover all orders.

        So for example...

        ExitLong() -- This already handles all orders

        Would be great if we could use something like :

        ExitLong(position.Quantity, "Early Exit Regardless of Entry Name");

        Right now when you execute the ExitLong function, if you provide an exit name it requires you to also provide the initial entry name.

        Thanks!


        -Chad
        chadnash
        NinjaTrader Ecosystem Vendor - Nash Technologies

        Comment


          #5
          Hello Chad,

          Thank you for the additional information.

          Although the method signatures for ExitLong() that allow a signalName also require fromEntrySignal, you may use an empty string to attach the exit order to all entries as noted in the help guide:
          https://ninjatrader.com/support/help...8/exitlong.htm
          "Note: Using an empty string will attach the exit order to all entries."

          For example, you offered the following:
          ExitLong(position.Quantity, "Early Exit Regardless of Entry Name");

          This could be done with an empty string, "", for the fromEntrySignal parameter. For example:
          ExitLong(position.Quantity, "Early Exit", "");

          Calling this one ExitLong() to exit the entire position could be more reliable than calling each individual exit paired with each entry and then an additional "catch all" ExitLong() in case there are any remaining contracts in the position. This is because of position updates in the strategy; if the exits are called but there hasn't been a position update yet, the strategy will still think it is in a long position even if exits have been called to flatten the position. This is likely the cause of the behavior where you have seen the strategy end up in a reversed position.

          If you are ever experiencing unexpected behavior in a strategy, adding Print() statements with all of the variables used can be helpful. You may also take advantage of TraceOrders as a tool for debugging the behavior of orders. For more information:Please let me know if I may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by lorem, Today, 09:18 AM
          1 response
          4 views
          0 likes
          Last Post lorem
          by lorem
           
          Started by bmartz, Today, 09:30 AM
          0 responses
          1 view
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by GussJ, 03-04-2020, 03:11 PM
          14 responses
          3,244 views
          0 likes
          Last Post GussJ
          by GussJ
           
          Started by ArkansasClint, Today, 09:28 AM
          0 responses
          0 views
          0 likes
          Last Post ArkansasClint  
          Started by hazylizard, Today, 08:38 AM
          4 responses
          12 views
          0 likes
          Last Post hazylizard  
          Working...
          X