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 gentlebenthebear, Today, 01:30 AM
          2 responses
          13 views
          0 likes
          Last Post gentlebenthebear  
          Started by Kaledus, Today, 01:29 PM
          2 responses
          7 views
          0 likes
          Last Post Kaledus
          by Kaledus
           
          Started by frankthearm, Yesterday, 09:08 AM
          13 responses
          45 views
          0 likes
          Last Post frankthearm  
          Started by PaulMohn, Today, 12:36 PM
          2 responses
          16 views
          0 likes
          Last Post PaulMohn  
          Started by Conceptzx, 10-11-2022, 06:38 AM
          2 responses
          55 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Working...
          X