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

After DrawLine() what is the selected object?

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

    After DrawLine() what is the selected object?

    Hi,

    After I have drawn several objects on the chart such as using DrawLine(), and the user clicks on one of the lines to select it, how do get the tag of the selected object? Is it part of IDrawObject?

    Thanks,
    Will.

    #2
    That's correct Will, the identification would be done over the tag id - https://www.ninjatrader.com/support/...rawobjects.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks I had missed that information.

      Still, I haven't been able to work out firstly how to identify if an object is selected, and then how to delete it. Correction... I guess RemoveDrawObject() would delete it, so I just need to know how to identify the selection.

      Thanks,
      will.
      Last edited by dontpanic; 07-02-2014, 04:23 PM.

      Comment


        #4
        Originally posted by dontpanic View Post
        Thanks I had missed that information.

        Still, I haven't been able to work out firstly how to identify if an object is selected, and then how to delete it. Correction... I guess RemoveDrawObject() would delete it, so I just need to know how to identify the selection.

        Thanks,
        will.
        You would have to use unsupported direct C# mouse methods.

        Comment


          #5
          Hi Koganam,

          Mouse Methods? Can you give me more of a hint?

          Are you suggesting that I write a method that detects whether my mouse click is in the 'zone' of any part of my draw object? If thats the case that would mean writing a different method for every type of draw object, and for objects like circles, arcs etc that could be very complicated.

          Surely there would be a 'selected' property or method somewhere, after all some part of NT has to know that the object is selected so that it can draw the selection corners?

          Will.

          Comment


            #6
            Originally posted by dontpanic View Post
            Hi Koganam,

            Mouse Methods? Can you give me more of a hint?

            Are you suggesting that I write a method that detects whether my mouse click is in the 'zone' of any part of my draw object? If thats the case that would mean writing a different method for every type of draw object, and for objects like circles, arcs etc that could be very complicated.
            Pretty much.
            Surely there would be a 'selected' property or method somewhere, after all some part of NT has to know that the object is selected so that it can draw the selection corners?

            Will.
            That is buried deep in the core of NT, not exposed.

            Comment


              #7
              Delete manually a selected draw object from the chart.

              Originally posted by dontpanic View Post
              Hi,

              After I have drawn several objects on the chart such as using DrawLine(), and the user clicks on one of the lines to select it, how do get the tag of the selected object? Is it part of IDrawObject?

              Thanks,
              Will.

              This is the code how I do it and it works perfect - I check if the selected object is either Line or Text. The others remain - I need it like this in my code. You can remove the switch and execute the code in the case section.

              Code:
              public void deleteSelectedObject()
              {
                          Type chartControlType = typeof(ChartControl);
                          FieldInfo fi = chartControlType.GetField("selectedObject", BindingFlags.NonPublic | BindingFlags.Instance);
                          if ( fi != null )
                          {
                              if ( fi.GetValue(ChartControl) != null )
                              {
                                  // an object is selected!
                                  IDrawObject clickedObject = (IDrawObject) fi.GetValue(ChartControl);
                                  switch ( clickedObject.DrawType )
                                  {
                                      case DrawType.Line:
                                      case DrawType.Text:
                                          RemoveDrawObject(clickedObject);
                                          break;
                                  }
                                  Print("Deleted Type=" + clickedObject.DrawType.ToString() + " Tag=" + clickedObject.Tag);
                                  // I have to notify NinjaTrader that the object has been removed otherwise it remains in NTs internal structure!
                                  ChartControl.ChartPanel.Focus();
                                  SendKeys.Send("{ESC}");
                                  ChartControl.Invalidate();
                                  ChartControl.Refresh();
                              }
                          }
              }
              Remember: There is no other way to delete a draw object from the chart which has been added by an indicator. When you try to delete it you receive the message that the indicator, which created the draw object, will be removed as well. You can delete with this method only draw objects created by the indicator which is running the above code.

              Also consider with this method you cannot delete a selected manual draw object!

              Comment


                #8
                Originally posted by AlBundy View Post
                Remember: There is no other way to delete a draw object from the chart which has been added by an indicator. When you try to delete it you receive the message that the indicator, which created the draw object, will be removed as well. You can delete with this method only draw objects created by the indicator which is running the above code.

                Also consider with this method you cannot delete a selected manual draw object!
                Thank you for your post.
                What about this solution: AllowRemovalOfDrawObjects


                // Initialize method of a custom indicator
                protected override void Initialize()
                {
                Add(new Plot(Color.Orange, "SMA"));
                AllowRemovalOfDrawObjects = true; // Draw objects can be removed separately from the script
                }
                Alternatively, you can set the "Locked" property of the draw object to False to enable manual change / removal of the object. For example:

                ChartLine line = (ChartLine)DrawLine(...);
                line.Locked = false;
                Last edited by ninZa; 02-21-2015, 10:17 PM.
                ninZa
                NinjaTrader Ecosystem Vendor - ninZa.co

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by AlgoDreamer, Today, 12:39 PM
                2 responses
                8 views
                0 likes
                Last Post AlgoDreamer  
                Started by ninza33, Today, 12:31 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by nleitman, Yesterday, 11:46 AM
                17 responses
                45 views
                0 likes
                Last Post nleitman  
                Started by tradingnasdaqprueba, Today, 03:42 AM
                7 responses
                32 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by kaywai, Today, 11:59 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Erick  
                Working...
                X