Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Counter for Side-By-Side Bars

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

    Counter for Side-By-Side Bars

    Hi NT,

    I created a counter below. It counts bars that are side-by-side (up close / down close or down close / up close)

    Code:
    if (
    
    Close[0] > Open[0] && Close[1] < Open[1] ||
    Close[0] < Open[0] && Close[1] > Open[1]
    
    )
    
    {
    
    if (counter == 0)
    counter = 2;
    
    else
    counter = counter + 1;
    
    Draw.Text(this, "MyText"+CurrentBar, counter.ToString(), 0, ((Open[0] + Close[0]) / 2), Brushes.White);
    
    }
    
    else
    counter = 0;
    I am using the UniRenko bar type and it works (see attached).

    Now, I would like to fine tune it.
    I would like to display only the highest count of side-by-side bars as we go along.
    For example 6 instead of 2 3 4 5 6

    If I remove the 'CurrentBar' in DrawText I am able to achieve that in real-time. However, I then lose the count with all the historical bars.
    Unfortunately, I can not figure out how to have both and would appreciate some assistance.
    Thank you

    #2
    Hello ij001,

    Thanks for your post.

    You would need to use RemoveDrawObjects(stringname);
    Reference: https://ninjatrader.com/support/help...drawobject.htm

    If your counter is greater than or equal to 3 you could RemoveDrawObject("MyText"+(CurrentBar-1)) which should remove the previous drawing. as the count increases and you draw the new count, the previous drawing of the count is removed.

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello ij001,

      Thanks for your post.

      You would need to use RemoveDrawObjects(stringname);
      Reference: https://ninjatrader.com/support/help...drawobject.htm

      If your counter is greater than or equal to 3 you could RemoveDrawObject("MyText"+(CurrentBar-1)) which should remove the previous drawing. as the count increases and you draw the new count, the previous drawing of the count is removed.
      I added


      RemoveDrawObject("MyText"+(CurrentBar-1));
      under my DrawText line and it worked.

      Thank you

      Comment


        #4
        Originally posted by NinjaTrader_PaulH View Post
        Hello ij001,

        Thanks for your post.

        You would need to use RemoveDrawObjects(stringname);
        Reference: https://ninjatrader.com/support/help...drawobject.htm

        If your counter is greater than or equal to 3 you could RemoveDrawObject("MyText"+(CurrentBar-1)) which should remove the previous drawing. as the count increases and you draw the new count, the previous drawing of the count is removed.
        Hello NT,
        I am revisiting this post from last year.

        I have set Calculate = Calculate.OnBarClose;

        When the bar closes, I would like it to draw the counter on bar[1] (which was CurrentBar)
        That does not happen. After the bar closes, it draws on bar[0], which is still developing.

        However, when I click Reload NinjaScript it loads on bar[1] with the correct value from the counter as intended.

        Hopefully I explained it correctly. How do I fix without reloading?

        Thx Irv
        Last edited by ij001; 11-17-2021, 08:05 PM.

        Comment


          #5
          Hello Irv,

          Thanks for your reply.

          Something does not make sense.

          If you are using Calculate.OnBarClose then the bar that is forming is not known to the script and [0] would be the just closed bar.

          Please verify your statements.


          Comment


            #6
            Originally posted by NinjaTrader_PaulH View Post
            Hello Irv,

            Thanks for your reply.

            Something does not make sense.

            If you are using Calculate.OnBarClose then the bar that is forming is not known to the script and [0] would be the just closed bar.

            Please verify your statements.

            That makes sense that the script does not know.
            As a habit, I don't use Calculate.OnEachTick because my belief is it may use too many resources for a simple method.

            What confuses me is when I click Reload NinjaScript that it loads what I intended. Essentially fixing the error.
            Perhaps you can explain why that is or provide a DrawText example, then I can properly word my question.

            Thank you.
            Irv

            Comment


              #7
              Hello Irv,

              Thanks for your reply.

              Can you post a screenshot of the chart before you reload and then after a reload? If so, be sure to capture both the price scale and the time scale in the view for reference.

              Also, please post the code you are using that includes the counter, the code to draw, and the code to remove.

              Comment


                #8
                Originally posted by NinjaTrader_PaulH View Post
                Hello Irv,

                Thanks for your reply.

                Can you post a screenshot of the chart before you reload and then after a reload? If so, be sure to capture both the price scale and the time scale in the view for reference.

                Also, please post the code you are using that includes the counter, the code to draw, and the code to remove.
                Hi Paul,

                I created a new chart and added the indicators. It appears to be working but I'll continue to monitor next week.

                Perhaps it was a bug of some kind and required a fresh start.

                Thanks Irv

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                636 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                366 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                568 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                571 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X