Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bug: OnBarUpdate processing historical bars with State.Realtime

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

    #46
    I have been further investigating into the problem B. I am able to reproduce the problem with 20 something indicators, which are not available open source. If I have some time I will code a simplified indicator to show the problem.


    Conditions necessary for triggering the exception

    (1) All indicators are programmatically set to "IsSuspendedWhileInactive = true."

    (2) All indicators load a secondary bar series of minute or tick data via AddDataSeries() in State.Configure.

    (3) All indicators have a custom OnRender() method.


    Reproducing the problem

    The easiest way to reproduce the problem is

    -> first to disconnect from the data feed

    -> then open a chart with a complex multi-timeframe indicator for which "IsSuspendedWhileInactive" is programmatically set to "true".

    -> then duplicate the chart 4 times by right clicking the tab in the lower left corner of the chart

    -> then change the instruments in the 4 duplicated tabs

    -> then reconnect to the data feed

    When reconnecting to the data feed one of the 5 charts is active, while the other 4 charts are inactive. For the active chart the plot works as expected. However, when I toggle to one of the inactive charts, I am getting the error message.

    "Error on calling 'OnRender' method on bar 324961: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

    The bar count 324961 refers to the bar count of the secondary bar series. The secondary bar series is nowhere called in the custom OnRender() method. After massive problems I have even replaced "BarsArray[0]" with "ChartBars" in all the custom OnRender() methods of my indicators.


    Interpreting the findings

    It seems that in the case of an inactive chart - which has not yet been active after connecting to a data feed - a false bar count is passed to OnRender(), which in turn tries to access a chart bar with an index that does not exist. The error message above was created on a 15-min chart (about 4382 bars) with a secondary bar series of 50-tick bars (324961 bars) added.

    I have also inserted a Print instruction in the beginning of the OnRender() method for BarsArray[0].Count, which showed a false barcount for the primary bars. This points to a problem of OnRender() running before OnBarUpdate() was completed.


    Workaround

    The only workaround here is to set all multi-timeframe indicators to

    Code:
    IsSuspendedWhileInactive = false;
    In this case everyrthing works as expected and there are no problems. I have well noticed that the pivots indicator - which loads a secondary bar series when used with daily data - is also set to "IsSuspendedWhileInactive = false", Probably this setting has been chosen to avoid similar problems that I have encountered.

    With the workaround available fixing this problem becomes less urgent. However, it should be noted that the current solution for "IsSuspendedWhileInactive" is incompatible with multi-timeframe indicators.
    Last edited by Harry; 09-01-2017, 02:34 PM.

    Comment


      #47
      OnBarUpdate() not being called

      I have now done further testing and have found two different scenarios with multi-time frame indicators. In the first scenario OnBarUpdate() is not being called, which in turn triggers exceptions in the custom plot as values are not being set.

      In the second scenario with another multi-timeframe indicator, OnBarUpdate() is being called, but Values[0].GetValueAt(lbarIndex) always returns the value 0.

      Both scenarios are 100% reproducible with my custom indicators.


      Why this matters for users:

      The customer has created a workspace with a chart window that contains several tabs. They open the workspace in the morning,

      Then they connect to a datafeed. The first active tab of the chart window loads correctly and the chart is displayed. Then they switch to the second tab and the chart is empty while OnRender throws an exception that can be checked in the logfile.

      1st Scenario:

      Not connected. Empty workspace. Add a simple 15-min chart for ES 09-17. Add a multi-timeframe indicator to that chart. Multi-timeframe indicator is programmatically set to "IsSuspendedWhileInactive = true;". Duplicate the chart by right-clicking on the tab. Change the instrument on the duplicated tab to something else, for example to CL 10-17. Switch back to the chart ES 09-17.

      ES 09-17 chart is now active, CL 10-17 is inactive. Both have just a single multi-timeframe indicator added. Now connecting to the datafeed.

      Active chart ES 09-17: After connection data is loaded. OnStateChange is called and running through states State.SetDefaults, State.Configure, State.DataLoaded and State.Historical. Afterwards OnBarUpdate() is called and processes the historical chart bars. This is as expected.

      Inactive chart CL 10-17: OnStateChange is called and running through states State.SetDefaults, State.Configure, State.DataLoaded and State.Historical. OnBarUpdate() is not called. No bars are processed.

      When switching to the second tab, CL 10-17 becomes the active chart. OnBarUpdate() is not called. OnRender() is called and throws an exception, because OnBarUpdate() has not processed a single bar.

      Problem is here: OnBarUpdate() is never called. In this scenario OnRender is called prior to OnBarUpdate(). BarsArray[0].Count returns the value as expected. Therefore the check that I use in OnRender "if (BarsArray[0].Count < ChartBars.ToIndex) return;"
      will not prevent OnRender() from running.

      2nd Scenario:.

      Not connected. Empty workspace. Add a simple 15-min chart for ES 09-17. Add a multi-timeframe indicator to that chart. Multi-timeframe indicator is programmatically set to "IsSuspendedWhileInactive = true;". Duplicate the chart by right-clicking on the tab. Change the instrument on the duplicated tab to something else, for example to CL 10-17. Switch back to the chart ES 09-17.

      ES 09-17 chart is now active, CL 10-17 is inactive. Both have just a single multi-timeframe indicator added. Now connecting to the datafeed.

      Active chart ES 09-17: After connection data is loaded. OnStateChange is called and running through states State.SetDefaults, State.Configure, State.DataLoaded and State.Historical. Afterwards OnBarUpdate() is called and processes the historical chart bars. This is as expected.

      Inactive chart CL 10-17: OnStateChange is called and running through states State.SetDefaults, State.Configure, State.DataLoaded and State.Historical. OnBarUpdate() is not called. No bars are processed.

      When switching to the second tab, CL 10-17 becomes the active chart. OnBarUpdate() is being called. However, the plot values cannot be accessed in OnRender() via GetValueAt().

      Values[n].GetValueAt(barIndex) returns the value 0 for all plots and bar indices. The chart remains empty.

      Again both scenarios are 100% reproducible. I would be pleased to discuss this problem more in detail via a teamviewer or Skype connection. I will further try to code simplified indicators that will allow for testing both scenarios.


      Multi-timeframe indicators working with setting "IsSuspendeWhileInactive = false"

      There is absolutely no problem

      - for multi-timeframe indicators set to IsSuspendedWhileInactive = false
      - for indicators that do not load secondary bars via "AddDataSeries"

      Comment


        #48
        Hello Harry,

        Thank you for your response.

        Our QA team would like to confirm that the attached indicator is an accurate means to reproduce your case for OnRender.

        Please let us know if this reproduces the matter.
        Attached Files

        Comment


          #49
          Originally posted by NinjaTrader_PatrickH View Post
          Hello Harry,

          Thank you for your response.

          Our QA team would like to confirm that the attached indicator is an accurate means to reproduce your case for OnRender.

          Please let us know if this reproduces the matter.

          I have checked the attached indicator and could not reproduce the issue with this indicator. I will probably go the reverse way, take an indicator that triggers the problem and then simplify it as much as possible. This would be a step by step process and may take a little longer.

          However, I promise to come back. Your efforts are appreciated!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          19 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          21 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X