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.
var drawing = Draw.Dot(...); if (drawing != null) drawing.ToolTipText = "Hello, world!";
var drawing = Draw.Dot(...); drawing?.SetToolTipText("Hello, world!");
To display controls on a few objects, you can use the ToolTipContent property to provide your element tree.
var drawing = Draw.Dot(...); var button = new Button { Content = "Hello" }; button.Click += (_, __) => button.Content = "World"; drawing?.SetToolTipContent(button);
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.
var drawing = Draw.Dot(...); drawing?.SetToolTipContentFactory(() => { var button = new Button { Content = "Hello" }; button.Click += (_, __) => button.Content = "World"; return button; });
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!
Comment