Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Partial exits of a position with the Strategy wizard

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

    Partial exits of a position with the Strategy wizard

    Hello,
    I have a strategy that once the order is filled i would like to exit on different profit targets.
    example:
    Strategy gets executed and i am long 9 contracts, i want to exit 3 at 10 ticks 3 at 15 ticks and leave the last 3 as runners with a trailing stop.

    can someone help me please?

    Thanks
    Last edited by sfigas; 08-03-2015, 07:12 AM.

    #2
    Hello sfigas,

    Thanks for your post and Welcome to the forums!

    Using the strategy wizard makes this a bit difficult and somewhat limited but not impossible. Basically you would need to break your entry into 3 orders of 3, each with a different signal name. You would create three separate trailing stops according to each signal name.

    For the first exit you would need to check that that the current close price is >= the average entry price + 10 ticks and then exitlong ("name of first order").

    For the 2nd 3, the exit process is the same except this time your check +15 ticks and then exitlong ("name of 2nd order").

    The 3rd of course would be by the trailing stop.

    I've attached 4 screenshots showing the above.
    In sfigas1 the conditions are a simple close > open and checking to make sure we are flat before entering. This was just for my testing purposes and you would replace the Close > open with your entry logic. Also, I only am showing a long entry and the exits, you would need to replicate and adjust the exits as needed for going short.

    The actions are to place 3 sets of orders with a quantity of 3 and give each a signal name. this was needed for the 3 separate exits you want. Also, note that I am setting the internal variable0 to a value of 1. Variable0 is used to keep track of where we are. 1 means order placed, 2 means 1st 3 contracts exited.

    In sfigas2, we again check that we are long, we check that current close price is >= than the avgPrice+10 ticks. When it is, we exit long by signal name, set variable0 to 2. I added the drawdot as a visual on the chart.

    In sfigas3, we again check that we are long, check that variable0 is now 2 and text that Close >= avg.price + 15 ticks. the action is to then exits the 2nd set of 3, reset variable0 to 0 and added a diamond as an on chart visual.

    In sfigas4, this is where all three different trailstops are set by signal name. I set them the same value, you could choose differently.
    Attached Files
    Last edited by NinjaTrader_PaulH; 08-03-2015, 07:37 AM.

    Comment


      #3
      Hello Paul,

      thank you for the reply,
      i don't want to do that necessary with the strategy wizard, i first made a mistake how i title the tread, if we use the code will it make it more efficient instead of creating different orders?
      Thank you
      George

      Comment


        #4
        Hello George,

        Thanks for your reply.

        Certainly as I showed it is possible to do what you wanted within the strategy wizard. Yes, you can execute the same in code and in fact this is what the strategy wizard does is to create the same code that you would write. You can always examine this with the "view code" button in the wizard.

        If you are looking for an alternative way to write the strategy what you could do is to create an ATM strategy to control the targets and trailing stop (as you have these well defined) and then create a strategy that contains your entry code and then calls the ATM strategy when your strategy enters an order. The value of this approach is that you can use the NinjaScript strategy to generate automated entry signals and once entered, you can delegate exit management to an ATM strategy which allows you degrees of manual control over how to close out of a trade.

        Please review the SampleATMstrategy which exists on your Ninjatrader. In addition you will want to review this section of the helpguide: http://ninjatrader.com/support/helpG...gy_methods.htm

        Comment


          #5
          Hi Paul,

          I will take a look at the ATM.

          Thank you
          George.

          Comment


            #6
            Hello Paul,

            I was trying to follow your instruction to reproduce very similar conditions but I am totaly confused.

            My idea is to have basicly two exits for each side of the trade long and short. First target will be at 30 ticks and than it will close 1 contract out of two which I am trading. Second contract will be exited at 100 ticks or reversed by opposite trade. Ideally, if the remaining contract will have trailing stop it will be great.

            Thank you for your help

            Miroslav
            Attached Files

            Comment


              #7
              Hello miroslav,

              Thanks for your post.

              In review of what you had posted it looks like set 4 would need to be changed. This is the profit exit of 1st short contract at 35 ticks, however in the statement you are adding 35 ticks instead of subtracting 35 ticks. Please change to add -35 ticks (you have to add a negative 35 ticks to effectively subtract in the wizard).

              You would not need to set profit targets for the first contracts as you are using sets 2 & 4 to exit first contract when you have 35 ticks profit. Having multiple exits on the same point could cause overfill conditions.

              Comment


                #8
                Hello Paul,

                thank you for your feedback. I have changed the condition in set 4 and deleted profit targets for first contracts.

                I run backtest again but it seems from some strange reason it is not entering and exiting second contract and after exiting first contracts it opens new trade. I am attaching print screen from backtesting.

                If I understood correctly it is checking if there is current trade and since second contract was not triggred at begining new position is opened since conditions are met.

                If I want to set trailing for second contract should I only change it in profit and exit windows?

                Thank you

                Miroslav
                Attached Files

                Comment


                  #9
                  Hello miroslav,

                  Thanks for your post.

                  When you apply the strategy are you setting the "Entries Per direction" to two? This will be found in the "Order Handling" section of the strategy panel.

                  Comment


                    #10
                    Hello Paul,

                    no I am setting quantities in the strategy wizards as you can see in previous screenshots.

                    Ok. if I set 2 in the Entries Per direction it shows entry of the second contract. But it does not closed (reversed) with oposite trade. It seems it is ignoring and not exiting second position with new trade. Instead of it it ignores possilbe next trade and is keeping second contracts in. See attached screenshots.

                    From the screenshot there should be 5 trades taken but none in current setting.

                    Miroslav
                    Attached Files

                    Comment


                      #11
                      Hello miroslav,

                      Thanks for your post.

                      On the 2nd contract you did not hit your fixed 30 tick stop loss nor your 100 tick profit target (it was closed by the exitonclose function). As you were still in a short position no other trade could be made because one of the conditions of entry in sets 1 & 3 is checking to see if you are flat. If you want condition sets 1 & 3 to fire regardless of your current position then remove the flat position check.

                      Comment


                        #12
                        Hello Paul,

                        yes it helped to eliminated issue with ignoring trades. But now after exiting first target it is reentering with one contract again. Than it is hitting stop losses and some issue with exiting second contract again.

                        The idea is to take first target of 35 ticks and have second contract as a runner until next trade. So basicly after exiting first target there will be only one contract remaining until next trade where second contract should be closed and 2 new contract should be executed etc.

                        thank you very much for your feedback.

                        Miroslav
                        Attached Files

                        Comment


                          #13
                          Hello miroslav,

                          Thanks for your post.

                          To prevent re-entry change the Market position check to check the intended direction.

                          So for set 1, which is the long entry, add the condition Position.MarketPosition != MarketPosition.Long. The "!=" means not equals. The logic here is that if your are not long already go ahead and enter long. So when your 1st long is hit you will still be long and it will not then be able to enter another order.

                          Same for set 3, Position.MarketPosition != MarketPosition.Short.

                          Comment


                            #14
                            Hello Paul,

                            fantastic!!!!! It reduced reentries.

                            It is taking T1 and than no trade until next trigger. The one thing I noticed is if there is no T1 for 35 ticks it is waiting until stop loss. Is there some way how to limit if there is no T1 it will behave as second contract it means exit on the next possible trade and not to wait until stop loss.

                            Please, have a look on the printscreen what I mean.
                            Attached Files

                            Comment


                              #15
                              Hello miroslav,

                              Thanks for your post.

                              I just noticed that in both sets 1 & 3, you have the same condition Open[0] > Close[1] and you probably need to reverse one of those to get this right.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              71 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              43 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              25 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              28 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              56 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X