Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Easier way to store a bar number without using a counter?

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

    Easier way to store a bar number without using a counter?

    Howdy.

    I am wondering if there is a simpler way to store the index of a bar that you want to keep for later use?

    Say an event occurs, and you want to keep track of WHEN that occurrence has happened. Typically what I have always done is start a counter, and increment it onBarUpdate(), and when I want to reference that number, subtract that from the current bar to get that location. Of course resetting that value when done.

    Is there a simpler way to accomplish that without the need for counting and resetting your count variables?

    #2
    Hello forrestang,

    You could use a variable to store the position of the Bar instead of counting. For Example:

    Code:
    #region Variables
    private int barConditionMeet = 0;
    #endregion
    
    if ( condition )
    {
       barConditionMeet = CurrentBar;
    }
    Let us know if that helps.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello forrestang,

      You could use a variable to store the position of the Bar instead of counting. For Example:
      Thanks for the reply sir,

      How would you then later reference that particular bar that you stored into that variable?

      Comment


        #4
        Hello forrestang,

        Subtracting the value of the bar that the condition was meet from the CurrentBar will get how many bars ago the conditions occurred at.

        Code:
        // Subtrace the barConditionMeet from the CurrentBar to get the number of bars ago the condition was true
        Close[CurrentBar-barConditionMeet];
        JCNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JC View Post
          Hello forrestang,

          Subtracting the value of the bar that the condition was meet from the CurrentBar will get how many bars ago the conditions occurred at.


          http://www.ninjatrader.com/support/f...ad.php?t=19346
          Oh, duh

          Can't believe I never thought of that "CurrentBar - barConditionMeet".

          Thank you sir!

          Comment


            #6
            store bar index at conditional event

            Thank you NinjaTrader_JC for the sample code.
            Like many things, it is easy when you know how.
            What one can do with NT never ceases to amaze me, but one still has to know how, and that is provided by all the help that we get from the NT help team and other senior members.
            Happy and Prosperous New Year to all NT users, from
            oldhiker

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            161 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            310 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            245 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            349 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            179 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Working...
            X