Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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

    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Jonker, Today, 01:19 PM
    0 responses
    1 view
    0 likes
    Last Post Jonker
    by Jonker
     
    Started by futtrader, Today, 01:16 PM
    0 responses
    4 views
    0 likes
    Last Post futtrader  
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,789 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    838 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,294 views
    1 like
    Last Post jgualdronc  
    Working...
    X