Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBar, but what's the Last Bar?

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

    CurrentBar, but what's the Last Bar?

    My code needs to know the number of the last bar which will processed by OnBarUpdate() , so that it know's it's in the last loop. I can get the CurrentBar but how do I know I'm on the last or rightmost bar? Any ideas?

    Thanks in advance. -Dean
    Last edited by cybertunerone; 02-01-2009, 09:47 PM.

    #2
    Hello,

    It depends on what you are doing exactly.

    !Historical may work:


    Or you can just check for when the bar index is zero, which is the current bar.
    DenNinjaTrader Customer Service

    Comment


      #3
      cyber,

      are you coming from the metatrader programming world?

      If you are things are easier than you think. Let me review some of the indicator converts I have created in the past and i'll get back to you.
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #4
        Originally posted by NinjaTrader_Ben View Post
        Hello,

        It depends on what you are doing exactly.

        !Historical may work:


        Or you can just check for when the bar index is zero, which is the current bar.
        Ok, but when I do this inside OnBarUpdate():
        if (CurrentBar==0)
        // never gets here
        if (Historical==false)
        // never gets here either
        Any ideas? Thanks -Dean

        Comment


          #5
          When running a strategy, you have a minimum bars required parameter. By default it is 20. This is why CurrentBar == 0 never evaluates to true. If you set BarsRequired = 0 then you can go CurrentBar == 0.

          if (Historical == false) will never be true during backtesting. It will only be true as you receive and process live, real-time data.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Maybe another way to ask this is, is there any way inside OnBarUpdate() to look ahead (peek?) to the next bar? (future historical data bar)

            Comment


              #7
              Nope. NinjaTrader does not allow for any peaking into the future.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Ok so no peeking, no problem. But back to the original question: How can OnBarUpdate() code detect that it's in the final loop through?

                My strategy needs to have all the historical bar data up to and including the most recent bar available before it can do calculations, so it can only really do anything in the final call to OnBarUpdate(). That's why it needs to know when the right most bar occurs.

                btw, BarRequired, CurrentBar, Historical don't help with this far as I can tell.

                Comment


                  #9
                  As discussed, NinjaTrader processes going forward. To it, every single OnBarUpdate is a process of the last available data. Not sure why you need to be in the final OnBarUpdate to do anything special. As far as NT sees it, every OnBarUpdate is the final and it will process it no different. If you wanted to store some value. Just have it go through, run OnBarUpdate, when it finishes the last value stored is the final value from the final OnBarUpdate run.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    ...If you wanted to store some value. Just have it go through, run OnBarUpdate, when it finishes the last value stored is the final value from the final OnBarUpdate run.
                    Ok, but that's the key, when is the final OnBarUpdate run? (and how to detect it?) And if I store some data during one or more OnBarUpdate calls, how do I process it later? Is it possible to have some code run after the final OnBarUpdate call?

                    There must be some way to detect the final pass through OnBarUpdate. The only way I can find that info during developement is to output Print() to the Output window and look at the final CurrentBar printed.

                    possible to do a sizeof() on a DataSeries that is Add() -ed in Initialize() maybe? Hmmmm... thanks for your help.
                    Last edited by cybertunerone; 02-02-2009, 10:56 AM.

                    Comment


                      #11
                      cybertunerone,

                      There is no "right most bar" concept. Every process is seen as the right most bar. As far as the strategy is concerned there is nothing in front of it until it processes something in front.

                      When you reach the last bar it will process that bar like every other bar. The output you get from that bar will be the output you want to keep.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Josh View Post
                        cybertunerone,

                        There is no "right most bar" concept. Every process is seen as the right most bar. As far as the strategy is concerned there is nothing in front of it until it processes something in front.

                        When you reach the last bar it will process that bar like every other bar. The output you get from that bar will be the output you want to keep.
                        Ok, no right most bar. However my strategy needs to look at all the historical OHLC data available before painting the indicators. Anything from 200 to 500 bars is usually enough. Is there some other way to do that?

                        Comment


                          #13
                          cybertunerone,

                          Unfortunately I do not understand what you are concerned about. When you paint you are painting relative to the bars present. You move one bar forward, you plot another data point on your plot based on the additional information. You keep moving forward, you keep updating your plot.

                          If you don't want the indicator to do anything until the 500th bar then use BarsRequired = 500. It won't plot till bar 501.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_Josh View Post
                            cybertunerone,

                            Unfortunately I do not understand what you are concerned about. When you paint you are painting relative to the bars present. You move one bar forward, you plot another data point on your plot based on the additional information. You keep moving forward, you keep updating your plot.

                            If you don't want the indicator to do anything until the 500th bar then use BarsRequired = 500. It won't plot till bar 501.
                            The strategy involves price exhaustion probability similar to DeMark indicators. There's no way to paint bar indicators as you go unless you could "unpaint" them on a later bar. The indicators on one bar can "cancel" the previous bar's indicator. So I could do as you suggest, set BarsRequired to 500 and process everything on bar 501, but only IF the code knows ahead of time that there are exactly 501 bars. If I set BarsRequired to 500 does that mean I'm guaranteed 500 bars of data? Doesn't seem it would work that way. Thanks for your help.
                            Last edited by cybertunerone; 02-02-2009, 11:41 AM.

                            Comment


                              #15
                              Yes, BarsRequired = 500 guarantees you 500 bars of data before doing anything.

                              I still do not understand your concern about painting. When you use a plot you have a data point for every single bar. Just look at the last bar's data point value. If you are trying to write text or draw on the chart, for sure you can just keep repainting them. Use the same signal name and it will overwrite the old one instead of making new objects.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              566 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              330 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              547 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              548 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X