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

bars between trades requirment

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

    bars between trades requirment

    is there a way to require number of bars between each exit and entry long or short, same as at startup but between trades?
    so as to avoid the buy,sell sell buy , buy sell churn

    #2
    looks like this is it

    // Only enter if at least 10 bars has passed since our last entry
    if ((BarsSinceEntryExecution() > 10 || BarsSince EntryExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
    EnterLong();

    Comment


      #3
      Hello obwon1,

      Thanks for your post.

      You could consider using BarsSinceEntryExecution or BarsSinceExitExecution to have the strategy check if at least x number of bars has passed since your last entry or exit.

      BarsSinceEntryExecution returns the number of bars that have elapsed since the last entry. When a signal name is provided, the number of bars that have elapsed since that last specific entry will be returned.

      BarsSinceExitExecution returns the number of bars that have elapsed since the last exit. When a signal name is provided, the number of bars that have elapsed since that last specific exit will be returned.

      See the help guide documentation below for more information and example code.
      BarsSinceEntryExecution: https://ninjatrader.com/support/help...yexecution.htm
      BarsSinceExitExecution: https://ninjatrader.com/support/help...texecution.htm

      Let us know if we may assist further.
      Brandon H.NinjaTrader Customer Service

      Comment


        #4
        && (BarsSinceExitExecution(0, "", 0) != 0)

        I use this, if that helps anyone

        But I have a different related question - I would like to do the same with my entry BUT USE A DIFFERENT DATASERIES BAR THAN MY PRIMARY STRATEGY BAR

        && (BarsSinceEntryExecution(0, "", 0) != 0)

        so What in the above needs to NOT be 0

        thanks

        Comment


          #5
          Hello DTSSTS,

          Thanks for your note.

          You would need to change the value of the barsInProgress argument when calling the BarsSinceEntryExecution() method.

          BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo)

          Setting the barsInProgress argument to 0 means that the primary data series would be used. A barsInProgress value of 1 would reference the first additional series added to the script. A barsInProgress value of 2 would reference the second additional series in the script, and so on.

          See the help guide documentation below for more information.

          BarsSinceEntryExecution: https://ninjatrader.com/support/help...barssinceentry
          BarsinProgress: https://ninjatrader.com/support/help...inprogress.htm

          Let us know if we may assist further.
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            So

            && (BarsSinceEntryExecution(1, "", 0) != 0)

            or

            && (BarsSinceEntryExecution(1, "", 1) != 0)

            Comment


              #7
              Hello DTSSTS,

              Thanks for your note.

              Yes, that would be considered using a barsInProgressIndex argument of 1 when calling the BarsSinceEntryExecution() method to reference the first additional series added in a script.

              BarsSinceEntryExecution(int barsInProgressIndex, string signalName, int entryExecutionsAgo)

              BarsSinceEntryExecution(1, "", 0) != 0

              Let us know if we may assist further.
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                it might be better to just remain on primary and just add signal name

                Is that the Name of the Trade used as a Label as below as LP1

                EnterLong(Convert.ToInt32(DefaultQuantity), @"LP1");

                so keeping Primary data would be as below

                && (BarsSinceEntryExecution(0, "LP1", 0) != 0)

                Comment


                  #9
                  Hello DTSSTS,

                  Thanks for your note.

                  "it might be better to just remain on primary and just add signal name"

                  This would ultimately depend on the logic of your script.

                  The signalName argument for BarsSinceEntryExecution() refers to the signalName given to the entry order as you have described. This could be seen in the Parameters section of the BarsSinceEntryExecution help guide page: "signalName: The signal name of an entry order specified in an order entry method.".

                  As stated in the BarsSinceEntryExecution help guide page: "When a signal name is provided, the number of bars that have elapsed since that last specific entry will be returned."

                  Passing a 0 in for the barsInProgressIndex will reference the primary series the script is running on, as stated in my previous post.

                  See the help guide page for information about using BarsSinceEntryExecution: https://ninjatrader.com/support/help...yexecution.htm

                  Let us know if we may assist further.
                  Brandon H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by GussJ, 03-04-2020, 03:11 PM
                  11 responses
                  3,229 views
                  0 likes
                  Last Post xiinteractive  
                  Started by andrewtrades, Today, 04:57 PM
                  1 response
                  14 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by chbruno, Today, 04:10 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post chbruno
                  by chbruno
                   
                  Started by josh18955, 03-25-2023, 11:16 AM
                  6 responses
                  441 views
                  0 likes
                  Last Post Delerium  
                  Started by FAQtrader, Today, 03:35 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post FAQtrader  
                  Working...
                  X