Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

null bars

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

    null bars

    I am programming (for NT 6.5) a 1-min bar NinjaScript strategy for an instrument that is quite likely to have less than 1 tick per minute during the time period of interest.

    Say that in a 10-minute period there a three 1-min periods in which no tick occurs.

    In relation to the above situation, if I reference Close[10] in my code will this refer to the close of the bar approx 10 minutes ago, or to the close of the bar approx 13 minutes ago (as there were three 1-min bars that had no OHLC, since no ticks occurred during the minute)?

    #2
    AnotherTrader, NinjaTrader is event not time based, as such if there's no bar there's no Close price for you to 'grab' at that point - it would give you the close price of the bar 13 mins ago then.

    Comment


      #3
      OK, thanks.
      So, when needing to know how many bars ago correspond with a particular point in time (e.g. say it’s now 13h00 EST, and I want know which bar corresponds to the bar which closed at 12h00 EST), it is not enough to make use of say Close[59] for the closing price of that bar; I guess I’ll need to do something like start a counter at 12h00 EST that updates on each OnBarUpdate, and then use Close[counter] for the bar that closed at 12h00 EST.
      Is that what you would recommend?

      Comment


        #4
        You can use the GetBar() method for this task -

        Comment


          #5
          OK, thanks.

          If the timestamp specifies a time after the first bar and before the last bar, but refers to a time at which no bar exists (for the reason previous, i.e. there were no ticks during that timeframe) what does GetBar() return?

          Comment


            #6
            It would then return the next bar satisfying it - for example I try getting todays 9:02 bar which would not exist in cash session on ES running on EST - so GetBar() returns then the 9:35 bar (on 5 min chart).

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              You can use the GetBar() method for this task -

              http://www.ninjatrader-support.com/H...V6/GetBar.html

              The above link references the following example:
              Code:
               
              // Check that its past 9:45 AM 
              if (ToTime(Time[0]) >= ToTime(9, 45, 00)) 
              { 
              // Calculate the bars ago value for the 9 AM bar for the current day 
              int barsAgo = GetBar(new DateTime(2006, 12, 18, 9, 0, 0)); 
              
              // Print out the 9 AM bar closing price 
              Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());
              I need to modify the above to calculate the bars ago value of the prior day's 9AM bar, and to do this on a rolling basis. How would I modify the above?

              Thanks.

              Comment


                #8
                You would for example use DateTime.Today.AddDays(-1) for yesterdays date, but you would need to introduce custom logic to cover weekends here.

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  You would for example use DateTime.Today.AddDays(-1) for yesterdays date, but you would need to introduce custom logic to cover weekends here.
                  ... and I guess market holidays, too.

                  Many thanks!

                  Comment


                    #10
                    How is DateTime.Today.AddDays(-1) inserted into the following in the simplest case (ie ignoring weekends and holidays)?

                    Code:
                     
                    // Check that its past 9:45 AM 
                    if (ToTime(Time[0]) >= ToTime(9, 45, 00)) 
                    { 
                    // Calculate the bars ago value for the 9 AM bar for the current day 
                    int barsAgo = GetBar(new DateTime(2006, 12, 18, 9, 0, 0)); 
                     
                    // Print out the 9 AM bar closing price 
                    Print("The close price on the 9 AM bar was: " + Close[barsAgo].ToString());

                    Comment


                      #11
                      Hello AnotherTrader,


                      If you want that for yesterday using your PC clock as reference:

                      int barsAgo = GetBar(DateTime.Today.AddDays(-1));

                      DateTime.Today is your computer clock date/time so this works for the most current session. If you want it to work historically, then you would use instead Time[0] which is the bar's time stamp.


                      int barsAgo = GetBar(Time[0].AddDays(-1));
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_RyanM View Post
                        .... If you want it to work historically, then you would use instead Time[0] which is the bar's time stamp.

                        int barsAgo = GetBar(Time[0].AddDays(-1));
                        But how would I specify 09h00 am EST on the previous day?

                        The following doesn't seem to work...

                        Code:
                        int barsAgo = GetBar(Time[0].AddDays(-1), 9, 0, 0);
                        Thanks for the help.
                        Last edited by AnotherTrader; 05-11-2011, 04:59 AM.

                        Comment


                          #13
                          AnotherTrader, I would give something like this a try :

                          Code:
                          int myYear  = DateTime.Today.AddDays(-1).Year;
                          int myMonth = DateTime.Today.AddDays(-1).Month;
                          int myDay   = DateTime.Today.AddDays(-1).Day;
                          				
                          int barsAgo = GetBar(new DateTime(myYear, myMonth, myDay, 9, 0, 0));
                          Last edited by NinjaTrader_Bertrand; 05-11-2011, 05:46 AM.

                          Comment


                            #14
                            Thanks.

                            And to be able to backtest, would this be modified to something as follows?

                            Code:
                            int myYear  = Time[0].AddDays(1).Year;
                            int myMonth = Time[0].AddDays(1).Month;
                            int myDay   = Time[0].AddDays(1).Day;
                             
                            int barsAgo = GetBar(new DateTime(myYear, myMonth, myDay, 9, 0, 0));

                            Comment


                              #15
                              Correct, you would need to work with the historical bar timestamp property then for backtesting.

                              Note: I just changed to AddDays(-1) in my posted previous snippet, as you would want to subtract a day, not really add.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              650 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              577 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X