Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best Practice Find High/Low

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

    Best Practice Find High/Low

    Hi
    I would like to kep track of the most recent High and low.
    Is there a better way than the following:
    1) Bool flag that I have walked back thru the last 100 High[x] and Low[x] to mark the highest high and low.
    2) From then on if a new value High[0] and Low[0] beat those historical values update
    the variables.

    Question 1- Is there a better way?
    Question 2- if (CurrentBar < 100) do something.... If I just start up the strategy and I want to check the last 100 bars for high and lows do I have to wait for the 100 bars to be created.
    Thanks
    Bob

    #2
    Hi Bob,

    MAX() is good for getting the highest value for the specified number of bars. MIN() is available for lowest values.

    Could you please clarify your second question? Bars are processed from left to right, starting at CurrentBar index 0. if (CurrentBar < 100) - That statement says check if the bar is in the first 100 bars.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      So for the max() and Min() I was going to have a boolean flag to state when I first fire up the strategy I get the min and max . Then as each new bar comes in I check to see if its a new min or max and save that value. (I would think that would be less expensive than calling Min() and Max() on every tick...Agreed?)
      My second question was really to clairify that when I first start the strtegy can I always be guaranteed to be able to call for example min(100) ???
      That is why I had the if (CurrentBar<100)

      Comment


        #4
        I'm not sure what value you're after. Are you trying to get the highest high or lowest low since the start of the chart? MAX(High, CurrentBar - 1) can check this.

        If you wanted to code a routine to keep track of this, maybe use something like:

        #region Variables
        private double myHigh;
        #endregion

        if (CurrentBar == 0)
        myHigh = High[0];

        if (myHigh > High[0])
        myHigh = High[0];

        In programming there are several ways of doing things so feel free to use what works best for you. That routine above checks only the most recent bar so should be more efficient than checking all bars in the series.

        If you call MIN(Low, 100) before 100 bars have passed, there will still be a value returned. It will check as far as it can to determine the low here.
        Last edited by NinjaTrader_RyanM1; 12-16-2010, 12:48 PM.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Yes you are correct on the coding example...on what I was asking.
          My goal was recent High and recent low.
          I was trying to see if there was a way to get historical data in my bars. Sounds like there is not a way you have to wait till it fills in for the X number of bars back you are wanting to check.
          Thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          91 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          48 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          31 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          34 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          69 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X