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

New AddOn: Add tool tips to drawing objects

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

    New AddOn: Add tool tips to drawing objects

    Usage

    This add-on adds three methods to the drawing objects. The methods are SetToolTipText (string), SetToolTipContent (object), and SetToolTipContentFactory (Func<object>). You only need to call one of these methods in order to apply your tooltip. The one you use will depend on your scenario.

    Scenario One

    In the simple case, you can use the SetToolTipText method to display a simple string.

    Code:
    var drawing = Draw.Dot(...);
    drawing.SetToolTipText("Hello, world!");
    Or:

    Code:
    Draw.Dot(...).SetToolTipText("Hello, world!");
    Scenario Two

    To display controls on a few objects, you can use the SetToolTipContent method to provide your element tree.

    Code:
    var drawing = Draw.Dot(...);
    var button = new Button { Content = "Hello" };
    button.Click += (_, __) => button.Content = "World";
    drawing.SetToolTipContent(button);
    Most likely, you will be calling this from the OnBarUpdate method. If this is the case, there will be an exception thrown because this method is not necessarily being called from the UI thread. I've included a method on Indicator that helps with this (You can add a similar one to Strategy if needed). The resulting code to do the above would be:

    Code:
    var drawing = Draw.Dot(...);
    Dispatch(() =>
        {
            var button = new Button { Content = "Hello" };
            button.Click += (_, __) => button.Content = "World";
            drawing.SetToolTipContent(button);
        });
    Scenario Three

    To display controls on many objects, you can use the SetToolTipContentFactory method to provide your element tree. The method you provide will be called only when the tooltip is shown. After the tooltip is hidden, the object instance you returned from the factory will be eligible for garbage collection.

    If you are creating custom tooltips for many drawing objects, it is recommended that you use this method since it will use the least amount of memory. Keep in mind that the function you provide can be called zero or many times.

    Code:
    var drawing = Draw.Dot(...);
    drawing.SetToolTipContentFactory(() =>
        {
            var button = new Button { Content = "Hello" };
            button.Click += (_, __) => button.Content = "World";
            return button;
        });
    Installation:

    Place the attached file in the AddOns folder.

    NOTES:
    • A new menu item under the Tools menu allows enabling/disabling. It does not work properly, however, after compiling. Will look for a workaround
    • After compiling, the chart will need to be refreshed for existing tooltips to show. This is because the tooltips are not stored on the drawings themselves
    • Be aware of captures when using lambdas. Assign indicator properties to local variables and use the local variables in the lambdas.
    • There are several classes in the file. They can be put into their own files is desired
    • I'm using .Net 4.7 but I believe I've used only 4.5 features in this file. If it doesn't compile for you, let me know and I will fix it
    Attached Files

    #2
    I really like all the possibilities this can open, but my knowledge in C# is limited, i am self taught so I get lost in some basic stuff. Can anybody throw a simple indicator on how to use this addon. Not sure how to make it work. Thank in advance.

    I try this without success:

    Draw.Square(this,"MySquare" + CurrentBar, true, 0, High[0] + 2 * TickSize, Brushes.Red).SetToolTipText("My Text");

    It doesn't compile.

    Comment


      #3
      Hi PrTester,

      Post the compilation error and I'll have a look.

      I take it the AddOn compiled with no problems?

      Wil

      Comment


        #4
        BTW: Make sure you've added "using NinjaTrader.Custom.AddOns" to your indicator.

        Comment


          #5
          Everything is working now, it was a long night, nothing a computer and NT re-start with a new day cannot fix. I will continue play with, but work as describe and better. Thanks, great addition.

          Comment


            #6
            Good to hear. Hope everything works out for you.

            Comment


              #7
              Hey. Thanks for the add-on. It is possible to finish for objects SharpDX.Direct2D1. Thank you.

              Comment


                #8
                Hi Arkadiy_B,

                I do not understand what you are asking for.

                Comment


                  #9
                  Hey.
                  I tried to use your add-on in my indicator. I have an OnRender method. in which I put on chart graphic objects created with the help of
                  RenderTarget.FillEllipse(new SharpDX.Direct2D1.Ellipse(new SharpDX.Vector2(x, y), size, size), brushDX);
                  I would like to attach a tooltrip here

                  Comment


                    #10
                    Okay. I see.

                    This is a totally different animal. What you are doing is just rendering, there is no underlying object instance being created to which you can attach/monitor.

                    You have two options:
                    1. Change your design so you are creating actual objects (using Draw.XXX methods)
                    2. Create a collection to keep track of the objects you are rendering (or just their bounds and tool tip) and implement the tool tip functionality


                    The first method is easier.

                    Comment


                      #11
                      Nice work wbennettjr.
                      Is it possible to set delay for the tooltip, etc
                      I am an intermediate coder so I have tried the usual setdelay etc but it doesn't work

                      Edit
                      Also it doesn't seem to work on DrawPlus the new enhanced drawing tool from Ninja??
                      My guess is it needs a new static call? But as I say my knowledge is intermediate on these things.

                      Edit 2
                      It does work on ChartPLus - the using Custom AddOn needs to be added as per standard.
                      Last edited by Mindset; 06-21-2022, 05:15 AM.

                      Comment


                        #12
                        How do I import the file ToolTipAddOn.cs as it is not a NT8 addon .zip file. I am using NT 8.0.26.1.

                        I have also tried to overlay the contents of this onto a blank indicator and it gives compile errors.

                        Comment


                          #13
                          Hello trader-ap,

                          Thank you for your reply.

                          Although it is preferred that you have the original .zip file, you can import .cs files through the following instructions.
                          • Navigate to (My) Documents\NinjaTrader 8\bin\Custom\Addon. Copy the .CS File in this directory.
                          • Open NinjaTrader
                          • From the Control Center select the New menu--> select NinjaScript Editor
                          • Right click on the editor window and select Compile
                          Please let us know if we may be of further assistance.
                          Kate W.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by Mindset View Post
                            Nice work wbennettjr.
                            Also it doesn't seem to work on DrawPlus the new enhanced drawing tool from Ninja??
                            What is DrawPlus? Is this an official NT release?

                            Comment


                              #15
                              Originally posted by neoikon View Post

                              What is DrawPlus? Is this an official NT release?
                              Hello neoikon,

                              Thank you for your note.

                              I believe Mindset was referring to the DrawPlus() methods from the ChartMarkersPlus script available in the free NinjaTrader User App Share. This script is not officially from NinjaTrader, though it was developed by one of our past employees. This script is publicly available on our NinjaTrader Ecosystem website:Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

                              Note — To import NinjaScripts you will need the original .zip file.

                              To Import:
                              1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
                              2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
                              3. Select the downloaded .zip file
                              4. NinjaTrader will then confirm if the import has been successful.

                              Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

                              Once installed, you may add the indicator to a chart by:
                              • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK

                              Here is a short video demonstration of the import process:Please let me know if I can be of further assistance.

                              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.
                              Emily C.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by yertle, Today, 08:38 AM
                              3 responses
                              9 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
                              80 responses
                              19,667 views
                              5 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by adeelshahzad, Today, 03:54 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post adeelshahzad  
                              Started by dappa, Today, 09:18 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by bill2023, Yesterday, 08:51 AM
                              5 responses
                              25 views
                              0 likes
                              Last Post bltdavid  
                              Working...
                              X