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

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.
      Emily C.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Marklhc1988, 04-19-2023, 11:11 AM
      12 responses
      569 views
      1 like
      Last Post victor68133  
      Started by nicthe, Yesterday, 02:58 PM
      1 response
      9 views
      0 likes
      Last Post nicthe
      by nicthe
       
      Started by percy3687, 05-17-2024, 12:28 AM
      3 responses
      30 views
      0 likes
      Last Post percy3687  
      Started by SilverSurfer1, Yesterday, 01:33 PM
      0 responses
      12 views
      0 likes
      Last Post SilverSurfer1  
      Started by ETFVoyageur, Yesterday, 10:27 AM
      2 responses
      19 views
      0 likes
      Last Post ETFVoyageur  
      Working...
      X