this is a script that displays the coordinates of the mouse. As the mouse moves, the text is refreshed with new coordinates. It works fine.
The problem arises if I change the type of cursor to Local (crosshair). Then the cursor does not move, it stays fixed (have to click on the ChartPanel for the cursor is refreshed) However, coordinates are painted and updated properly.
Best Regards
public class MouseMove : Indicator { private Point mousePosition; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "MouseMove"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.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.DataLoaded) { if( this.ChartPanel != null ) this.ChartPanel.MouseMove += new MouseEventHandler(this.OnMouseMove); } else if ( State == State.Terminated ) { if( this.ChartPanel != null ) this.ChartPanel.MouseMove -= new MouseEventHandler(this.OnMouseMove); } } internal void OnMouseMove(object sender, MouseEventArgs e) { this.mousePosition = e.GetPosition( this.ChartPanel ); this.ChartControl.InvalidateVisual(); e.Handled = true; } protected override void OnBarUpdate() { } protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); System.Windows.Media.Brush textBrush = Brushes.RoyalBlue; SharpDX.Direct2D1.Brush textBrushDX = textBrush.ToDxBrush(RenderTarget); SharpDX.RectangleF rectangleF = new SharpDX.RectangleF( 10.0F, 20.0F, 500.0F, 100.0F ); SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(Core.Globals.DirectWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.ExtraBold, SharpDX.DirectWrite.FontStyle.Normal, SharpDX.DirectWrite.FontStretch.Normal, 15.0F ); //{ TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading, WordWrapping = WordWrapping.NoWrap }; String text = "Mouse: (" + this.mousePosition.X.ToString() + " , " + this.mousePosition.Y.ToString() + " )" + Environment.NewLine; RenderTarget.DrawText( text, textFormat, rectangleF, textBrushDX); } }
Comment