NexusFi: Find Your Edge


Home Menu

 





NT-7 Context Menu Items


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Prtester with 4 posts (0 thanks)
    2. looks_two Mindset with 3 posts (0 thanks)
    3. looks_3 sam028 with 2 posts (1 thanks)
    4. looks_4 roonius with 1 posts (12 thanks)
    1. trending_up 8,937 views
    2. thumb_up 13 thanks given
    3. group 6 followers
    1. forum 11 posts
    2. attach_file 2 attachments




 
Search this Thread

NT-7 Context Menu Items

  #1 (permalink)
 Prtester 
SE-Asia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Amp
Trading: ES
Posts: 151 since Jun 2009
Thanks Given: 66
Thanks Received: 124

Anyone work with Context Menu Items in NT-7?, I have a working indicator in 6.5 , but the code break in nt7.

the problem is with this line :
int event1 = ChartControl.ContextMenu.MenuItems.Add(0, menuItem1);

it throw an exception ("Object reference not set to an instance of an object.")

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
35 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
19 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Spoo-nalysis ES e-mini futures S&P 500
14 thanks
  #2 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


Prtester View Post
Anyone work with Context Menu Items in NT-7?, I have a working indicator in 6.5 , but the code break in nt7.

the problem is with this line :
int event1 = ChartControl.ContextMenu.MenuItems.Add(0, menuItem1);

it throw an exception ("Object reference not set to an instance of an object.")

Can you provide the NT 6.5 code ?

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
 Prtester 
SE-Asia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Amp
Trading: ES
Posts: 151 since Jun 2009
Thanks Given: 66
Thanks Received: 124



sam028 View Post
Can you provide the NT 6.5 code ?

Not complete but here are the important sections:

On BarUpdate section:

if (!inited && ChartControl!=null )
{
MenuItem menuItem1 = new MenuItem("My Option-1", new EventHandler(MyOption1));
MenuItem menuItem2 = new MenuItem("My Option-2, new EventHandler(MyOption2));
int event1 = ChartControl.ContextMenu.MenuItems.Add(0, menuItem1);
int event2 = ChartControl.ContextMenu.MenuItems.Add(1, menuItem2);
int event4 = ChartControl.ContextMenu.MenuItems.Add(3, new MenuItem("-"));
ChartControl.MouseDown += new MouseEventHandler(OnMouseClick);
inited=true;
}

public void MyOption1(object sender, EventArgs e)
{
in here insert your action code
}

public void MyOption2(object sender, EventArgs e)
{
in here insert your action code
}
protected override void Dispose()
{
if (inited && ChartControl!=null)
{
ChartControl.ContextMenu.MenuItems.RemoveAt (1);
ChartControl.ContextMenu.MenuItems.RemoveAt (0);
ChartControl.ChartPanel.MouseDown -= new MouseEventHandler (this.OnMouseClick);

inited = false;
}
base.Dispose ();
}

Started this thread Reply With Quote
  #4 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,440 since Jun 2009
Thanks Given: 33,214
Thanks Received: 101,599



I would like to know as well.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

Prtester, with only the piece of code included, it's very hard to make something working on NT 6.5.
So, very hard to find what's wrong with NT 7.0...

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
  #6 (permalink)
 Prtester 
SE-Asia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Amp
Trading: ES
Posts: 151 since Jun 2009
Thanks Given: 66
Thanks Received: 124


sam028 View Post
Prtester, with only the piece of code included, it's very hard to make something working on NT 6.5.
So, very hard to find what's wrong with NT 7.0...

Try with this Sam

Attached Files
Elite Membership required to download: Sam28_test.cs
Started this thread Reply With Quote
  #7 (permalink)
 
roonius's Avatar
 roonius   is a Vendor
 
Posts: 131 since Jun 2009
Thanks Given: 20
Thanks Received: 295


Prtester View Post
Anyone work with Context Menu Items in NT-7?, I have a working indicator in 6.5 , but the code break in nt7.

the problem is with this line :
int event1 = ChartControl.ContextMenu.MenuItems.Add(0, menuItem1);

it throw an exception ("Object reference not set to an instance of an object.")

NT 7 upgraded ContextMenu to ContextMenuStrip.
You can see quick sample how to implement Context Menu Items in the attached file.
To PrTester and others: Please DO NOT bypass TriggerCustomEvent or you can end up messing up internal NinjaTrader Events and get unpredictable results and/or behavior.

P.S. Attached file is for NT7 only. NT 6.5 users do not bother trying it.

Attached Files
Elite Membership required to download: CtxMenu.zip
Reply With Quote
  #8 (permalink)
 Prtester 
SE-Asia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Amp
Trading: ES
Posts: 151 since Jun 2009
Thanks Given: 66
Thanks Received: 124


roonius View Post
NT 7 upgraded ContextMenu to ContextMenuStrip.
You can see quick sample how to implement Context Menu Items in the attached file.
To PrTester and others: Please DO NOT bypass TriggerCustomEvent or you can end up messing up internal NinjaTrader Events and get unpredictable results and/or behavior.

P.S. Attached file is for NT7 only. NT 6.5 users do not bother trying it.

Thank you Sir :-), I will try to not mess my NT

Started this thread Reply With Quote
  #9 (permalink)
 
Mindset's Avatar
 Mindset 
Singapore
 
Experience: Intermediate
Platform: NT
Broker: ib
Trading: MES
Posts: 365 since Sep 2009
Thanks Given: 90
Thanks Received: 291

Roonius
Thanks for the code example - I am slightly confused though. You declare ToolStripitems yet place them in a contextmenustrip.
I haven't worked out what ontermination() does yet eitherbut I have only had beta for a day - it can't be instead of dispose which is where I would have put this code previously. EDIT -YES IT IS- NT7 does away with Dispose()

Just as I thought I had some kind of handle on NS it all changes (lol)

Edit - when you hover the mouse over Trigger Custom Event it now urges you to use another signature as it is deprecated?? Oops I see the new signature.
I have spent a fruitless 3 hours trying to get my menu to work using this Code structure but it won't.
I shall have to see if support can help ( that should be a laugh!)
Sorted it myself with Roonius' code example above.

Reply With Quote
  #10 (permalink)
 
Mindset's Avatar
 Mindset 
Singapore
 
Experience: Intermediate
Platform: NT
Broker: ib
Trading: MES
Posts: 365 since Sep 2009
Thanks Given: 90
Thanks Received: 291


Big thanks to Roonius for supplying the context menu snippet - saved me hours of searching.
I am brand new to NT7 and without that concept of ContextMenuStrip I have no idea how long it would have taken me to sort out.

Reply With Quote




Last Updated on November 17, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts