Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Remove Draw Object troubles

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

    Remove Draw Object troubles

    Hello,
    I am trying to remove rectangles that I drew and for some reason I cannot remove them successfully. The following is a code snippet similar to my actual code and the output it generates. What am I doing wrong? Thank you.

    Code:
    public class RemoveDrawObjectTest : Indicator
        {
    
            public class RectRegion
            {
                public double high;
                public double low;
                public string tag;
            }
            public List<RectRegion> rect_l;
            SessionIterator sessionIterator;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                            = @"Enter the description for your new custom Indicator here.";
                    Name                                = "RemoveDrawObjectTest";
                    Calculate                            = Calculate.OnBarClose;
                    IsOverlay                            = false;
                    DisplayInDataBox                    = true;
                    DrawOnPricePanel                    = true;
                    DrawHorizontalGridLines                = true;
                    DrawVerticalGridLines                = true;
                    PaintPriceMarkers                    = true;
                    ScaleJustification                    = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive            = true;
                }
                else if (State == State.Configure)
                {
                    rect_l = new List<RectRegion>();
                }
                else if (State == State.Historical)
                {
                    sessionIterator = new SessionIterator(Bars);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (Bars.IsFirstBarOfSession)
                    sessionIterator.GetNextSession(Time[0], true);
    
                if (CurrentBar > 5)
                    return;
    
                // define some region
                RectRegion reg = new RectRegion();
                reg.high = GetCurrentAsk();
                reg.low = reg.high - 3 * TickSize;
                reg.tag = CurrentBar.ToString();
                // put it in the list
                rect_l.Insert(0, reg);
                // Draw the region
                Draw.Rectangle(this, reg.tag, Time[0], reg.low, sessionIterator.ActualSessionEnd, reg.high, true, "Default");
                // remove old elements
                int n = rect_l.Count;
                if (n > 3)
                {
                    RemoveDrawObject(rect_l[n - 1].tag);
                     Print("rect_l.Count: " + n + "   DrawDrawObjects.Count: " +  DrawObjects.Count + "    tag: " + rect_l[n - 1].tag);
                    foreach (var item in DrawObjects)
                        Print(DrawObjects[item.Tag].Tag);
                    rect_l.RemoveAt(n - 1);
                }
            }
        }
    Output:

    rect_l.Count: 4 DrawDrawObjects.Count: 4 tag: 0
    @0
    @1
    @2
    @3
    rect_l.Count: 4 DrawDrawObjects.Count: 5 tag: 1
    @0
    @1
    @2
    @3
    @4
    rect_l.Count: 4 DrawDrawObjects.Count: 6 tag: 2
    @0
    @1
    @2
    @3
    @4
    @5
    Last edited by nedlloyd; 03-16-2016, 06:47 AM.

    #2
    Hello nedlloyd,

    Thank you for your post.

    Can you attach the .cs file or the exported source file from NinjaTrader to your response?

    Comment


      #3
      Here you go, Patrick. Thank you.
      Attached Files

      Comment


        #4
        Hello nedlloyd,

        Are you trying to remove all drawn objects? Or just any over three objects?

        Comment


          #5
          In the actual application, I want to remove SPECIFIC objects, which is why I am saving the tags. I just wrote this code to show that the objects are not being removed after the call to RemoveDrawObject.

          Comment


            #6
            Patrick,
            I changed the code to use 'bool isGlobal = false' in the call to Draw.Rectangle() and I believe it works. Is there a way to remove the objects once they are global? Interestingly, the objects on the chart are removed as expected, but the output is still:

            rect_l.Count: 4 DrawDrawObjects.Count: 4 tag: 0
            0
            1
            2
            3
            rect_l.Count: 4 DrawDrawObjects.Count: 5 tag: 1
            0
            1
            2
            3
            4
            rect_l.Count: 4 DrawDrawObjects.Count: 6 tag: 2
            0
            1
            2
            3
            4
            5

            Not sure why the object count is 6 when there are only 3 objects on the chart.

            Comment


              #7
              So, is there a way to remove draw objects if they are global?

              Comment


                #8
                Hello nedlloyd,

                Thank you for your patience.

                I see this with objects that are not global. I am looking into this further. When we have further information I will update this thread.

                Comment


                  #9
                  Patrick,
                  Any updates on this? Thank you.

                  Comment


                    #10
                    Hello nedlloyd,

                    Thank you for your note.

                    This is expected for resolution in the next beta release.

                    Comment


                      #11
                      Hi Patrick.

                      Was this ever resolved? I still can't remove objects when isGlobal = true;

                      Comment


                        #12
                        Hello trader3419,

                        Thank you for your response.

                        This would have been resolved as of Beta 11. Can you advise which Beta version you are running? This will be found under Help > About in the Control Center.

                        In addition, can you attach the code you are using to your response?

                        Comment


                          #13
                          I am on version 11.
                          I have been in contact with Jesse on this post.

                          Comment


                            #14
                            Hello trader3419,

                            Thank you for your response.

                            Can you upgrade to release 13 of NinjaTrader 8?
                            You can do so from the following link: http://ninjatrader.com/support/helpG...en-us/beta.htm

                            Comment


                              #15
                              I am on version 13. Sorry I mistyped. I have always been on version 13.
                              Please look into this issue as it is keeping me from releasing my product.

                              Comment

                              Latest Posts

                              Collapse

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