Announcement

Collapse
No announcement yet.

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.
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      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.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          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.
              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              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.
                  <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  54 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  131 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  73 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  49 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X