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

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 bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,603 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X