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

yesterdays H/L bar number

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

    yesterdays H/L bar number

    Hi,
    Is there any possibility to get the bar number of a 5min chart , that made yesterdays High or Low? I'd like to draw S/R levels from these bars for the current day.

    I have already H/L price of the prior day but can not figure out how to get the bar numbers, that made the H/L.

    Cheers
    Thomas

    #2
    Hi Thomas,
    There is built in method HighestBar() that returns the number of bars since the high occurred.

    This snippet below should work for you, but it uses unsupported property LastBarOfSession and only works historically.

    Code:
    #region Variables
    private int myBarsAgo;
    #endregion
    	
    if (Bars.LastBarOfSession)
    myBarsAgo = HighestBar(High, Bars.BarsSinceSession);
    			
    Print(myBarsAgo);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      This was always my problem with HighestBar function. It's unable to work with an index value [int barsAgo]. Even Metatrader had a function supporting this.
      I need to draw this using live data, as it draws HLC lines from Y on the current days chart.

      As a workaround I may use Most Recent Occurence (MRO) to find the bar number.
      int barsAgo = MRO(delegate {return High[0] == Bars.GetDayBar(1).High;}, 1, Bars.BarsSinceSession+81);

      But if you have sessions with less than 81 bars this wouldn't work.

      Any suggestions for this?

      Comment


        #4
        Yeah, I can see how indexing on HighestBar would make this much easier, will add as a suggestion. Yours should work as well. I would also check into modifying PriorDayOHLC() to see if you can custom track a bars ago value there.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Will this work? (I have not tested, only compiled it).

          In Variables:

          public DataSeries x;


          In OnBarUpdate():

          x.Set (Closes[0][1]); //I don't think this would work in initialize?

          Print ( HighestBar (x,15) );

          If anyone proves this out, please reply.




          Originally posted by td_910 View Post
          This was always my problem with HighestBar function. It's unable to work with an index value [int barsAgo]. Even Metatrader had a function supporting this.
          I need to draw this using live data, as it draws HLC lines from Y on the current days chart.

          As a workaround I may use Most Recent Occurence (MRO) to find the bar number.
          int barsAgo = MRO(delegate {return High[0] == Bars.GetDayBar(1).High;}, 1, Bars.BarsSinceSession+81);

          But if you have sessions with less than 81 bars this wouldn't work.

          Any suggestions for this?

          Comment


            #6
            Sledge,
            X has not been instantiated. I get 'Object not set to an instance of the object'.
            I tried to instantiate x but am too unfamiliar with the environment.
            Duke

            Comment


              #7
              Originally posted by dukeb View Post
              Sledge,
              X has not been instantiated. I get 'Object not set to an instance of the object'.
              I tried to instantiate x but am too unfamiliar with the environment.
              Duke
              In Initialize() try adding

              x = new DataSeries(this);

              then it seems like sledge's method should work!

              Comment


                #8
                Originally posted by Radical View Post
                In Initialize() try adding

                x = new DataSeries(this);

                then it seems like sledge's method should work!

                OMG! lol

                I was about ready to say it was going to fail, because I Close[0][1] is a double, not a dataseries. LOL.

                But now this is what we were doing the other week in the DataSeries example and using .Dispose().

                haha, I got lucky on this one.

                But we are making a data series, one off.

                Comment


                  #9
                  I am getting numbers from 0-14. It looks as though '0' is really '1' . Is this correct??

                  Comment


                    #10
                    Originally posted by dukeb View Post
                    I am getting numbers from 0-14. It looks as though '0' is really '1' . Is this correct??
                    Yes, add 1.

                    Print ( HighestBar (x,15)+1 );

                    Comment


                      #11
                      Incredible ...
                      You have made my day, week month ...
                      I can't thank you enough ... great work!!!
                      Duke

                      Comment


                        #12
                        Originally posted by dukeb View Post
                        Incredible ...
                        You have made my day, week month ...
                        I can't thank you enough ... great work!!!
                        Duke
                        I just thought about it. The +1 works on the Closes[0] series.

                        The x (or whatever you decide to call it), won't need it. It's just a copy of a DataSeries that we have built that is 1 bar behind.

                        Comment


                          #13
                          Sledge,
                          I have the following two lines of code.
                          Since you used a set statement to populate the object..
                          I assume you would use a get statement to assign the contents.
                          I have tried a number of possibilities using intellisense. None seem to compile.
                          This compiles but returns wrong information.

                          objHighBarsAgoNumber.Set (Closes[
                          0][1]);
                          HighBarsAgoNumber = (HighestBar (objHighBarsAgoNumber,
                          30)+1); <<<<
                          Thoughts?
                          Thanks,
                          Duke

                          Comment


                            #14
                            Never mind --- I have found the problem...

                            Comment


                              #15
                              awesome idea - many thanks

                              awesome idea - many thanks

                              Thomas

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bmartz, 03-12-2024, 06:12 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Started by Aviram Y, Today, 05:29 AM
                              4 responses
                              12 views
                              0 likes
                              Last Post Aviram Y  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              3 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by gentlebenthebear, Today, 01:30 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by cls71, Today, 04:45 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X