Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Preventing New entries after taking profit using BarsSinceExit()

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

    Preventing New entries after taking profit using BarsSinceExit()

    Click image for larger version  Name:	image.png Views:	0 Size:	113.0 KB ID:	1227747 Hello,

    I am looking to create logic that will prevent my strategy from entering trades if I exited a position within a certain number of bars. ​In the picture attached, the strategy takes an entry immediately after closing a profitable position. I want to implement a "No Trade" rule where once I close a position in profit, the strategy does not trade for a certain number of bars.

    I attempted to do this using a condition for entry of:

    > BarsSinceExitExecution(0,@"End Rotation",0) > 7 = True

    But the strategy never executes any trades when this is a condition.

    I attempted to create a bool variable that is only true if BarsSinceExit() is greater than 7, but I run in to the same problem. The strategy does not ever enter trades with this condition in the code.

    I've added a picture to illustrate what my goal is, and I've attached both the current version of the strategy and the version that includes the BarsSinceExit bool variable to show you what I thought might work. ​

    #2
    If you are using BarsSinceExitExecution() as an "entry" condition then you have to account for the very first attempt at an historical trade which cannot occur because you have no previous exits.
    From the help guide: https://ninjatrader.com/support/help...nceexitexecuti on.htm Specifically Method Return Value: An int value that represents a number of bars. A value of -1 will be returned if a previous exit does not exist.

    Look at their example: if ((BarsSinceExitExecution() > 10 || BarsSinceExitExecution() == -1) so this checks for the bars to be greater than 10 OR no prior exit with -1




    Comment


      #3
      Hello RallySquirrel,

      Thank you for your note.

      As Tasker-182 has mentioned, you have to consider the possibility of the strategy not yet placing any trades in addition to the number of bars since your last exit. By including an OR statement in your condition, such as || BarsSinceExitExecution() == -1, this should fix the behavior you have reported. Here is an example of how your previous condition could be added to:

      if (BarsSinceExitExecution(0,@"End Rotation",0) > 7 = True || BarsSinceExitExecution() == -1)
      // enter here

      Please let us know if we may be of further assistance.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      51 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      128 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X