Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

System.OutOfMemoryException

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

    System.OutOfMemoryException

    Good morning all!
    While backtesting I had this exception, I think this is due to the amount of data I was testing, maybe something like a timeout, but after that I'm unable to start testing strategies again, maybe I need to reboot NT?!?!?
    Is there some way to backtest a huge amount of data? maybe by using a NT backtest version w/o scripting timeout?

    Thanks for suggestions
    Marce
    Attached Files

    #2
    Sorry, not sure what you mean by "scripting timeout".

    Comment


      #3
      Ciao Dierk,
      I was testing a strategy and during backtesting (after some minutes) I had the exception, what I'm meaning is that it seems the backtest was too long to be managed

      Thanks for your time
      Marce

      Comment


        #4
        I see. The only option available is to backtest less data.

        Comment


          #5
          It could be really interesting having a NT backtest version, only for intensive systems backtests
          Marce

          Comment


            #6
            Thanks for your suggestion. We'll add it to the list.

            Comment


              #7
              I've run into these issues myself. Essentially, any run, if you put enough data or combinations of parameters into it, will run out of memory at some point.

              You may or may not have already done this, but a couple of rounds of optimizing your code will go a long way. Some of the things I did:

              1. Optimize your indicators. For example, if you are using two or more indicators, copy the code out of them into one. Fewer objects will be created this way. Or, if the indicators have plots you are not using, leave those out of your optimized indicator.

              2. Be careful about creating objects. If you need to make 2 calls to SMA(), for example, just save the results in a local variable and use it twice.

              3. Don't print anything using the Print statement. I always add a parameter to my strategies called IsBacktest and check this before printing.

              4. I also run into cases where some of my parameter combinations don't make sense. (Just as an example, let's say you are going to test a moving average crossover using ranges 4-10 and 9-20...it doesn't make sense to test the pair 10,9.) To avoid this, I created my own optimizer class and don't run those combinations at all.

              Some of these things are not ideal from a design perspective, but any additional data I can get out of backtesting runs greatly increases my productivity.

              Comment


                #8
                Thanks for the feedback.

                Comment


                  #9
                  Pete, thanks for that info ! nex codes I will try to be as "clean and fluid as possible".
                  Marce

                  Comment


                    #10
                    In my testing, the biggest cause of "out of memory" has been excessive use of the Print statement.

                    I suggest clearing the Output window before starting each backtest. In some cases this will be enough, in other cases you may wish to do as Pete has suggested and limit your output during backtesting.

                    Comment


                      #11
                      Something I noticed, backtesting minutes strategies, by making tests with different parameters, example strategy A (par x par y par z) test on a 5 year of 5 minutes, after results test again changing inputsm then again. I noticed that remains too many memory used, so I have to reboot ninja and everything starts working fine again....IT'S A STRESS TEST to Ninja.
                      Just regarding memory usage and stress test...I imported txt files of TBT data w/o any sort of freez or something like that, fies big 160 mb + each one.
                      MB

                      Comment


                        #12
                        To isolate the cause of trouble I suggest running any stress test first of our standard MASampleCrossOver. This eliminates any potential issue you could have with your actual strategy code.

                        Comment


                          #13
                          Yes, I have also noticed this. I forgot to mention I experimented with running the .net garbage collector myself at various intervals during the run, with no noticable benefit.

                          It will happen on the simplest of strategies, although I haven't specifically tested with the SampleMA one. If you use Process Explorer to monitor the app's virtual and heap sizes you can predict when you're going to start running into issues (http://www.microsoft.com/technet/sys...sexplorer.mspx) and do a preemptive restart.

                          This actually prevents me from doing strategy development during trading hours as I can't afford to have a crash while my strategies are running live.

                          However, I have accepted this as a fact of life for now as I doubt there is much the NT team can do about this.

                          Comment


                            #14
                            Thanks for feedback. Please let us know as you can reproduce issue using MASampleCrossOver.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by andrewtrades, Today, 04:57 PM
                            1 response
                            8 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by chbruno, Today, 04:10 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post chbruno
                            by chbruno
                             
                            Started by josh18955, 03-25-2023, 11:16 AM
                            6 responses
                            436 views
                            0 likes
                            Last Post Delerium  
                            Started by FAQtrader, Today, 03:35 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post FAQtrader  
                            Started by rocketman7, Today, 09:41 AM
                            5 responses
                            19 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Working...
                            X