Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarTime?

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

    BarTime?

    In NT7 one could do this to get the timestamp of a bar:
    DateTime dateTime = indicator.Bars.GetTimeEnd(indicator.CurrentBar);
    How NT8?

    #2
    Hello,

    There is actually a Time collection in both NinjaTrader 7 and NinjaTrader 8 which contains DateTime objects pegged to the end time of each bar. In either version, you can use Time[0] to get a DateTime representing the current bar.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Actually I need the next bar:
      DateTime dateTime = indicator.Bars.GetTimeEnd(indicator.Bars.CurrentBa r + 1); // PLUS 1

      indicator.Time[0]; // will give me the current bar time
      indicator.Time[1]; // will give me previous bar time
      but can I say?:
      indicator.Time[-1]; // minus 1?

      I'm porting a lot of code and I'm not going to be testing for a while. I thought there must be a way to get the DateTime using a CurrentBar parameter. Is there?

      Comment


        #4
        I would not personally advise trying to view data for future bars in general, as this data is not always available, and doing this can lead to unexpected results.

        That being said, since Time[0] returns a DateTime object, you should be able to use one of DateTime's "Add" methods to determine the timestamp of future bars (assuming you are using time-based bars and not tick, Renko, etc.).

        For example, something like this should provide you with a timestamp of the next two bars on a 1-minute interval:

        Code:
        	DateTime timeCurrentBar;
        		DateTime timeNextBar;
        		DateTime timeTwoBarsOut;
        		
        		protected override void OnBarUpdate()
        		{
        			timeCurrentBar = Time[0];
        			timeNextBar = timeCurrentBar.AddMinutes(1);
        			timeTwoBarsOut = timeCurrentBar.AddMinutes(2);
        		}
        Using CurrentBar for this could be tricky. The Time collection uses a "bars ago" value rather than CurrentBar. Thus, for example, if CurrentBar == 2552, then Time[0] will refer to Bar # 2552, which is 0 bars ago.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          Thinking about this further, there is a better option available, depending upon the goal you are trying to accomplish.

          In NinjaTrader 8, we differentiate the concept of a Bar from the concept of a Slot in a data series. Data series are set up with "slots" corresponding to their interval, and then Bars are painted within those slots. Trying to access properties of an actual bar in the future is not advisable, and that is what I was referring to in my previous post. However, accessing a slot in the future should be completely safe. This is because the object corresponding to a future bar may not yet exist at a specific point in time, while the slots will already exist.

          That being said, if what you are really looking for is a slot in the data series at a future point, then you could accomplish this with the ChartControl.GetTimeBySlotIndex() method, and this would allow you to use a CurrentBar value as a starting point to find a future time.

          Take a look at the example below, which will give you the time of the next slot at any point in time:

          Code:
          protected override void OnBarUpdate()
          {                                                                                                                                                                                                                                               
             Print("Current bar time: " + Time[0]);
             Print("Next slot time: " + ChartControl.GetTimeBySlotIndex(CurrentBar + 1));
          }
          In this example, we use ChartControl.GetTimeBySlotIndex(), and then pass in a value that is 1 greater than CurrentBar.
          Dave I.NinjaTrader Product Management

          Comment


            #6
            Hi Dave.
            That's all good to know however it doesn't meet me needs.

            First I should clarify my purpose: On the historical bars I need to access the next trade date. Using the DateTime object will not work but looking forward one day in the dataseries works perfectly.

            This is code that works in NT7 and I'm simply trying to directly port it over. Must have the next bar in the series.

            Comment


              #7
              Hello Brillo,

              For further clarification, can you please provide the code that you have written in NinjaTrader 7 that accomplishes what you are asking for?
              Zachary G.NinjaTrader Customer Service

              Comment


                #8
                Sure. Put this line in any NT7 indicator script:

                DateTime dateTime = Bars.GetTimeEnd( Bars.CurrentBar + 1);

                Get's the DateTime for the next bar in the series during historical bars processing.

                Comment


                  #9
                  Brillo,

                  If you need to get a historical DateTime object from an absolute Bar Index, you can use Bars.GetTime()

                  Code:
                  Print(Bars.GetTime(CurrentBar + 1));
                  Note that the logic breaks down when using it on real-time data. It is in that case you should try using the ChartControl.GetTimeBySlotIndex(CurrentBar + 1)
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    Question: Does NinjaTrader have a RENKO ATR bar available?

                    Hi Guys. Does NinjaTrader have a RENKO ATR bar available? I would like an ATR Renko bar, plotted on OHLC, like TradingView. Is that available for NinjaTrader? Thanks

                    Comment


                      #11
                      Can you please clarify exactly what the Renko ATR would do? Since Renko bars are all sized equally, according to the Brick Size set by the user, I would expect an ATR on Renko bars to always equal the bars' Brick Size, but there could be an angle that I'm not seeing.
                      Dave I.NinjaTrader Product Management

                      Comment


                        #12
                        Hello spmcc33,

                        Renko bars are an available bar type already included with NinjaTrader as well as an ATR indicator and a PriorDayOHLC indicator.

                        In order to switch a chart to a Renko chart, you'll want to right-click on the chart and select Data Series. This will bring up the Data Series window. Here, you'll want to change the "Type" parameter under the "Period" category to Renko. You'll then be able to specify the brick size of your Renko bars below the Type.

                        Once you have done this, press OK. This will change your current chart to a Renko chart.

                        Here is a link to the NinjaTrader help guide that details working with price data in the Data Series window: http://ninjatrader.com/support/helpG...price_data.htm

                        To find the ATR and PriorDayOHLC indicators, please right-click on the chart and select Indicators. This will bring up the Indicators window.

                        To add an indicator to the chart, select the indicator from the indicator list and then select New. You'll then be able to modify the parameters for the indicator. Do this for each indicator you would like to add to your chart.

                        Here is a link to the NinjaTrader help guide that details working with indicators: http://ninjatrader.com/support/helpG...indicators.htm
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          After doing a bit of research on this, I've found what you were referring to. This is not currently available in NinjaTrader, although it would be possible to create a new ATR Renko bar type via NinjaScript. I've added a feature request tracked with ID # SFT-854 for this request. Thank you.
                          Dave I.NinjaTrader Product Management

                          Comment


                            #14
                            Hi Matthew

                            Code:
                            Print(Bars.GetTime(CurrentBar + 1));
                            This works but the DateTime object returned does not have the TimeSpan component. In other words, the time is always 12:00 am.

                            The Time[0] property returns a DateTime with the TimeSpan but unfortunately one can not look ahead with the relative syntax such as Time[-1].

                            I've solved the problem by assuming that "today's" end bar time will be tomorrow's end bar time:

                            Code:
                            Bars.GetTime(CurrentBar + 1).Add( Time[0].TimeOfDay )
                            Probably should look up the session for tomorrow?
                            But it looks like a bug to me in the GetTime API.

                            Comment


                              #15
                              Hello Brillo,

                              You would want to be using ChartControl.GetTimeBySlotIndex(CurrentBar + 1).

                              Originally posted by NinjaTrader_Matthew View Post
                              Note that the logic breaks down when using it on real-time data. It is in that case you should try using the ChartControl.GetTimeBySlotIndex(CurrentBar + 1)
                              Please, let us know if we may be of further assistance.
                              Zachary G.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Javierw.ok  
                              Started by timmbbo, Today, 08:59 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post bltdavid  
                              Started by alifarahani, Today, 09:40 AM
                              6 responses
                              40 views
                              0 likes
                              Last Post alifarahani  
                              Started by Waxavi, Today, 02:10 AM
                              1 response
                              18 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by Kaledus, Today, 01:29 PM
                              5 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X