Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Poor Performance With Secondary Data Series

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

    Poor Performance With Secondary Data Series

    I'm seeing very poor performance,10x to 50x slower strategy execution, when adding a secondary series built from minute bars.

    I have attached a bare bones strategy to demonstrate the issue. Note that the strategy is doing basically nothing in OnBarUpdate. It's only reporting the elapsed time on the final historical bar.

    There are some boolean properties that can be selected in the UI, each will load a different type of secondary data series. After re-running the strategy, look at the elapsed time in the output console.

    I have 5 years of YM 03-24 30min bars in a chart as my primary series.

    ​​

    Here are my results selecting each of the secondary data series options in turn (via the Strategy UI). The numbers below are typical values after refreshing and re-running the strategy multiple times.

    No secondary series 40ms
    Add Day Series 60ms
    Add 30 Minute Series 40ms
    Add 60 Minute Series 506ms
    Add 1440 Minute Series 527ms
    Add 30 Minute MYM Series 2231ms
    Add 30 Minute ES Series 2127ms
    Add 30 Minute CL Series 4000+ms then 43ms

    Several points:
    • These numbers show a 10x to 50x performance hit for certain scenarios.
    • These times usually persist per iteration in the optimizer, massively slowing down optimizations.
    • The behavior is NOT 100% consistent. In the CL 30min case above, it was multi-second times for several minutes of testing until suddenly it was super fast. Meanwhile, MYM 30min and ES 30min are still very slow. The super fast speed is what I would always expect because you can cache the bars. But it seems to be completely rebuilding bars every time and even re-downloading the data some of the time.
    Click image for larger version

Name:	Redownloading.png
Views:	225
Size:	54.5 KB
ID:	1283942


    My Questions:

    1. Why is there such a performance hit for some scenarios?
    2. I've seen these types of flaky performance issues on data series for years on different computers, different NT versions, different installs. It's very frustrating. (That wasn't a question.)
    3. Is there anything that can be done, or guidelines to follow, that will minimize or eliminate these types of problems.
    4. Can you replicate the issue?
    5. Is this expected behavior?

    By the way, I have cleared the files in /NinjaTrader 8/db/cache



    #2
    Hello BarzTrading,

    Thank you for your post.

    Adding data series dynamically is not supported. This is mentioned in the Help Guide page for AddDataSeries():
    https://ninjatrader.com/support/help...dataseries.htm

    Adding a secondary series will likely trigger historical data to download, which is expected to have some performance impact since that data has to be processed.

    To test, I suggest disconnecting from all connections and testing in the Strategy Analyzer.

    Please let us know if we can assist further.

    Comment


      #3
      Thanks, Gaby.

      1. What are the differences between running a strategy in a chart versus running in Strategy Analyzer

      The help page that you linked above says:

      Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.​
      When I ran my original strategy included above in Strategy Analyzer I did get the error mentioned, that I may be trying to add a data series dynamically. But I never got this error when running in a Chart. Why the difference?

      I am seeing that there are significant differences in handling of data series between a Chart and Strategy Analyzer. In general, I've been expecting them to behave the same which is probably part of my problem. Even hard coded secondary data series in a Chart still are quite slow compared to running in SA.

      2. NT seems to frequently hit the server or download data when it doesn't have to. It already has all the data it needs.

      Adding a secondary series will likely trigger historical data to download, which is expected to have some performance impact since that data has to be processed.
      I understand that adding a secondary series will trigger a download of data IF the data is not cached. That makes perfect sense. BUT it often does it, though not always, after hitting F5 in a chart to rerun the strategy on the exact same data. Why does it need to hit the server if the data is cached? And I'm not talking about live data. I'm using a time window that ends on 1/1/2023 so it should not think that live data is needed. Is this just the way things are in a Chart? It will check with the server anyway? Even if it doesn't have to?

      3. Dynamic loading of data series.

      Just to clarify, this is NOT dynamic loading, correct?

      Code:
      bool loadCL = true;
      if (loadCL)
      {
           AddDataSeries("CL 01-24", BarsPeriodType.Minute, 30);
      }
      else
      {
           AddDataSeries(BarsPeriodType.Minute, 30);
      }

      Comment


        #4
        Hello,

        Although you may not be seeing an error, it is still unsupported and adding data series dynamically can have unexpected behavior.

        Even if the data is cached, your strategy still has to process that data which will have some impact on performance. Due to the way NinjaTrader caches historical data and creates strategy instances internally, using dynamic values from variables can break the loading of historical data. Since it cannot work in all situations, it is unsupported.

        Please see the link below to the help guide on what causes historical data to be fetched from the server.

        https://ninjatrader.com/support/help...historicaldata

        On a chart, typically the end date is going to be changing which will trigger NinjaTrader to fetch data. Reloading a script that dynamically adds a data series would also likely cause historical data to be re-fetched.

        ​Also yes, that would be considering dynamically adding a data series. By using an if statement, this can dynamically change what values the parameters provided to AddDataSeries() will have.

        Please let us know if you have any further questions. ​

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        62 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        134 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