NinjaTrader 8 AddOn - How to get the exact price from a right-click on ChartControl?

Hello,

I am developing a NinjaTrader 8 AddOn called SDTGestorOrdenes.

The AddOn successfully detects the chart’s native ContextMenuOpening event and adds a custom menu item called “SDT Buy Limit”.

My goal:

I need to obtain the exact price level where the user right-clicks on the chart, so I can eventually place a Buy Limit order at that price using the ATM strategy selected in Chart Trader.

What I have confirmed:

  • The native context menu opens correctly.

  • The event sender is NinjaTrader.Gui.Chart.ChartControl.

  • ContextMenuEventArgs.CursorTop provides a vertical coordinate.

  • The chart has one panel and three scales: Right, Left, and Overlay.

The problem:

I attempted to use:

chartControl.ChartPanels[0].Scales[0].GetValueByYWpf(e.CursorTop)

The code compiled successfully, but opening the context menu caused an unhandled NullReferenceException.

My questions:

  1. What is the correct and safe way to obtain the exact price at the right-click position from a NinjaTrader 8 AddOn?

  2. How can I obtain the appropriate ChartScale outside an indicator’s OnRender() method?

  3. Does CursorTop use the correct coordinate system for GetValueByYWpf(), or must the mouse position be converted relative to the chart panel?

  4. Is there an official example or working code demonstrating this functionality?

I would appreciate guidance from developers who have implemented this successfully.

Thank you.

Take a look at https://ninjatraderecosystem.com/user-app-share-download/trading-from-chart/

1 Like

Hi Bill,

I wanted to sincerely thank you for taking the time to respond to my question and share the TradingFromChart link.

I downloaded and installed the indicator, tested it successfully in NinjaTrader 8, and it works perfectly!

Your suggestion helped me solve an important part of a trade and risk management project I am developing.

I truly appreciate your time, kindness, and willingness to help others in the NinjaTrader community.

Thank you again for pointing me in the right direction!

Best regards,
Rita