• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Increase memory usage during Optimization for indicators with Draw

  • Filter
  • Time
  • Show
Clear All
new posts

    Increase memory usage during Optimization for indicators with Draw

    Hey guys -

    I wanted to report an issue that I found.

    When you Optimize a strategy using an indicator with the Draw object, the Optimization/Strat Analyzer will consume all physical memory until the system slows to a crawl.

    I've attached a Test Script and a test indicator so you can see the problem. The script was built off the Sample MA Crossover with the only additions being the DM and DMArrow references. The DM Arrow indicator is simply the DM indicator with the Draw Arrow lines added.

    Steps to duplicate:
    1. In your test script, make sure the 2 DMArrow lines are commented out.
    2. For the Optimization settings, see attached graphic for what I used. I just wanted something large enough so you can see the memory usage within a few minutes.
    3. Start optimization. Open Task Manager and monitor the NJT exe memory usage. You can see that NJT will continually 'cleanup' its memory usage after a few minutes of running.
    4. Once you see the memory cleanup process happening, hit Abort.
    5. Edit the TestScript strategy and comment out the DM indicator and remove the comments from the 2 DMArrows lines. Compile.
    6. Run the optimization again and watch the resource utilization and notice that it doesn't cleanup. It just continues until you hit your max physical memory.
    7. Hit Abort when you're done looking.

    PS. While running this test, after you hit Abort before the test concludes, you may see the same error I reported a while back:

    Unhandled exception: Value does not fall within the expected range.

    This seems to occur when you Abort a large Optimization test. The error will keep occurring until you reboot your desktop. So, this is an additional error outside of the memory leak.
    Attached Files

    Thanks for the report PN720,

    I'm looking into the memory issue on my end and will write back after I have been able to fully analyze.

    I have not been able to reproduce the Unhandled Exception error yet. I'll include this note in a report, but if you are able to come up with similar steps to reproduce, it can help to lead the development team towards a fix.

    EDIT: I've done some profiling and I've created an internal ticket. The memory utilization looks to be expected due to the default garbage collection, but I am clarifying and also looking into the number of iterations that are completed.

    I'll keep you posted on my findings with this issue.
    Last edited by NinjaTrader_Jim; 09-12-2018, 07:17 AM.
    JimNinjaTrader Customer Service


      Thanks for your patience PN720.

      QA has reported back that this performance impact is expected.

      Optimizations will run numerous iterations and can effectively create numerous drawing objects. The system will eventually run out of memory which effects performance and then we will have to wait for garbage collection to clean up before the backtest can continue.

      Generally speaking, drawing tools do carry a performance impact and drawing tools that are only used for visual purposes should not be used in optimization backtests.

      You may use some code like the example linked below to detect if you are running an optimization backtest and control using drawing tools in your script.


      We have not been able to reproduce the unhanded exception, so please let us know if this is still an on going issue that we should troubleshoot.
      JimNinjaTrader Customer Service


        Hi Jim,

        Thanks for the confirmation about the memory leak. I'll just work around it by excluding the Draw objects when I do Optimizations.

        For that Unhandled Exception error, I'm still seeing it intermittently after an Optimization is complete. For example, today I just completed a Walk Forward Optimization and as soon as I clicked on the taskbar to switch windows back to the Control Center, I see the error. The Optimization was running on one of my custom strategies at the time. I switched to the Sample MA Crossover and still saw the error.

        I've reported this before and the error will only clear when I reboot. You can't just restart Ninjatrader as it returns anytime you want to switch NJT windows.

        Here's what the error looks like:



          Hello PN720,

          I'd like to work with you closer on this matter through email. Could you send me a message to platformsupport [at] ninjatrader [dot] com with the text "Attn Jim" and a link to this thread?

          Thanks in advance, I look forward to troubleshooting this further.
          JimNinjaTrader Customer Service


          Latest Posts


          Topics Statistics Last Post
          Started by giogio1, 11-10-2019, 11:23 PM
          4 responses
          Last Post bltdavid  
          Started by Dolosumo, Today, 01:05 AM
          0 responses
          1 view
          Last Post Dolosumo  
          Started by StevenNelson, Yesterday, 07:31 PM
          1 response
          Last Post NinjaTrader_ChrisSch  
          Started by dtl-saw, Yesterday, 09:37 PM
          0 responses
          Last Post dtl-saw
          by dtl-saw
          Started by TazoTodua, Yesterday, 03:01 PM
          3 responses
          Last Post TazoTodua