Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ForceRefresh() not refreshing chart

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

    ForceRefresh() not refreshing chart

    I'm using the code to change the value of a textbox in the MainMenu of a chart. The function is called correctly and showSize is updated, however ForceRefresh does not repaint the chart. I have to click and drag the chart for any updates to be rendered. Is there another function that calls OnRender()?


    Code:
    private void sizeBox_TextChanged(object s, EventArgs e){
    			TextBox b = (TextBox) s;
    			showSize = Convert.ToInt32(b.Text);
    			
    			ForceRefresh();
    			
    		}
    Also, when trying to change the value of my textbox by entering numbers, ninjatrader will bring up the quick time period change dialog. I'm getting around the issue by using my middle mouse wheel to scroll, but eventually this should be fixed as well.
    Last edited by habibalex; 10-26-2015, 05:20 PM.

    #2
    ForceRefresh() queues OnRender() to be called by resetting an internal marker which is used to determine when OnRender() should be called next. It does not immediately invalidate the chart control and is documented as a "safe" way to update the chart should you need to (e.g., there has not be a recent tick).

    For more advanced programming such as adding and interacting with 3rd party controls, you should consider use ChartControl.InvalidateVisual().
    This is an "unsafe" and undocumented method which can lead to performance or threading issues. Only programmers experienced with threading and understand the impact of excessive calls to OnRender() should use this method.

    I've attached a test indicator to demonstrate the difference.

    To test:
    • Add this indicator to a chart which will add two buttons to the Chart's Main Menu
    • Disconnect from any data feeds (to prevent additional calls to OnRender which may obscure your test)
    • Open the NinjaScript output window.
    • Click on either button to observe the difference.

    The result should print the time span from OnRender() was last called.

    As you will observe, ForceRefesh() will end up in calling OnRender(), however on some subsequent clicks, you'll notice that ForceRefresh() does not always trigger an OnRender() for each time it is called, e.g.,

    ForceRefresh() Clicked
    Seconds since last render=0.1750175
    ForceRefresh() Clicked
    Seconds since last render=0.8130813
    ForceRefresh() Clicked
    ForceRefresh() Clicked
    ForceRefresh() Clicked
    Seconds since last render=1.0731073
    ForceRefresh() Clicked
    ForceRefresh() Clicked
    Seconds since last render=0.4890489
    Compare to InvalidateVisual(), you would not see this behavior and would see that OnRender() is called after each subsequent click, e.g.,

    InvalidateVisual() Clicked
    Seconds since last render=0.1750175
    InvalidateVisual() Clicked
    Seconds since last render=0.1350135
    InvalidateVisual() Clicked
    Seconds since last render=0.1610161
    InvalidateVisual() Clicked
    Seconds since last render=0.1720172
    InvalidateVisual() Clicked
    Seconds since last render=0.1430143
    InvalidateVisual() Clicked
    Seconds since last render=0.1510151
    It would be recommended to always try to accomplish your needs to update OnRender with ForceRefresh(). If you’re running into situations where that is not updating fast enough, you may need to call ChartControl.InvalidateVisual() directly, but do be mindful of the risks involved in using this method.
    Attached Files
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by habibalex View Post
      Also, when trying to change the value of my textbox by entering numbers, ninjatrader will bring up the quick time period change dialog. I'm getting around the issue by using my middle mouse wheel to scroll, but eventually this should be fixed as well.
      For this problem, set the keyevent to handled, as per this post:

      MatthewNinjaTrader Product Management

      Comment


        #4
        InvalidateVisual() is throwing an error saying "does not exist in the current context"

        Comment


          #5
          Please double check you are using ChartControl.InvalidateVisual().

          If so, can you provide reproducible code including using statements which is generating this error?
          MatthewNinjaTrader Product Management

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mizzouman1, Today, 07:35 AM
          4 responses
          18 views
          0 likes
          Last Post Mizzouman1  
          Started by philmg, Today, 01:17 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by cre8able, Today, 01:01 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by manitshah915, Today, 12:59 PM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by ursavent, Today, 12:54 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X