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

Add Custom DrawingTool to chart from Indicator

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

    Add Custom DrawingTool to chart from Indicator

    Hello

    I want to make an indicator that adds ray cast price lines and price regions into the future. When price trades back to them I can click on or hover over the line or region it will displays a popup text box with more info about the line or region.

    So I made a custom drawing tool that extends Line take advantage of its OnMouseDown/Up callbacks and its IsSelected behaviour for the text box pop up. The tool creates lines and regions with working pop ups as desired by hand.

    But I can't figure out what is the correct way to instantiate a DrawingTool instances from an Indicator?
    (Current efforts either CustomDrawingTool.OnRender doesn't get called, or if I use the Indicator.OnRender method to call all the CustomDrawingTools OnRender methods they have no RenderTargets set.)

    Or If I headed down a dead end with DrawingTool, what is the correct way to have an Indicator add drawing objects that have mouse interactivity?

    Thanks





    #2
    Not sure what you look for, but you can go to the ecosystem there to look for it :

    Comment


      #3
      Hello SmartArtsStudio,

      Thank you for your post.

      You could look at the built in Drawing Tool tile indicator which invokes a pen to draw the selected tool with the following:

      ChartControl.TryStartDrawing(dt.GetType().FullName );

      You can also add overloads to your custom drawing tool that will allow the tool to be drawn from a NinjaScript. You can look at existing drawing tools for examples of this. To elaborate on the NinjaScript overloads which allow the DrawingTool to be used in indicators, this involves public static methods which are included in the DrawingTool. For the Lines DrawingTool script, this code is located after line 704.

      Please let us know if we may be of further assistance to you.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        Thanks Kate

        Phew, glade i don't have to start over. TryStartDrawing enacts the tool for manual use so its going to be overloading. (But handy to know about because its not documented.)

        Could you update the following code sample if I am on the wrong path. Partial class overloading a class like this is new to me.
        I can't get my head around it as everything else in the Draw partial class is private?

        When I call Draw.SmartLine() cast the indicator as Line.

        Thanks in advance.

        Code:
        namespace NinjaTrader.NinjaScript.DrawingTools.SmArt {
        
            public partial class SmartLineTool : Line {
                // add properties
        
                // add methods
        
                protected override void OnStateChange() {
                    base.OnStateChange();
        
                    if (State == State.SetDefaults) {
                        LineType = ChartLineType.Line;
                        Name = "SmartLineTool";
                   }
        
                  if (State == State.Configure) {
        
                      // do constructor stuff
                  }
               }
        
             public static partial class Draw {
        
                  public static Line SmartLine( NinjaScriptBase owner, bool isAutoScale, string tag, int startBarsAgo, DateTime startTime, double startY, int endBarsAgo, DateTime endTime,
                                                                                  double endY, Brush brush, DashStyleHelper dashStyle, int width ) {
        
                       // Just assume I have a matching signature, as this is what my IDE is giving me grief over
                       return  DrawingTools.Draw.Line(owner, isAutoScale, tag, startBarsAgo, startTime, startY, endBarsAgo, endTime, endY, brush, dashStyle, width, false, null);
                 }
             }
        }
        Last edited by SmartArtsStudio; 05-20-2021, 02:43 PM.

        Comment


          #5
          Hello SmartArtsStudio,

          Thank you for your reply.

          I'd advise taking a look at this publicly available drawing tool add on that creates labeled lines (extending the existing Line tools) from our User App Share:

          https://ninjatraderecosystem.com/use...-drawing-tool/

          We wouldn't recommend using a partial class to expand on a drawing tool. The above drawing tool add on inherits from Line in LabeledLines, and implements NS overloads, that may help give you some further direction.

          Please let us know if we may be of further assistance to you.

          The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Hello Kate

            Thank you! You had me at "Its possible" ...but that file reference is excellent for multiple reasons.
            C# not my strongest language I had mistaken partial classes for vertical inheritance not composition,
            To duplicate so much code I would have totally thought I was doing it wrong.

            I really appreciate your help.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Christopher_R, Today, 12:29 AM
            0 responses
            10 views
            0 likes
            Last Post Christopher_R  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            166 responses
            2,235 views
            0 likes
            Last Post sidlercom80  
            Started by thread, Yesterday, 11:58 PM
            0 responses
            3 views
            0 likes
            Last Post thread
            by thread
             
            Started by jclose, Yesterday, 09:37 PM
            0 responses
            8 views
            0 likes
            Last Post jclose
            by jclose
             
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            10 responses
            1,415 views
            0 likes
            Last Post Traderontheroad  
            Working...
            X