Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MouseMove/OnRender/Timer too slow to reflect mouse changes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MouseMove/OnRender/Timer too slow to reflect mouse changes

    Hello,

    I'm using the following code to match the mouse position to the bar index in real time, this is my objective, that in a smooth and responsive way the bar index is highlighted on the chart.

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
     Print(string.Format("Render Event on {0}", DateTime.Now));
     //var point = e.MouseDevice.GetPosition(this.ChartControl);
     var point = this.ChartControl.MouseDownPoint;
    
     Print(string.Format("X {0} Y {1}", point.X, point.Y));
    
     DateTime slotTime = this.ChartControl.GetTimeByX((int)point.X);
    
     if (Bars == null)
      return;
    
     int barsAgo = CurrentBar - Bars.GetBar(slotTime);
    
     Draw.TextFixed(this, "TEXT", string.Format("{0}", CurrentBar - barsAgo), TextPosition.TopRight);
    }
    I have also tried using a Timer (250ms) and the MouseMove event, however all these options seem to lag behind by even a few seconds, is there something I'm missing?

    Regards,

    #2
    Hello Waxavi,

    OnRender is called for rendering events which the chart dictates how often that happens. The MouseDownPoint will only be updated by NinjaTrader based on specific criteria, this is not the same as a WPF mouse movement event so that also may not be directly in sync with OnRender.

    To have a constant mouse position you would need to use a private variable and then use one of the WPF mouse events which has subscribed to the ChartControl object. From that mouse event you could update your private variable to the current known position which OnRender could read.

    There is a sample of using the mouse events in the following link: https://ninjatrader.com/support/foru...ter#post820868

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    65 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X