In summary, with the mouse inside a focused chart, after pressing and releasing the ALT modifier key by itself, the ChartPanel.MouseLeave() callback is called. It is basically as if the mouse has left the chart, even though it is still within the chart panel.
After this, moving the mouse within the panel does not call ChartPanel.MouseMove() anymore because it believes that the mouse pointer is outside the chart when in fact it's not. Only by pressing ALT again or by clicking on the chart triggers ChartPanel.MouseEnter(), which enables ChartPanel.MouseMove().
The following code is a basic proof of concept to see this:
namespace NinjaTrader.NinjaScript.Indicators { public class ProofOfConcept : Indicator { private int counter = 0; protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "ProofOfConcept"; Description = @"Testing ChartPanel.MouseLeave and ChartPanel.MouseEnter"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = false; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; } else if (State == State.Configure) { } else if (State == State.Historical) { if (ChartPanel != null) { ChartPanel.MouseLeave += OnMouseLeave; ChartPanel.MouseEnter += OnMouseEnter; ChartPanel.MouseMove += OnMouseMove; } } else if (State == State.Terminated) { if (ChartPanel != null) { ChartPanel.MouseLeave -= OnMouseLeave; ChartPanel.MouseEnter -= OnMouseEnter; ChartPanel.MouseMove -= OnMouseMove; } } } private void OnMouseEnter(object sender, MouseEventArgs e) { Print("OnMouseEnter"); } private void OnMouseLeave(object sender, MouseEventArgs e) { Print("OnMouseLeave"); } private void OnMouseMove(object sender, MouseEventArgs e) { if (counter++ % 10 == 0) Print(string.Format("OnMouseMove: {0}", counter)); } } }
OnMouseMove: 1 OnMouseMove: 11 OnMouseMove: 21 OnMouseMove: 31 OnMouseMove: 41 OnMouseMove: 51 OnMouseMove: 61 OnMouseMove: 71 OnMouseMove: 81 OnMouseMove: 91 OnMouseMove: 101 OnMouseMove: 111 OnMouseLeave
Is this expected behavior? If so, is there a workaround for this?
I expected to received the MouseMove callback whenever the mouse moves inside the chart. This affects one of our indicators where ALT is used as a modifier key to see order previews on the chart.
This is on NinjaTrader 8.0.26.1 64-bit.
Comment