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

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 bortz, 11-06-2023, 08:04 AM
            47 responses
            1,606 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            15 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X