Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using a Custom Drawing Tool from an indicator or from another Custom Drawing Tool

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

    Using a Custom Drawing Tool from an indicator or from another Custom Drawing Tool

    I have created a handful of custom drawing tools (love the new NT8 abilities!) and I would like to create an indicator that draws my new, custom drawing tool (similar to how you can draw a "line" within an indicator). Is this possible?

    Similarly, I'd like to output my custom drawing tool from another custom drawing tool.

    I see that "Draw" and "RenderTarget" don't seem to include my new tools, so perhaps this isn't the right place?

    I feel like this is obvious, but I can't seem to find it.

    Any help is greatly appreciated!

    #2
    Hello neoikon,

    Thanks for your post.

    You might look at the various tools code for an example of the overloads used to call it. These are located in the public static partial class Draw.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks again for pointing me in the right direction. I see how I wasn't defining the type and public calls in the Draw "partial class".

      However, owner is causing me an issue. Typically, a drawing object is called by an indicator (or is on the chart itself), so the owner is of type "NinjaScriptBase". However, if I have a "custom drawing object" calling another "custom drawing object", the owner of the 2nd object isn't of NinjaScriptBase (correct?). So, I am running into a roadblock on how to actually define/make the calls.

      Perhaps I need to set the owner of the 2nd drawing object as the 1st drawing object's owner (as opposed to the 1st object itself)? One, how do I get the owner (this.DrawnBy isn't working for me), and two, will this cause an issue when the first drawing tool is destroyed (add handling in Dispose()?)?

      (This may be confusing, so let me know if I don't explain this very well (or if I don't understand what I'm talking about))

      Maybe a more simple question would be, "How do I call Draw.Line() from my custom drawing object?" (Within OnRender(), I imagine.) If I knew the answer to that, it may sort everything out for me.

      If I set the owner as "this.DrawnBy", it compiles, but throws a runtime error that simply says "owner" (due to it being null, I believe).
      Last edited by neoikon; 03-09-2016, 01:34 PM.

      Comment


        #4
        Hello,

        In the case you want to chain a drawing tool which creates other drawing tools, you have noted the main problem which is passing the owner.

        I have created a sample of this concept and also a video as it is fairly complicated to understand until you have moved through it once.

        The main item to take from this sample/video is that the instance of the owner would need to be passed using the static partial class Draw, otherwise there is no instance for the owner.

        Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.



        As for issues related to this, I am actually not sure what stipulations surround this as this is both undocumented and appears that none of the other tools utilize this process so there certainly could be problems.

        If you are trying to use the built in drawing tools, I might suggest instead of daisy chaining multiple tools together, to instead just write all required logic into that tool specifically. What I mean by this is if you need to draw lines from this tool, add code to draw lines using its OnRender instead of calling an entirely different tool from OnRender which may have a much larger performance impact.



        I look forward to being of further assistance.
        Attached Files
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you so much for the detailed reply!

          In my situation, the drawing tools are pretty complicated, so I'm hoping to not integrate/duplicate the functionality within each other. "Daisy Chaining" them really seems like the best option for me. Also from a usability sense, I want to define a template for the 2nd drawing tool and have the user specify that template in the 1st drawing tool.

          The logic you gave in the video makes perfect sense and I've added the logic within my code (for both of my custom drawing tools involved).

          Unfortunately, I'm seeing that "myOwner" is still null. I'm creating the 1st drawing tool from the "Drawing Tool" drop down on the chart (and not from an Indicator), so could that be the reason?

          I don't think that "MyCustomDrawingToolCore" is being called when the tool is created from the chart, correct? (if it should be called, then perhaps I have a bug in my code).

          In the context of being instantiated from a chart, is there something I can grab as the owner in that situation? Something in the ChartControl (or some other object), for example? Something I can cast as NinjaScriptBase?
          Last edited by neoikon; 03-10-2016, 11:03 AM.

          Comment


            #6
            Hello,

            Thank you for the reply.

            Yes this example deals specifically with calling by code, I am unsure of a way for this to work currently by manually drawing it.

            I will need to review if that would be possible using the user interface to accomplish the same task. Being that the Draw class was added specifically for NinjaScript to access the drawing tools and to allow custom implementations, the user interface may not use the same paths as a indicator would.

            Once I have further information on this I will reply back.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks for looking into this for me! Yes, this is really an important feature for me and my products (I'm a NT partner, FWIW).

              I will keep digging as well to see if there is something that I am missing or perhaps another workaround.

              EDIT: It seems the main tasks of the "Core" are setting the start/end anchors, the anchor line stroke, set active state, and then "SetDrawingToolCommonValues" (not sure what's going on in there).

              If an object is created from the "Drawing Tool drop down" and it doesn't have an "owner", then there must be a way to create the object, correct? Perhaps DrawingTool.TryLoadFromTemplate()?

              Perhaps, without an "owner", I could create a constructor that simply passes in the start/end ChartAnchors? I would need to create an empty CustomDrawingTool object.

              Perhaps doing something like this:

              PHP Code:

              ...

              CustomDrawingTool myCustomDrawingTool DrawingTool.TryLoadFromTemplate(typeof(CustomDrawingTool), "Default") as CustomDrawingTool;

              myCustomDrawingTool.Tag tag;
              myCustomDrawingTool.IsAutoScale isAutoScale;
              myCustomDrawingTool.IsLocked true;
              //??? More??? Anything Render related?

              startAnchor.CopyDataValues(myCustomDrawingTool.StartAnchor);
              endAnchor.CopyDataValues(myCustomDrawingTool.EndAnchor);

              ... 
              I can get that to run without exception, but nothing appears on the chart.

              It comes down to what is called instead of DrawingTool.GetByTagOrNew() by the chart's "Drawing Tool drop down" (for lack of a better term)
              Last edited by neoikon; 03-11-2016, 07:53 AM.

              Comment


                #8
                Hello,

                I wanted to reply back on this item.

                After further review with development on the topic of creating a drawing object in the same way that you would from the user interface, it looks like this is currently not exposed in a way that would make this feasible.

                It has been added to a list of items for review to be further exposed potentially. Unfortunately at the moment, using the static Draw methods you implement into the script would be the only correct way to call the tool from NinjaScript but would require an owner.

                In the case of manually drawing the tools, you are not utilizing the custom overload sets in the static draw methods so a different path is taken. Chaining tools together like this would currently only be possible from NinjaScript specifically it seems.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by f.saeidi, Today, 12:14 PM
                7 responses
                16 views
                0 likes
                Last Post f.saeidi  
                Started by Russ Moreland, Today, 12:54 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by philmg, Today, 12:55 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChristopherJ  
                Started by TradeForge, 04-19-2024, 02:09 AM
                2 responses
                32 views
                0 likes
                Last Post TradeForge  
                Started by aprilfool, 12-03-2022, 03:01 PM
                3 responses
                329 views
                0 likes
                Last Post NinjaTrader_Adrian  
                Working...
                X