Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Finding Highs/Lows For Prev 5 Days on 1-Minute Chart

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

    Finding Highs/Lows For Prev 5 Days on 1-Minute Chart

    Hi,

    Ultimately, I am trying to find out if the current price (on a 1-minute chart or otherwise) is a 5-Day high or a 5-Day low.

    I am confident that I can perform the necessary calculations to make that determination if I could just find the highs and lows over the past 5 days.

    There is where my problem lies. I am trying to use the following:
    Bars.GetDayBar(2).Low // or replace 2 with 1,3,4, or 5.

    This works on a daily chart but breaks on a 1-minute chart.

    So, in the OnBarUpdate() method, I place the following code:
    double myVar = Bars.GetDayBar(2).Low; // find the low from 2 days ago
    Print(myVar.ToString());

    Note: Since I am wanting to find the previous 5 days highs/lows, I have this at the top of my OnBarUpdate() method:
    if (CurrentBars[0] < 5)
    return;

    This works perfectly on a daily chart.

    On a 1-minute chart, I get the following error message:

    "Error on calling OnBarUpdate method on bar 5: Object reference not set to an instance of an object."

    Any help on this would be greatly appreciated!

    #2
    Hey SeanK,
    Have a look at the built in Swing indicator.

    Comment


      #3
      Hello SeanK,

      Thank you for your note.

      You could use the swing indicator or you could add a secondary daily data series, and reference that series previous high values.

      I put together a sample indicator you can apply to a minute chart, and the indicator will display the previous 5 days highs in the upper right hand corner of the chart.

      Your error in your indicator is related to not checking to having enough intraday bars to get day information, see current bar check



      Also see GetDayBar, and related warning.


      In my sample I used,





      I left a print statement in my sample which prints yesterdays highs using Bars.GetDayBar(1).Low. You could still go that approach too as long as you check you have enough current bars.

      Please let us know if you need further assistance.
      Attached Files
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by SuperDriveGuy View Post
        Hey SeanK,
        Have a look at the built in Swing indicator.
        Thank you for this! I will take a look.

        Comment


          #5
          Hey Alan,

          Thank you so much for your detailed reply! This helps a lot.

          I will test this out and let you know if I have any other issues.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          65 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          139 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X