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

Removing Historical Draw Objects

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

    Removing Historical Draw Objects

    Dear Support,

    This is a general question regarding removing history draw objects created by an indicator. For example the RSI will draw an object (an up or down arrow on price bars when price is above or below the 30 or 70 RSI levels. That leaves many arrows if price stays below or above these levels for a long time.

    The question is how to remove all the past signals and leave just the most recent draw object?

    Using the RemoveDrawObject("my Tag") under the OnBarUpdae and before a draw statement does not seem to work and leaves all past draw objects on the chart.

    Thanks.

    #2
    Hello,

    Thank you for the post.

    You are using the correct approach or using the RemoveDrawObject but the tag would need to be exactly the tag for the individual object which is very likely not going to be just "my Tag".

    If you are appending a drawing object it would need a unique tag name to allow more than 1 object to be drawn, you can check what they are being named by double clicking on one of the arrows. Its tag would likely be something like: "my Tag 145"

    You could either loop over the number of bars and remove objects using a prefix like:

    Code:
    for(int i = 0; i < 10; i++)
    {
        RemoveDrawObject("my Tag " + i);
    }
    This is just an example, you would need to modify this to use the correct tag prefix and also the number of bars to loop over.

    A more simple approach would be if you only need 1 object at a time, make the tag nonunique:

    Code:
    DrawArrowDown([B]"myTag"[/B], true, 0, High[0] + TickSize, Color.Blue);
    using a non-unique tag name would only allow one object to be drawn on the entire chart with this name.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse, I was using the long version of the draw statement for a specific tag name. Would have been nice if the help guide had a little explanation on specific vs non-specific draw objects, I did not know about this difference.

      All is well now.

      Many thanks.

      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for the post.

      You are using the correct approach or using the RemoveDrawObject but the tag would need to be exactly the tag for the individual object which is very likely not going to be just "my Tag".

      If you are appending a drawing object it would need a unique tag name to allow more than 1 object to be drawn, you can check what they are being named by double clicking on one of the arrows. Its tag would likely be something like: "my Tag 145"

      You could either loop over the number of bars and remove objects using a prefix like:

      Code:
      for(int i = 0; i < 10; i++)
      {
          RemoveDrawObject("my Tag " + i);
      }
      This is just an example, you would need to modify this to use the correct tag prefix and also the number of bars to loop over.

      A more simple approach would be if you only need 1 object at a time, make the tag nonunique:

      Code:
      DrawArrowDown([B]"myTag"[/B], true, 0, High[0] + TickSize, Color.Blue);
      using a non-unique tag name would only allow one object to be drawn on the entire chart with this name.

      I look forward to being of further assistance.

      Comment


        #4
        Hello

        I don't understand how loops work.

        protected override void OnBarUpdate()
        {
        if (BarsInProgress != 0)
        return;

        if (CurrentBars[0] < 1)
        return;

        // Set 1
        if (CrossAbove(Close, EMA1, 1))
        {
        Draw.Text(this,@"Test" + CurrentBar, @"V", 0, (Low[0] + (-10 * TickSize)) );
        }
        }

        For example, I want drawing objects in last 5 bars where conditions are met... The code would be this?

        for(int i = 0; i < 5; i++)
        {
        RemoveDrawObject("Test " + i);
        }

        But that does not work... All drawing objects remains. Where in the code these lines would be?

        Thanks

        Comment


          #5
          Hello Impeesa,

          Thanks for your post.

          Here is an external link to how C# loops work: https://www.programiz.com/csharp-programming/for-loop You can find almost any topic on C# programming with a search on the internet.

          Looking at your code example, the for-loop to remove draw objects would not work for a couple of reasons.

          The tag name of each object is "Test" plus the value of CurrentBar. CurrentBar is the systems bar counter which starts on the first bar of the data series and increments on each new bar processed. So you might see object names like Test23452, Test1223, etc. etc. In your for-loop you are only adding the counter "i"s value to the "Test" meaning you would see Test0, Test1, etc. etc. so these tag names likely would not exist and would not match up with what is on the chart.

          The other reason is that the loop is working with 5 consecutive numbers and even if these were legit bar numbers, the draw objects are not being drawn on the last 5 bars but are being drawn as/when the cross over conditions occur.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hello Paul

            I use +CurrentBar because I thought it was the only way that every signal would be drawn in the chart... What would be a better way to assigning tags of each object?
            Thanks

            Comment


              #7
              Hello Impeesa,

              Thanks for your reply.

              You can use any means you wish to create unique tag names. Using +CurrentBar is a convenient way to do so as it references an existing bar.

              You can create your own counter to count the objects as you draw them and then your for loop would work.

              For example at the class level create a counter like private int myCounter = 0;

              Each time you draw an object:
              if (my conditions to draw an object)
              {
              myCounter++; // increment the drawing counter first
              DrawText(this,@"Test" + myCounter, @"V", 0, (Low[0] + (-10 * TickSize)) );
              }


              To later remove draw objects:

              if (myCounter > 5 && your conditions tot remove the last 5 objects) // a safety check to ensure ytoyu have at least 5 drawn
              {
              for(int i = 1; i <= 5; i++)
              {
              RemoveDrawObject("Test " + i); // remove last 5
              }
              myCounter = myCounter - 5; // readjust counter since we removed 5
              }

              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Hello, Paul

                Loop works perfectly and it will be very useful in some codes I am working now.

                Thanks a lot for your patience with programming beginners like me. This forum is amazing.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by alifarahani, Today, 09:40 AM
                6 responses
                31 views
                0 likes
                Last Post alifarahani  
                Started by Waxavi, Today, 02:10 AM
                1 response
                17 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by Kaledus, Today, 01:29 PM
                5 responses
                13 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by Waxavi, Today, 02:00 AM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by gentlebenthebear, Today, 01:30 AM
                3 responses
                17 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X