NexusFi: Find Your Edge


Home Menu

 





Showing a context menu in the NinjaTrader chart


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Zondor with 3 posts (1 thanks)
    2. looks_two AlBundy with 2 posts (2 thanks)
    3. looks_3 ratfink with 1 posts (0 thanks)
    4. looks_4 futuretrader with 1 posts (0 thanks)
    1. trending_up 3,515 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
AlBundy's Avatar
 AlBundy 
Vienna Austria
 
Experience: Advanced
Platform: NinjaTrader
Trading: Forex
Posts: 25 since Jun 2013
Thanks Given: 10
Thanks Received: 12

NT 7.0

How can I show a context menu in the chart [for example when a user double clicks in the chart]:

 
Code
   MenuItem [] menuManualButton = new MenuItem []
   {
      new MenuItem( "Text 1", eventHandler1),
      new MenuItem( "Text 2", eventHandler2),
   };

   ContextMenu contextManualButton = new ContextMenu( menuManualButton );
   contextManualButton.Show( (ChartControl) sender, Cursor.Position );
My question is what I have to provide in the show function as the first parameter? This should be a control object.


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
MegaETH Proves the Crowd Right: Prediction Markets Calle …
Prediction Markets & Event Contracts
Election Sunday Resolves: Peru Heads to Runoff at 42pct, …
Prediction Markets & Event Contracts
TradingView Deploys AI to Monitor SEC Filings in Real Ti …
TradingView
Weekend Update: First Qatari LNG Transit Attempted -- IR …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #2 (permalink)
 
AlBundy's Avatar
 AlBundy 
Vienna Austria
 
Experience: Advanced
Platform: NinjaTrader
Trading: Forex
Posts: 25 since Jun 2013
Thanks Given: 10
Thanks Received: 12

This works like a charm and the context menu is shown exactly on the mouse position where the double click occurred:

 
Code
//---------------------------------------------------------------------------------------
private void ChartPanel_MouseDoubleClick( object sender , MouseEventArgs eventArguments )
//---------------------------------------------------------------------------------------
{
	MenuItem [] contextMenuItems = new MenuItem []
	{
		new MenuItem( "Menu 1", eventMenu1 ),
		new MenuItem( "Menu 2", eventMenu2 ),
	};

	ContextMenu contextMenuObject = new ContextMenu( contextMenuItems );
	contextMenuObject.Show( (Control) sender, eventArguments.Location, LeftRightAlignment.Right );
}

Don't forget to add the handler to the chart:
 
Code
ChartControl.ChartPanel.MouseDoubleClick += ChartPanel_MouseDoubleClick;

and unload it with:
 
Code
ChartControl.ChartPanel.MouseDoubleClick -= ChartPanel_MouseDoubleClick;


Started this thread Reply With Quote
Thanked by:
  #3 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: Ninjatrader®
Broker: CQG, Kinetick
Trading: Gameplay Klownbine® Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,734


Unfortunately, so far have not been able to compile in NT8.

Problem with this line:

 
Code
private void ChartPanel_MouseDoubleClick( object sender ,MouseEventArgs eventArguments )
MouseEventArgs is an ambiguous reference between System.Windows.Input.MouseEventArgs and System.Windows.Forms.MouseEventArgs.


"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,550 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,430


Zondor View Post
Unfortunately, so far have not been able to compile in NT8.

Problem with this line:

 
Code
private void ChartPanel_MouseDoubleClick( object sender ,MouseEventArgs eventArguments )
MouseEventArgs is an ambiguous reference between System.Windows.Input.MouseEventArgs and System.Windows.Forms.MouseEventArgs.

Under NT8 these areas are a mixture of WPF and Forms so you have to specify whichever one you want to use in full:

 
Code
		// we're in WPF space

		private void ChartPanel_MouseDoubleClick( object sender , System.Windows.Input.MouseEventArgs eventArguments )
		{
		}

		// we're in Forms space
		
		private void ChartPanel_MouseDoubleClick( object sender , System.Windows.Forms.MouseEventArgs eventArguments )
		{
		}
Cheers


Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: Ninjatrader®
Broker: CQG, Kinetick
Trading: Gameplay Klownbine® Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,734

@ratfink, that's a step in the right direction, but there still seems to be a long way to go to get it to work in NT8.

Thanks for your help, will continue to play around with this.


"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 futuretrader 
Como Italy
 
Experience: Intermediate
Platform: Ninjatrader, customized
Trading: ES
Posts: 525 since Feb 2010
Thanks Given: 471
Thanks Received: 643

In NT8 you can also add items to the right-click context menu when you've selected an indicator on the chart, which avoids having to mess around with the mouse controls.


Reply With Quote
  #7 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: Ninjatrader®
Broker: CQG, Kinetick
Trading: Gameplay Klownbine® Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,734

The idea is to not use the NT8 context menu but to have my own.

I do NOT want to reload the chart after the user inputs are made to my menu.


"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett
Follow me on X Visit my NexusFi Trade Journal Reply With Quote




Last Updated on May 7, 2017


© 2026 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 - Downloads - Top
no new posts