Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Add-On Development

Add-On Development General NinjaScript development questions.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 07-15-2017, 05:07 PM   #1
wbennettjr
Senior Member
 
Join Date: Mar 2012
Location: Florida
Posts: 137
Thanks: 38
Thanked 88 times in 37 posts
Cool 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
File Type: cs ToolTipAddOn.cs (22.7 KB, 7 views)
wbennettjr is offline  
Reply With Quote
The following 3 users say thank you to wbennettjr for this post:
Old 07-17-2017, 09:08 AM   #2
PrTester
Senior Member
 
Join Date: Mar 2007
Posts: 216
Thanks: 2
Thanked 10 times in 7 posts
Default

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.
PrTester is offline  
Reply With Quote
Old 07-17-2017, 03:48 PM   #3
wbennettjr
Senior Member
 
Join Date: Mar 2012
Location: Florida
Posts: 137
Thanks: 38
Thanked 88 times in 37 posts
Default

Hi PrTester,

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

I take it the AddOn compiled with no problems?

Wil
wbennettjr is offline  
Reply With Quote
Old 07-17-2017, 03:56 PM   #4
wbennettjr
Senior Member
 
Join Date: Mar 2012
Location: Florida
Posts: 137
Thanks: 38
Thanked 88 times in 37 posts
Default

BTW: Make sure you've added "using NinjaTrader.Custom.AddOns" to your indicator.
wbennettjr is offline  
Reply With Quote
Old 07-18-2017, 07:10 AM   #5
PrTester
Senior Member
 
Join Date: Mar 2007
Posts: 216
Thanks: 2
Thanked 10 times in 7 posts
Default

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.
PrTester is offline  
Reply With Quote
Old 07-18-2017, 01:11 PM   #6
wbennettjr
Senior Member
 
Join Date: Mar 2012
Location: Florida
Posts: 137
Thanks: 38
Thanked 88 times in 37 posts
Default

Good to hear. Hope everything works out for you.
wbennettjr is offline  
Reply With Quote
Reply

Tags
addon, tooltips

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to draw objects on chart through AddOn? jjhou Version 8 Beta 1 08-10-2016 08:57 AM
Exception with Custom Drawing Tool after opening Drawing Objects Window sdonahue Version 8 Beta 2 03-16-2016 02:54 PM
Tool Drawing Objects deployed hesther Platform Technical Support 2 03-04-2016 11:22 AM
Please add an Extending Rectangle drawing tool duncanhoo Platform Technical Support 16 12-10-2013 03:43 AM
Add Shortcut for Remove Drawing Objects? RTB777 Suggestions And Feedback 1 06-02-2008 10:39 PM


All times are GMT -6. The time now is 06:29 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.