Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help reseting bool after x bars

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

    Need help reseting bool after x bars

    This is my set up in Strategy Builder.

    The variable bool is set to false as default.
    When condition 1 occurs the variable bool is set to true
    When condition 2 occurs and bool is true a trade is placed and bool is reset to false.


    I need to know how to reset the bool to false after x number of bars if condition 2 does not occur.​

    Thanks

    #2
    When you set the bool to true, save the bar number in an int variable. Then count the bars. When CurrentBar == int BoolTrueBar + X and condition 2 == false, set your bool to false.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      Hello cowlickfarms,

      Thank you for your post and welcome to the NinjaTrader forum community!

      What you could do is also create a custom series that saves the CurrentBar number when the bool is set to true. It must be saved to a series and not an int variable, because with a Series you can use an offset in the Strategy Builder to perform arithmetic. You can have another series that keeps the CurrentBar value for each new bar continuously, and then use the offset to subtract the CurrentBar from when the bool was set to true from the CurrentBar of the continuously updated series. This allows you to have a bar counter, and you can set a condition that checks if that bar counter hits x number of bars before Condition 2 is met. If so, set the bool back to false.

      Here is a link to an example Bar Counter from the Strategy Builder:
      with regard to the attached image: Line A is an indicator Line B is the m period MAX of line A Line C is an average of this indicator A Line D is another average of this indicator A is it possible, possibly using the strategy builder, but without adding a temporary variable, to set on the condition: line C crosses below line D


      You could combine the bar counter idea with your current conditions for the bool in order and this should help you achieve your desired goal.

      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
      44 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      124 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      65 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