Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bar range for specific days

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

    Bar range for specific days

    Hi NT8 bods,

    I am trying to work out the best way to get the bar range for today, yesterday, the day before that etc so I can do calcs on those specific bars .. I can see I can use first bar of session and barsgao, but not too sure how to use that going back over a series fo days for example today .. to .. 7 days ago for example .. have you got any links or test scripts I can take a look at ?

    As always, many thanks in advance for your help

    Cheers

    #2
    Originally posted by 12tkram View Post
    Hi NT8 bods,

    I am trying to work out the best way to get the bar range for today, yesterday, the day before that etc so I can do calcs on those specific bars .. I can see I can use first bar of session and barsgao, but not too sure how to use that going back over a series fo days for example today .. to .. 7 days ago for example .. have you got any links or test scripts I can take a look at ?

    As always, many thanks in advance for your help

    Cheers
    NinjaTrader ships with an indicator called Range.

    Comment


      #3
      doesn't that give the range of a bar ? https://ninjatrader.com/support/help...nt8/?range.htm ? if so, then thats not what I am asking, let me clarify ..

      I want the bar number of the first bar of today, then, the number of the bar of the first bar of yesterday and the last bar or yesterday, then the number of the first bar two days ago and the last bar of that day ... day 3 .... day 4 .... day 5 .... day 6 .... day 7 ....


      Comment


        #4
        Hi 12tkram, thanks for your note.

        You can add a Daily series to your script and get the Range in terms of the daily series. I attached an example for your reference. If you want to run this, place the attached file within Documents\NinjaTrader 8\bin\Custom\Indicators and compile.

        Please let me know if you have any questions.
        Attached Files

        Comment


          #5
          Thanks Chris, what does this do ? give the range of price for the day ? that is not what I am after

          So, for example, I have a 1 minute chart, I want to know the bar[n] number of the first bar of the day so I can use

          if(CurrentBar<bar[n])//do some stuff for today

          Then, I would like to get the bar[n] of the first bar and last bar of yesterday,

          if(CurrentBar<bar[first bar] and CurrentBar>bar[last bar])//do some stuff for yesterday

          Then the bar[n] of the fist and last bar of day 2

          if(CurrentBar<bar[first bar] and CurrentBar>bar[last bar])//do some stuff for the day before yesterday

          Does that make sense ?

          I know I can use first bar of session, but not 100% sure how to use that for previous days etc.

          Cheers







          Comment


            #6
            Hi 12tkram, thanks for your reply.

            The first and last bar will need to be accumulated as the indicator runs through the historical data, you would then store the values from those bars in a custom struct. Alternatively, you can store the CurrentBar value and reference whatever that value is when you need the info from these bars. Use IsFirstBarOfSession and IsLastBarOfSession to tell when the first and last bar comes.

            Comment


              #7
              Thanks Chris, ok, so, was going to store in an int array, not to good with structs ... which way does nt script parse the bars ? is it max to min, or min to max ? and do you have any suggestions as to how to work out what day the loop is on so I can use that as the index for the array ?

              Comment


                #8
                actually. not to worry, will do a count, then if its max to min reverse the count from the max iteration .. and if its min to max then its already the right way round .. just not sure which order it parses the bars ..

                Comment


                  #9

                  if(Time[0]>=today.AddDays(-2)&&Time[0]<=today.AddDays(-3)) // summit like that ? that will work won't it ?

                  Comment


                    #10
                    Hi, thanks for your reply.

                    You have two ways of accessing historical bars. The CurrentBar property counts from left to right. So the leftmost bar on the chart will be CurrentBar == 0. The other way is to access the data from the Price series array. With a price series the most current price will be referenced as Close[0] and the leftmost bar would be Close[CurrentBar].

                    Since IsFirstBarOfSession and IsLastBarOfSession will only work on the currently processing bar you will need to capture the data on the historical run.

                    The procedure would be:

                    if IsFirstBarOfSession
                    store a value for the current bar (Close[0], Open[0], etc)

                    if IsLastBarOfSession
                    store needed last bar of session values

                    Place these values in a data structure where they can be accessed at a later time.
                    Last edited by NinjaTrader_ChrisL; 10-31-2019, 03:15 PM.

                    Comment


                      #11
                      Originally posted by 12tkram View Post
                      if(Time[0]>=today.AddDays(-2)&&Time[0]<=today.AddDays(-3)) // summit like that ? that will work won't it ?
                      What you have written will logically never be true. You want Time[0] that is >= a time 2 days ago, and <= a time 3 days ago. If you switched that, the line would work, but is also static.

                      You want something that you can store and query later. That suggests a collection of some kind. The most elegant would be to create a list of structs, and then query each member of a struct to get the value that you want. However, you could simply use 2 separate lists, one for the FirstBarOfSession and another for the LastBarOfSession.
                      1. Declare your lists at the class level as List<int>
                      2. Populate the lists in OnBarUpdate()
                      Let us assume that you declare 2 lists, FBOS and LBOS.
                      Code:
                      private List<int> FBOS = new List<int>();
                      private List<int> LBOS = new List<int>();
                      Then in OnBarUpdate(), you would simply do:
                      Code:
                      if (Bars.IsFirstBarOfSession) FBOS.Add(CurrentBar);
                      else if (Bars.IsLastBarOfSession) LBOS.Add(CurrentBar);
                      Now then the first bar of today would be FBOS[FBOS.Count - 1], and the last bar of yesterday would be LBOS[LBOS.Count - 1]. Previous indices would hold the values as you go backwards in time.
                      Last edited by koganam; 10-31-2019, 03:06 PM.

                      Comment


                        #12
                        cool, thanks for the info, I will have a play with that, looks like its the right way to go.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        581 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        338 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        103 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        554 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        552 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X