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 PhillT, Today, 02:16 PM
            1 response
            1 view
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by Kaledus, Today, 01:29 PM
            3 responses
            9 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frankthearm, Yesterday, 09:08 AM
            14 responses
            47 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by gentlebenthebear, Today, 01:30 AM
            2 responses
            13 views
            0 likes
            Last Post gentlebenthebear  
            Started by PaulMohn, Today, 12:36 PM
            2 responses
            17 views
            0 likes
            Last Post PaulMohn  
            Working...
            X