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

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 WHICKED, Today, 12:56 PM
          0 responses
          4 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by Spiderbird, Today, 12:15 PM
          2 responses
          10 views
          0 likes
          Last Post Spiderbird  
          Started by WHICKED, Today, 12:45 PM
          0 responses
          7 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by FrazMann, Today, 11:21 AM
          2 responses
          6 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by rjbtrade1, 11-30-2023, 04:38 PM
          2 responses
          80 views
          0 likes
          Last Post DavidHP
          by DavidHP
           
          Working...
          X