• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RemoveDrawObject

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

    RemoveDrawObject

    I want to call RemoveDrawObject from a class instance and can't find a reference to the method. I think it's currently only available in the Indicator class and not available to user classes. Can you provide the way that I can call this from my custom class. I've got the object ID's and need to update/remove drawings realtime.

    Thanks

    #2
    Hello dtl-saw,

    RemoveDrawObject(s) is available to Indicators and to Strategies (where drawing objects can be created from).
    http://ninjatrader.com/support/helpG...drawobject.htm
    http://ninjatrader.com/support/helpG...rawobjects.htm

    What kind of script are you attempting to call this from?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      I have an indicator that uses an instance of a custom class I created to draw many different objects on the chart.
      In the custom class I use the Draw.Line and Draw.Text methods to place drawing objects on the chart.
      For every object drawn on the chart I create and store a unique drawing ID that is also stored in the custom class.
      If one of the drawing objects becomes irrelevant to the current price action I want to delete it from the chart.
      Currently during the custom class instantiation I'm passing in references to ChartControl, ChartBars, and IndicatorBase.
      These references give me everything I need to place the drawings on the chart, but I can't see how to remove a drawing object once created.

      Since I'm using the custom class to create the drawing objects on the chart I also want to use the custom class to delete the drawing objects on the chart. This keeps all the code nice and tidy from an organizational viewpoint. Also, I'm not a pro software developer so I'm not sure what the pros are doing but I doubt they're writing 5000 lines of code in the "protected override void OnBarUpdate()" section of the indicator script.


      Thanks for your help
      Last edited by dtl-saw; 08-01-2016, 12:23 PM. Reason: additional info

      Comment


        #4
        Hello dtl-saw,

        Using your own custom class that is within the class of the indicator and I would expect this to still work. If this class is outside of the class of the indicator, this would be outside of the realm of support, but I would recommend you pass the existing instance of the indicator to your class, and use the instance of the indicator to call RemoveDrawObject().
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks,
          The class is currently outside of the class of the indicator. Could you give a code snippet of how to pass the indicator instance to the class? I'm already passing "this" as type IndicatorBase to the class in order to get to the Draw.Line method.

          Comment


            #6
            Hello dtl-saw,

            Using a custom class this way is outside of the realm of what is supported by NinjaTrader support.

            This thread will remain open for any community members that would like to provide you with an example.

            However, the gist is, make a public variable in your custom class that is the same type as the indicator being passed.

            Then when constructing the new class from the indicator, set the variable to this.

            CustomClass myCustomClassVar = new CustomClass()
            {
            SMA = this;
            }

            You can also contact one of our professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              okay, got it working now.
              Thanks for your help Chelsea.

              Comment


                #8
                Solution?

                @dtl-saw

                Would you mind explaining how you were able to solve this problem? I have run into the same issue. I've not been able to access IndicatorBase.RemoveDrawObjects() even though other base methods are working in my custom class.

                Thanks!

                Comment


                  #9
                  solution

                  Here's an example of stripped down code to show just the parts you are interested in.
                  It worked for me back in August, but I had to dig this version out of repository and haven't used this approach for awhile -- so, I didn't test this to make sure it still works. Let me know if you have problems.



                  namespace NinjaTrader.NinjaScript.Indicators
                  {
                  public class TradeSeries
                  {
                  public WeeklySetups mainClass { get; set; } // handle to indicator so that methods like RemoveDrawObject() can be called

                  public TradeSeries(IndicatorBase myIndi, WeeklySetups ws, ChartControl cc, ChartBars cb, string iFile )
                  {
                  mainClass = ws;

                  foreach (Trade x in SeriesOfTrades)
                  {
                  if (x.TradeID == 56)
                  {
                  mainClass.RemoveDrawObject(x.TradeDrawingsID[0].ToString());
                  NinjaTrader.Code.Output.Process("Remove called with = " + x.TradeDrawingsID[0].ToString() + "\n", PrintTo.OutputTab1);
                  }
                  }
                  }
                  }

                  public class WeeklySetups : Indicator
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"weekly trade setups";
                  Name = "WeeklySetups";
                  ...
                  }
                  else if (State == State.Configure)
                  {
                  }
                  else if (State == State.Realtime)
                  {
                  TradeSeries LongTradeSeries = new TradeSeries(this, this, ChartControl, ChartBars, inFile);
                  }
                  }
                  }

                  Comment


                    #10
                    Thanks dtl-saw, I appreciate it!

                    I'll let you know if I run into anything.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bztynbzp, Yesterday, 11:17 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post bztynbzp  
                    Started by Dan_D_Trader, Yesterday, 03:49 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post Dan_D_Trader  
                    Started by JohnAymin, Yesterday, 02:38 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Tyler  
                    Started by Rmos22, Yesterday, 02:20 PM
                    2 responses
                    23 views
                    0 likes
                    Last Post Rmos22
                    by Rmos22
                     
                    Started by sawtooth500, Yesterday, 12:59 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Spencer  
                    Working...
                    X