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

Hack Alert: Show tooltip on drawing object (kinda sorta)

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

    Hack Alert: Show tooltip on drawing object (kinda sorta)

    There is a less intrusive and simpler version here: New AddOn: Add tool tips to drawing objects

    Background

    During indicator and strategy development, I often add a lot of texts and/or drawings to the chart in order to highlight conditions that are interesting. This makes it easier to spot/verify patterns and to flesh out different approaches.

    The problem with this approach is that, especially with texts, the charts slow down and there is only so much room on the chart before it becomes really cluttered and hard to read.

    Possible Solutions

    One solution would be to put a minimal amount of texts/drawings and put the detailed information in a tooltip that is shown when the text/drawing is hovered over with the mouse.

    Problems

    Unfortunately, NT does not support custom tooltips out of the box. Neither does it expose properties/methods that make it easy to implement a custom solution.

    Hack

    Since source code is included for the text/drawing objects, we can modify the code to add the functionality we desire. The solution below does not implement tooltips in the strict sense of the feature as defined by Windows. Due to the limited information provided by NT, this is more of a hybrid Frankenstein's monster version.

    If you are really determined and persistent, you could eventually get a correct version working since all the information is in NT - it's just not easy and straightforward to get to in an efficient manner.

    Drawbacks

    Since we are hacking the source directly, we need to copy the changes over each time we install a new version of NT.

    Solution

    I've attached files that implement the "tooltips" for texts, chart markers and drawing objects (ellipse, rectangle, triangle). These files are a replacement for the ones that ship with NT in the DrawingTools folder (See the notes below about replacing). You could use the same technique to apply this to the other drawing objects as well.

    How It Works

    Unlike regular tooltips that appear on hover, you need to click the target object so it is selected. Any movement of the mouse will then cause the "tooltip" to appear. Also unlike regular tooltips, the tooltip will remain visible until you click somewhere other than in the tooltip.

    Usage

    This hack adds three properties to the drawing objects. The properties are ToolTipText (string), ToolTipContent (object), and ToolTipContentFactory (Func<object>). You only need to set one of these properties 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 ToolTipText property to display a simple string.

    Code:
    var drawing = Draw.Dot(...);
    
    if (drawing != null)
        drawing.ToolTipText = "Hello, world!";
    Or if you are using my hack for compiling with .Net 4.6 or later (Here)

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

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

    Code:
    var drawing = Draw.Dot(...);
    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 ToolTipContentFactory property 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 property 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;
        });
    NOTE: It is important to check the result from the Draw.* functions because they sometimes return null.

    Installation
    • If you are using version 8.0.6.0, copy the attached files into the DrawingTools folder
    • If you are using a different version (or whenever you need to upgrade), search for the sections enclosed with "// Begin Wil changes", "// End Wil changes" and copy them into the corresponding files and locations in the DrawingTools folder. I have some changes in there to adjust the calculations of drawing objects to be confined to a bar instead of in-between bars. You can remove those changes if you don't want them


    NOTES

    Since TextFixed cannot be selected, you won't be able to access any tooltips assigned to instances of it. Since by definition there will usually be at most five instances per chart (based on position), you could efficiently implement a proper tooltip for this class - with proper hit testing and hovering.

    !! Super Hack Alert !!

    If you are adventurous and like to live on the edge, you could use custom tooltips to modify the behavior of your indicator/strategy on the fly!
    Attached Files
    Last edited by wbennettjr; 07-15-2017, 05:16 PM.

    #2
    It would be great if NinjaTrader would look at this approach and actually implement into the built-in objects.

    Comment


      #3
      Hello neoikon,

      I will put in a feature request for this.
      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by algospoke, Today, 06:40 PM
      0 responses
      10 views
      0 likes
      Last Post algospoke  
      Started by maybeimnotrader, Today, 05:46 PM
      0 responses
      7 views
      0 likes
      Last Post maybeimnotrader  
      Started by quantismo, Today, 05:13 PM
      0 responses
      7 views
      0 likes
      Last Post quantismo  
      Started by AttiM, 02-14-2024, 05:20 PM
      8 responses
      168 views
      0 likes
      Last Post jeronymite  
      Started by cre8able, Today, 04:22 PM
      0 responses
      10 views
      0 likes
      Last Post cre8able  
      Working...
      X