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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      87 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      132 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      65 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      118 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      67 views
      0 likes
      Last Post PaulMohn  
      Working...
      X