Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Removing plots

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

    Removing plots

    Hi,
    I have a strategy where i have a button, which includes the following code.
    It is supposed to remove certain DrawObjects.
    foreach(IDrawObject draw in DrawObjects)
    {
    if(draw.Tag.StartsWith("Name"))
    {
    Print(draw.Tag);
    // RemoveDrawObject(draw.Tag);
    }
    ChartControl.ChartPanel.Refresh();
    }

    if I run the code like that without the RemoveDrawObject statement, it prints all the desired DrawObjects to the Output Window.
    If I uncomment the RemoveDrawObject statement,
    it prints only one tag and removes only one Object.
    Why does the code not remove all objects which were printed to the Output window, when the statement was commented out?

    #2
    Hello Keepsimple,

    Thank you for your note.

    You might be getting an Object handling error in either the Log tab or the Trace file.

    You can check the Trace file which is located in (My) Documents -> NinjaTrader 7 -> Trace

    You will see a line with **************** Handled Exception trapped************

    You can also send me the file to platformsupport [at] ninjatrader [dot] com
    Put ATTN Cal in the subject and reference this thread in the body
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      ys, think you are right, here is the log.

      2014-10-14 15:36:02:823 in OnUnhandledThreadException
      2014-10-14 15:36:02:823 *************** unhandled exception trapped ***************
      2014-10-14 15:36:02:823 Die Auflistung wurde geändert. Der Enumerationsvorgang kann möglicherweise nicht ausgeführt werden.
      2014-10-14 15:36:02:823 bei System.Collections.Hashtable.HashtableEnumerator.M oveNext()
      bei NinjaTrader.Gui.Chart.DrawObjectsEnumerator.MoveNe xt()
      bei NinjaTrader.Strategy.MyOFTBeta01.Split_Click(Objec t sender, EventArgs e)
      bei System.Windows.Forms.ToolStripItem.RaiseEvent(Obje ct key, EventArgs e)
      bei System.Windows.Forms.ToolStripButton.OnClick(Event Args e)
      bei System.Windows.Forms.ToolStripItem.HandleClick(Eve ntArgs e)
      bei System.Windows.Forms.ToolStripItem.HandleMouseUp(M ouseEventArgs e)
      bei System.Windows.Forms.ToolStripItem.FireEventIntera ctive(EventArgs e, ToolStripItemEventType met)
      bei System.Windows.Forms.ToolStripItem.FireEvent(Event Args e, ToolStripItemEventType met)
      bei System.Windows.Forms.ToolStrip.OnMouseUp(MouseEven tArgs mea)
      bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
      bei System.Windows.Forms.Control.WndProc(Message& m)
      bei System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
      bei System.Windows.Forms.ToolStrip.WndProc(Message& m)
      bei System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
      bei System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
      bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

      Do not know, what causes the error.

      Comment


        #4
        Keepsimple,

        What is occuring is the foreach is getting the number of objects in the collection of DrawObjects, but since we are removing an object from that collection we get the enumeration error.

        You will need to convert the foreach over to a for loop. This should work around the enumeration error that you are getting.

        for(int i = 0; i < DrawObjects.Count; i++)
        {

        }

        Let me know if I can be of further assistance.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Thanks,

          yes that might work, but how do I acces the DrawObject to remove then?

          RemoveDrawObject(???????), what do I put in the brackets?

          Comment


            #6
            Keepsimple,

            You would want to use the same logic but slightly modified -

            Code:
            for(int i = 0; i < DrawObjects.Count; i++)
            {
                 if(DrawObjects[i].Tag.StartsWith("Name"))
                 { 
                      Print(DrawObjects[i].Tag);
                      RemoveDrawObject(DrawObjects[i].Tag);
                 }
                 ChartControl.ChartPanel.Refresh();
            }
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Hi Cal,

              thought about something like that.
              I copied and pasted your code.
              But unfortunately it does not compile.
              I get several error messages,
              1. int cannot be converted into string
              2. this[string] method has invalid arguments

              Really appreciate your help, which was great so far.

              Comment


                #8
                Keepsimple,

                Can you please give me a visual of those compile error messages or attach your script so that I can look into it?
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  see Attachment
                  Attached Files

                  Comment


                    #10
                    Keepsimple,

                    Can you send me the script so that I can test this on my end?
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Cal,

                      for your help, which was really great.

                      Solved the problem.

                      Regards

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      576 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      334 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
                      553 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      551 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X