Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Paul H.NinjaTrader Customer Service

    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.


          Paul H.NinjaTrader Customer Service

          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.

              Paul H.NinjaTrader Customer Service

              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 nleitman, Today, 11:46 AM
                6 responses
                16 views
                0 likes
                Last Post nleitman  
                Started by cmtjoancolmenero, Today, 01:09 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by DanielRaz, Today, 12:54 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Russ Moreland, 04-24-2024, 12:54 PM
                2 responses
                18 views
                0 likes
                Last Post JosephDavidsona  
                Started by truepenny, Today, 03:45 AM
                5 responses
                27 views
                0 likes
                Last Post NinjaTrader_RyanS  
                Working...
                X