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

calling RemoveDrawObject from custom object

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

    calling RemoveDrawObject from custom object

    Hi,

    I want to call the RemoveDrawObject method from my class which does not have the Indicator object passed to it. I have the NinjaScriptBase passed, but unfortunately the method is unreachable from that object. Is there any other way my class can use that method without using an Indicator object passed to it?

    I want my classes to be able to be used by both Indicators and Strategies so that is why I am not using the Indicator object and instead using the NinjaScriptBase object.

    I am assuming I cant pass an Indicator Object to a custom class in a strategy, Is that correct? I figure I must pass a NinjaScriptBase object.
    Last edited by KhaosTrader; 12-06-2016, 02:52 PM.

    #2
    Hello KhaosTrader, and thank you for your question.

    It is possible to access Global drawing objects through code. This sample, which must be run from an Indicator (but any indicator, not necessarily the one that drew the object), demonstrates how.

    Code:
    [FONT=Courier New]
          string basetag = "MyLine";
          string globtag = "@" + basetag;
          bool tagIsGlobal = DrawObjects.FirstOrDefault(d => d.Tag.Contains("@")) != null;
          string tag = tagIsGlobal ? globtag : basetag;
    
                if(DrawObjects.Count > 0)
                {
            Print("Removing DrawObjects[\"" + tag + "\"]");
                    RemoveDrawObject(tag);
                }
                else
          {
                    Draw.HorizontalLine(this, "MyLine", High[0], true /* try making this false, it will continue to work */, "");
          }[/FONT]
    Beyond this, NinjaTrader 8 is a multi-threaded application and, as such, there is no thread safe global context where handles to every indicator are located. Because of this, there is also no thread safe global context where you can access every drawn element.

    You can code your indicator using static global methods, sending in a class object containing an external callback method which will be called by your indicator, and in so doing have a thread safe and asynchronous way to pass messages back and forth between your calling class and your indicator. Your indicator will still be responsible for removing its own drawing objects, but you will have more control over how this happens from the outside. Doing so is an exercise for the programmer, but all the language used in this post is commonly used and searchable.

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Ok, Is there a way to access the draw objects from a strategy? Or is it just from an indicator? If you haev an example of the external callback method that would be great, or somewhere where i can read about how to do that.

      Thank you for your continued patience and support

      Comment


        #4
        Where I said Indicator earlier I should have said any NinjaScript object. Drawing objects are organized in the Help Guide under the common section, and the common section itself includes this excerpt.

        Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/common.htm
        The following section documents methods and properties available to every NinjaScript type that access various forms of data including bar data, price data, and statistical forms of data. The Common section is broken into several categories pertaining to distinct NinjaScript objects or concepts. An index of topics under the Common section can be found below:
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          If I have an object that uses the NinjaScriptBase class, this cant delete objects. However, if that object instantiates an Indicator object, can that object delete drawings? I tried this and was unsuccessful, but it didnt throw errors, so I am not sure if I did it incorrectly or what.

          Comment


            #6
            This is related to this thread,



            I have put in the same feature request with respect to this thread.
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Hello KhaosTrader,

              This feature is being reviewed by the product management team and has been assigned the following unique tracking ID


              SFT-1793


              Please let us know if there is any other way we can help.
              Jessica P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,265 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X