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

How to not enter another trade within X bars of last exit

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

    How to not enter another trade within X bars of last exit

    Hope the above is pretty self explanatory, all using the Strategy Builder

    #2
    Hello demo166130,

    You can do this by using BarsSinceExitExecution: https://ninjatrader.com/support/help...=barssinceexit

    An important note with this method is that if no exit exists a negative 1 is reported, this can be used logically to know if an exit had not occurred or if a number of bars since exit has occurred.

    In the builder, this is located in the Misc -> Bars Since Exit.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Im having issues using this command using the strategy Builder. When I say 'Bars Since Exit (Greater than) numeric value 3' no trades take place from the backtested data telling me something isn't right. I'm clearly doing something wrong. Any ideas?

      Comment


        #4
        Hello demo166130,

        The Bars since exit would need an exit to occur, are you seeing the exit happen on the chart of the backtest?

        Have you also specified a Signal name in Bars Since Exit? The signal name of an exit order would be used here.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I've attached an image of the way I've set it up. Just to be clear I want to ensure I dont take another trade immediately after one has just been exited, as detemined by a number of bars since the last exit. Could you illustrate how this should look from your end?
          Attached Files

          Comment


            #6
            Hello demo166130,

            In the image I see you have not used a signal name, just to be clear are you using an exit order with no signal name, or are you using one of the targets to exit the position? You would need to use a signal name here if your exit has a signal name such as Stop loss.

            I additionally see you have used true as the comparison, this does not return true or false but returns a number of bars so that would need to change to misc-> numeric value. That will be either -1 or greater.

            Also if you have used this for the entry order, you may also need to use the negative value logically. For example, if the value is -1 or greater than 5. That would indicate either a exit had not happened yet, or it has been 5 bars since an exit. Is this for an entry specifically? If so, you likely will need to use the if Any of the conditions are true instead of if All are true for this set in addition to making a check for -1, and another check for the target number of bars since exit.

            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Im using a fixed Exit as determined by a number of ticks which is determined by an input in the profits and targets section.

              I'm not fully understanding the purpose of a signal name..

              Yes this is supposed to be an entry cue, to ensure we don't take a trade if we have only just exited one within the last 5 bars.

              Would you be able to illustrate for me what you mean? For some reasin this isn't sinking is as hoped for.

              Comment


                #8
                Will this also mean creating a group for the function?

                Comment


                  #9
                  Hello demo166130,

                  Thank you for clarifying the goal.

                  For an entry, you would need to use the negative one value logically like I have noted so that your logic can start if you have no other entry conditions. Here is an image of a simple condition that allows for a first entry or entries after exits. https://www.screencast.com/t/H9O4qftjfdw

                  The purpose of signal names are to link orders and logic together, you need to use the exit signal name which you want to know how many bars it has been since that exit. For the orders from the targets page, you will need to view the performance report and the Trades tab so you can view the orders Name which can then be used as the SignalName.

                  Please let me know if I may be of additional assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Im still clearly not doing something correctly. Just to be perfectly clear, I don't know how to do this, so if you assume I'm doing simple things without being told they need to be done, I won't be doing them, and we will almost certainly go wrong. And just to be clear on the intention, the idea is to ensure we do not take trades within at least 5 bars of the last one we got stopped out of (I think you understand this). I've attached another screen shot in case it helps.
                    Attached Files

                    Comment


                      #11
                      Looking back at the conversation I may not have made clear the fact that I would like to ensure we do not take trades until at least 5 bars after the last time we have a losing trade i.e get stopped out.

                      Comment


                        #12
                        Hello demo166130,

                        Thank you for the reply.

                        Im still clearly not doing something correctly. Just to be perfectly clear, I don't know how to do this, so if you assume I'm doing simple things without being told they need to be done, I won't be doing them, and we will almost certainly go wrong.
                        I am not certain what specifically you are referring to here, all I can suggest on this note would be to practice in the builder and review our help materials. Programming comes with practice even if it is a more simple programming such as the GUI of the builder.

                        Looking back at the conversation I may not have made clear the fact that I would like to ensure we do not take trades until at least 5 bars after the last time we have a losing trade i.e get stopped out.
                        Yes, in this case, your concern was not totally clear and this detail was omitted. In any case, you would need to be able to use Bars Since Exit before you could expand on the condition further. Locating specifically a losing trade would be something that can be accomplished in manual programming but there would not be a specific option for this in the builder.

                        Looking at your image, it looks like you have other condition in the set, are you sure these are coming true?

                        I also see you are possibly using an incorrect signal name. Have you viewed the performance report for the exit name as I had mentioned? You would need to correctly spell the name of the exit in addition to correct capitalization. "Stop loss" would be correct for the stops and targets page, otherwise if you have an exit named specifically "StopLoss" you would use that instead.

                        Have you at this point tried a more simple test like the image I had provided in the last post? That would be a good starting point to make sure the BarsSinceExit is working as expected, you could then append other conditions as needed to continue testing.


                        Please let me know if I may be of additional assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          OK, I think ensuring we don't take trades after another has just been taken, even if that's not a trade we got stopped out of, would still go some way to achievng the desired outcome. Can we imagine the slate is wiped entirely clean because there was some confusion that led to mix ups, mainly from my end.

                          I need to use BarsSinceExit in the Strategy builder (see attached screenshot). Hopefully this first part is correct. Maybe more needs to be done. Please let me know.
                          Attached Files

                          Comment


                            #14
                            Hello demo166130,

                            Is this the only entry in your strategy or do you have another entry in one of the other sets? If this is the only entry this will not work.

                            I would suggest trying the condition I provided an image of in post #9. You need to use the negative 1 logically if you only have one entry in your script. If you otherwise have an entry which will trigger an exit, this would work because there will be a number of bars since that exit and not -1 bars.

                            Please let me know if I may be of additional assistance.

                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              I have a short entry in set 2.

                              I have a condition not to enter a trade until flat so the other entry won't trigger a trade in the opposite direction while closing out the opening trade.

                              I checked the log and as you suspected 'Stop loss' is the correct signal needed.

                              The other conditions in the sets are correct, they are being read as true because they alone cause trades to take place in the Analyzer.

                              Here's an update (see screenshot). I just ran the analyzer with these 2 extra lines in set 1 and 2, and it causes no trades to be executed.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X