Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Memory bug when WFA optimizing

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

    Memory bug when WFA optimizing

    Hi there, I recently noticed that there may be an issue with memory allocation when running back testing. I noticed that the memory utilisation of my windows VPS increases steadily until the whole application crashes and no memory is left .

    I’ve tried this on different machines and always observe the same outcome.

    One of the main reasons I purchased a license was to be able to do complex backtesting. How can I troubleshoot this?

    Thanks!


    #2
    Hi Oracletrades,
    I'm more than happy to be corrected here, but I'm afraid Optimization can use UNLIMITED memory and crash. It might (still) be possible to limit the number of iterations running in parallel using the (undocumented) WaitForIterationsCompleted() command. However, individual users should not have to deal with "debugging" NT from my point of view. RAM Control is a must have, particularly for such software.
    NT-Roland

    Comment


      #3
      Hello Oracletrades,

      With many backtest iterations of an optimization this may require very large amounts of memory.

      If this is a script you have written, I recommend modifying the script to take advantage of IsInstantiatedOnEachOptimizationIteration being set to false. This will reduce the amount of backtest instances being generated in memory for each iteration.
      https://ninjatrader.com/support/help...niteration.htm

      Objects should only be initialized in State.DataLoaded when absolutely necessary, existing objects that can be reset like arrays should be cleared / reset instead of new objects initialized. All variables will need to be reset to an initial value.

      Below is a link to an example that demonstrates the effect of IsInstantiatedOnEachOptimizationIteration.
      After I run the Optimization in Strategy Analyzer, the top results are displayed in a table. The table columns such as Net Profit, Percent Profitable, etc.. However the values displayed in the table is incorrect and inconsistent with the actual values shown in the "Summary" when you select a set of parameter. See the


      Further, the IncludeTradeHistory can make a huge performance impact. If the script is not using the SystemPerformance collection, setting IncludeTradeHistory to false in State.Configure can dramatically improve backtest and optimization performance.
      https://ninjatrader.com/support/help...inbacktest.htm

      If the script is making a lot of Draw method calls, this can also have a large impact. Disabling draw method calls when the script is in the Strategy Analyzer can reduce this impact.
      https://ninjatrader.com/support/help...gyanalyzer.htm

      If this is not a script you have made, I would recommend contacting the vendor or author and requesting these changes.
      Last edited by NinjaTrader_ChelseaB; 12-20-2022, 09:07 AM.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you Chelsea, Roland. I wasn't aware of that script and assumed that NT would do that automatically. I have 24 GB of RAM on the machine and was running 100.000 iterations which is quite common when you have 4-5 variables... Will try what you suggest above and revert.

        Comment


          #5
          Hi everyone, just a follow-up to this post. Quite frankly, the proposed solution is too complicated for me to implement and understand. Therefore, I did the following (in case anybody ever has the same issue):

          - increased the Windows Paging file to 16GB
          - as I am on a SSD, the read/write speeds are sufficient for the backtesting (it slows down a bit, but time is not my issue)

          Cheers!

          Comment


            #6
            SOLUTION: to anybody coming across this post, please just remove any "drawing" objects like arrows from the strategy. The memory leakage will stop and your strategy will run, even with 1.000.000 iterations (just doing this on a 16GB RAM machine).

            Took me a few weeks. Support, please take note of this solution, it was mentioned in a few other posts.

            FEATURE REQUEST: for future releases, can you consider "disabling" the drawing of objects in the strategy analyzer when doing optimizations, entirely? There is no value anyway during the optimization process and it solves the memory hog problem without the need of coding anything.

            Comment


              #7
              Hello Oracletrades, thanks for your reply .

              You can use IsInStrategyAnalyzer to ignore drawing draw objects while backtesting/optimizing:

              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by Oracletrades View Post
                SOLUTION: to anybody coming across this post, please just remove any "drawing" objects like arrows from the strategy. The memory leakage will stop and your strategy will run, even with 1.000.000 iterations (just doing this on a 16GB RAM machine).
                Took me a few weeks. Support, please take note of this solution, it was mentioned in a few other posts.
                FEATURE REQUEST: for future releases, can you consider "disabling" the drawing of objects in the strategy analyzer when doing optimizations, entirely? There is no value anyway during the optimization process and it solves the memory hog problem without the need of coding anything. https://givology.org/~GabrielBlocker/blog/326896/
                Hi! Thanks for the suggestion: I've managed to stop memory leakage by removing "drawing" objects. But is it some kind of bug? I didn't find it on a list.

                Comment


                  #9
                  Hello mcrobertg7,

                  Drawing object method calls all create new instances of the drawing object which all need need memory locations whether or not they will be drawn.
                  This is not a leak. This is the number of objects being created by the strategy that is calling the methods for these.
                  To avoid the drawing objects from being created, do not call the draw method during historical data or specifically when in the strategy analyzer.

                  Any objects created by a strategy will need memory locations.

                  This also involves using IsInstantiatedOnEachOptimizationIteration set to false where the variables should be initialized only when null in State.DataLoaded and reset when possible to save memory.

                  Below is a link to the help guide.


                  Below is a link to a thread where this is mentioned.
                  https://ninjatrader.com/support/foru...39#post1069339
                  Last edited by NinjaTrader_ChelseaB; 06-23-2022, 07:39 AM.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NT-Roland View Post
                    Hi Oracletrades,
                    I'm more than happy to be corrected here, but I'm afraid Optimization can use UNLIMITED memory and crash. It might (still) be possible to limit the number of iterations running in parallel using the (undocumented) WaitForIterationsCompleted() command. However, individual users should not have to deal with "debugging" NT from my point of view. RAM Control is a must have, particularly for such software.
                    NT-Roland
                    Hi Oracletrades - any chance you could share with me more info on the WaitForIterationsCompleted() command? - would be much appreciated!
                    DTBTraders
                    NinjaTrader Ecosystem Vendor - dtbtraders.com

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Rapine Heihei, Today, 08:19 PM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 08:25 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post Rapine Heihei  
                    Started by f.saeidi, Today, 08:01 PM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 07:51 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Rapine Heihei  
                    Started by frslvr, 04-11-2024, 07:26 AM
                    5 responses
                    96 views
                    1 like
                    Last Post caryc123  
                    Working...
                    X