Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bar Counter - incrementation every X bars

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

    Bar Counter - incrementation every X bars

    Hi

    I'd like my BarCounter of 1 minute chart to print the same numbers as of on my 5m chart. Which means number every 5th bar with nothing in between.
    How could I achieve that? Or maybe is out there somewhere the counter that counts every 5th bar?

    Thanks

    #2
    Hello Pabulon,

    Thank you for your post.

    Are you just looking to get the bar index every 5th bar?

    You could use a counter variable that is incremented on each pass on OnBarUpdate() (if using Calculate.OnBarClose), when the counter = 5 you can print out the CurrenBar to get the index of the bar then reset the counter back to 0.

    Please let us know if you have any further questions.

    Comment


      #3
      5min chart ________1Mchart

      I I I I I I I I I______ __I_I_I_I_I_I_I_I_I_I_I_I_I_I
      1 2 3 4 5 6______________1 ______2 _____3

      I'm looking for smth like above. I hope it represents with clarity what I'm thinking about.
      Last edited by Pabulon; 06-11-2024, 11:32 AM.

      Comment


        #4
        Hello Pabulon,

        Thank you for your response.

        You can achieve this with a counter variable as described above and using Draw.Text().



        Please see the attached sample which demonstrates.
        Attached Files

        Comment


          #5
          Yeah that's what I was hoping for. Thanks for help. Though if you could apply that syntax into regular BarCounter so that it actually starts with the start of the session - that would've be perfection.
          Ofc I aprreciate your help and I can take it from here but it's still not an easy task because I lack basics in coding.

          Comment


            #6
            Hello,

            You would simply need to reset the counter when Bars.IsFirstBarOfSession is true.



            Please let us know if you have any further questions.

            Comment


              #7
              Great. Last thing - how could I lower the FontSize and Align it more properly because atm it looks like below - it overlaps with the bar. I assume it's to be set somewhere in this line
              Draw.Text(this, "barNumber" + CurrentBar, barCounter.ToString(), 1, Low[0] - TickSize, Brushes.Gray)
              Sorry for noob question but so far you helped me greatly. One last small step remained
              Click image for larger version

Name:	image.png
Views:	90
Size:	7.5 KB
ID:	1306909

              Comment


                #8
                Hello,

                To specify a font size for your drawing object you will need to use a SimpleFont and the Draw.Text() overload that lets you specify a SimpleFont parameter.

                Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, int barsAgo, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity)

                For example:

                Code:
                // create custom Courier New, make it big and bold
                NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 50, Bold = true };​
                
                // draw text on chart using SimpleFont myFont
                Draw.Text(this, "MyObject", true, "My Text", 0, Low[0] - TickSize, 0, Brushes.Cyan, myFont, null, null, 100);
                ​​

                If you want to adjust the position of the text in relation to the bar, you will need to adjust the double y parameter.

                Please let us know if you have any further questions.

                Comment


                  #9
                  One more ting to think about -- there are not always 5 days in a trading week. Holidays can result in fewer days in some weeks.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  672 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  379 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  111 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  575 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  582 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X