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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X