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

Multiple trades from one entry criteria, NT exits all at same time when exit criteria

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

    Multiple trades from one entry criteria, NT exits all at same time when exit criteria

    My strategy is buying when ADX> 25 I want it to close a position 10 days after entry. What the strategy is actually doing is buying at the end of each day where ADX > 25 and then exiting any and all trades which are entered in to between the first trade and day 10.

    E.g. If ADX>25 for a 10 day period, my strategy will go long at the end of each of those days and therefore there will be 10 long trades. Rather than exiting each one 10 days after it was executed, it exits all 10 trades on day 10.

    How do I change settings/code in order to have each long position exit 10 days after its entry? Thanks for any help!

    #2
    Hello Kunal1234,

    Thanks for your post and welcome to the forums.

    You can use unique signal names for the entries and then the exits can be set to only exit the appropriate entry by using the same signal name in the exit.

    Reference: https://ninjatrader.com/support/help...d_approach.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thankyou Paul.

      The issue I'm finding is that criteria set 1 is generating all my entries and so all entries are marked with the same signal name . If I set an exit tied to an entry signal, all entries generated by criteria set 1 are closed simultaneously.

      Do I need to use IOrders or is there a way to use the Managed Approach to make this happen? IOrders throws up another issue for me. If ADX>25 every day for the month of December 2017, I want to buy at market close each day ADX>25 which means every day of December.

      I want to close each trade 10 days after entry. On the 11th day, IOrder 1 will be closed out. Also on day 11, because ADX>25, I want go long on a new trade. Because IOrder 1 has already been used, I can't use that name again can I? Which means I'd have to define a new IOrder which I'd call IOrder11. The problem comes because it's easy to define Order11 in this post, but say during a 5 year backtest, there will be 200 trades, I will need 200 IOrders defined. Then during a backtest, if I change my entry criteria to ADX>20 then I'd need even more IOrders. So my questions is, how do I get NinjaTrader to generate the exact number of IOrders I need during the backtest period and how do I reference a specific IOrder when I want to exit the long position?

      Comment


        #4
        Hello Kunal1234,

        Thanks for your reply.

        Yes, you can use the managed approach. No, you do not need to use IOrders.

        If you have a limit to the number of active orders at any one time then you can create a counter to create unique signal names even if using the same entry criteria. For example (pseudo code)

        if (your entry criteria met)
        {
        counter++; // increment the counter
        enter the order with a signal name of "Myentry"+counter
        }
        so your order would have the signal name of Myentry1, Myentry2, MyEntry3, etc.

        The counter is nothing more than an integer variable that gets incremented just before placing a new order.

        For the exits, assuming you are using daily bars, you might use the BarsSinceEntryExecution() along with the signal names where you test for the signal name to see that 10 bars have passed since that signal names entry.

        reference: https://ninjatrader.com/support/help...yexecution.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          If you know the maximum number of trades you can be in any time, you won't need to make an individual order variable for every trade. You just need to make as many variables as you can have open at any moment, and make sure to reset them after they are closed.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by benmarkal, Yesterday, 12:52 PM
          3 responses
          23 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by helpwanted, Today, 03:06 AM
          1 response
          20 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          12 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          244 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Working...
          X