Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bar Numbering

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

    Bar Numbering

    I am trying to find a bar numbering indicator, similar to what Al Brooks uses. I found a numbering indicator, but it doesn't start with bar 1 of the current chart and I don't see any way to change it. Does anyone have such a thing?

    Dale

    #2
    Dale, you could certainly create your own indicator that numbers the bars. Just stick this line of code inside OnBarUpdate() of an indicator (perhaps a new indicator to keep stuff separate) and you'll be good to go:
    Code:
    DrawText("bar number" + CurrentBar, CurrentBar.ToString(), 0, High[0] + 3 * TickSize, Color.Black);
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thanks Austin, I tried your suggestion, and just got a pile of error messages.

      Db

      Comment


        #4
        Dale, please try this:

        1) Tools -> New indicator -> name it -> next -> next -> next until the code appears
        2) Paste the line into OnBarUpdate()
        3) Hit the F5 key to compile
        4) Put your new indicator on a chart.
        Attached Files
        AustinNinjaTrader Customer Service

        Comment


          #5
          Hi again Austin, I discovered the problem, I use 6.5 for my trading, I haven't switched to 7 for live trading yet. When I created the indicator in 7 it worked, however there is already an indicator called Bar Numbers created by someone else which does the same thing. Could you tell me how to set it so the count starts with the first bar of the day? Right now it starts with the first bar of the first day of the chart series.

          DB


          Comment


            #6
            Dale, you'll have to create some sort of a counter that resets upon each new session. We aren't allowed to write code for customers, but I knew this would be hard to explain and it would result in much back-and-forth between you and us, so I just coded it out for you. Please take a look and study the code so you can see how and when the numbers reset. Of primary interest is the property Bars.FirstBarOfSession - this property returns true if and only if the bar is the first bar of a new session.
            Code:
            public class SessionBars : Indicator
            {
                private int sessionBar = 0;
                private int difference = 0;
                protected override void Initialize()
                {         
                    Overlay                = false;
                }
                protected override void OnBarUpdate()
                {
                    if (Bars.FirstBarOfSession)
                    {
                        sessionBar = 0;
                        difference = CurrentBar;
                    }
                    
                    if ((sessionBar + difference) != CurrentBar)
                    {
                        sessionBar = sessionBar + 1;
                    }
                    
                    DrawText("bar number" + CurrentBar, sessionBar.ToString(), 0, High[0] + 3 * TickSize, Color.Black);
                    
                }
            }
            If you want to show less text, you could draw only on every odd numbered or even numbered bar by using the modulo operator (%). It basically gives you the remainder after a division operation.
            Code:
            if (CurrentBar % 2 == 0)
            {
               // place the draw text code here
            }
            The screenshot only shows every other bar number.
            Attached Files
            AustinNinjaTrader Customer Service

            Comment


              #7
              Thanks Austin, I appreciate your help, I will try it out tommorrow, I really know nothing about code, and my focus right now is on improving my trading results.

              Dale

              Comment


                #8
                Five stars to Austin

                Excellent - takes half the time and supports a new user.

                Comment


                  #9
                  Is it possible to number the bars at the bottom of the screen? Kind of like the attached picture.
                  Attached Files

                  Comment


                    #10
                    Hi JoshDance,

                    One of our members has shared an indicator that does this - available in the file sharing section:

                    http://www.ninjatrader.com/support/f...d=4&linkid=430
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks very much Ryan-- I would like to see if I can modify it to show numbers on two separate rows like in the picture I posted, as when we get into the double digit bars starting with 10 it becomes a bit crowded. Thanks for pointing me to this!

                      Comment


                        #12
                        Originally posted by NinjaTrader_Austin View Post
                        Dale, you'll have to create some sort of a counter that resets upon each new session. We aren't allowed to write code for customers, but I knew this would be hard to explain and it would result in much back-and-forth between you and us, so I just coded it out for you. Please take a look and study the code so you can see how and when the numbers reset. Of primary interest is the property Bars.FirstBarOfSession - this property returns true if and only if the bar is the first bar of a new session.
                        Code:
                        public class SessionBars : Indicator
                        {
                            private int sessionBar = 0;
                            private int difference = 0;
                            protected override void Initialize()
                            {         
                                Overlay                = false;
                            }
                            protected override void OnBarUpdate()
                            {
                                if (Bars.FirstBarOfSession)
                                {
                                    sessionBar = 0;
                                    difference = CurrentBar;
                                }
                                
                                if ((sessionBar + difference) != CurrentBar)
                                {
                                    sessionBar = sessionBar + 1;
                                }
                                
                                DrawText("bar number" + CurrentBar, sessionBar.ToString(), 0, High[0] + 3 * TickSize, Color.Black);
                                
                            }
                        }
                        If you want to show less text, you could draw only on every odd numbered or even numbered bar by using the modulo operator (%). It basically gives you the remainder after a division operation.
                        Code:
                        if (CurrentBar % 2 == 0)
                        {
                           // place the draw text code here
                        }
                        The screenshot only shows every other bar number.
                        Austin, I used the above code and even-number only modification you suggested, to create the bar-numbering indicator I wanted so thank you very much. It just has one bug I can't figure out how to fix: the first bar on my 5-minute chart (i.e. the one that closes at 9:35am Eastern) is numbered 0. I need it to be numbered 1 or else it throws off the count for the whole day. What do I need to change in the code? Thank you.

                        Comment


                          #13
                          Start your session count at a value of 1

                          Code:
                          if (Bars.FirstBarOfSession) 
                          {             
                          sessionBar = 1;             
                          difference = CurrentBar - 1;
                          }
                          Last edited by koganam; 01-24-2012, 03:20 PM.

                          Comment


                            #14
                            Thank you. I tried that, and now the first bar is numbered 2. Here's the full script; is there something else in there throwing it off? Thanks again.


                            public class SessionBars : Indicator
                            {
                            private int sessionBar = 0;
                            private int difference = 0;
                            protected override void Initialize()
                            {
                            Overlay = false;
                            }
                            protected override void OnBarUpdate()
                            {
                            if (Bars.FirstBarOfSession)
                            {
                            sessionBar = 1;
                            difference = CurrentBar;
                            }

                            if ((sessionBar + difference) != CurrentBar)
                            {
                            sessionBar = sessionBar + 1;
                            }

                            if (CurrentBar % 2 == 0)
                            {
                            DrawText("bar number" + CurrentBar, sessionBar.ToString(), 0, High[0] + 3 * TickSize, Color.White);

                            }
                            }
                            }
                            }

                            Comment


                              #15
                              I believe I may have edited it while you were working? At any event, what you have is not what I last wrote.

                              difference = CurrentBar - 1;

                              Funnily enough, once you use that line, it will not matter if you set sessionBar to zero or one: you should get the same result.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by pilotfo, Today, 12:50 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by DTSSTS, Today, 11:35 AM
                              2 responses
                              11 views
                              0 likes
                              Last Post DTSSTS
                              by DTSSTS
                               
                              Started by sinpeople, Today, 07:20 AM
                              2 responses
                              9 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Frank1000, Today, 03:05 AM
                              5 responses
                              16 views
                              0 likes
                              Last Post Frank1000  
                              Started by fscabrera03, Yesterday, 01:18 PM
                              2 responses
                              26 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X