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

Trying to understand IsInstantiatedOnEachOptimizationIteration and optimization

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

    Trying to understand IsInstantiatedOnEachOptimizationIteration and optimization

    Hello,

    So currently running optimization on some variables in my strategy, and I'm running into a big issue where the optimizer will only be able to handle about 6000 iterations before my RAM memory is maxed out and the program begins to stall very frequently and runtime goes up.

    Specs:
    CPU -Ryzen 7 37000x
    RAM- (2x8) 16 Gb DDR4 3200Mhz

    Couple questions:

    1. How many iterations should my computer reasonable be able to handle with these specs because currently im locked at about 6000-7000 before the program becomes unresponsive and basic functions of the computer begin to stop working.

    2. I saw that people were using

    IsInstantiatedOnEachOptimizationIteration

    to help with performance issues. Looking at the documentation I am still a bit confused however,
    Click image for larger version

Name:	image.png
Views:	163
Size:	40.1 KB
ID:	1221207
    Assuming that I had some variables like these that I use in my strategy, my understanding is that after if (State == State.SetDefaults) in the else if ( State == State.Dataloaded)
    Click image for larger version

Name:	image.png
Views:	127
Size:	14.3 KB
ID:	1221208
    and within this state.DataLoaded i need to manually reset all the variables to use IsInstantiatedOnEachOptimizationIteration correctly? Currently I initialize the values for the variables in onBarUpdate(), would I need to get rid of those or is setting a additonal value in .DataLoaded ok?

    What about the other variables in the State.SetDefaults​ such as: that came with generating a strategy.
    Click image for larger version

Name:	image.png
Views:	102
Size:	133.2 KB
ID:	1221209
    Thank you!
    ​​

    #2
    Hi tchen7, thanks for posting.

    1. The strategy analyzer does not run the garbage collector for performance reasons, so if you have found this to be the upper limit for your hardware, only further optimization of the strategy would be able to help, or just wait longer for the optimization to finish.

    2. The default variables that belong to the class are not used in the logic of the strategy. The example on the IsInstantiatedOnEachOptimizationIteration is to demonstrate how to reset variables that you create that are used in the actual trading logic, because these variables need to be reset manually when IsInstantiatedOnEachOptimizationIteration = false.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hey Chris,

      As a quick follow up,

      1. Would I need to reset my variables even if I never initialized them with a value and only ever assigned them a value in onBarUpdate()?

      2. I was not aware of the garbage collection part, but as per the waiting for the optimization to finish the program eventually takes up too much RAM and my computer becomes unresponsive, im assuming finding this upper bound is a matter of trial and error?

      3. I believe this is true, but I'm guessing removing print statements and chart marking would improve optimization?


      Thanks!

      Comment


        #4
        Hi tchen7, thanks for posting.

        1. There is no need to reset variables that are only set up in OnBarUpdate since they are cleared out after OnBarUpdate is complete each time.

        2. Correct, since all PC's and strategies are different, finding an upper limit for memory is not a one size fits all solution.

        3. That is correct. Print takes up a good bit of performance.

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Another quick follow up,

          Regarding your first answer

          "There is no need to reset variables that are only set up in OnBarUpdate since they are cleared out after OnBarUpdate is complete each time."

          If i do not assign values in (State == State.SetDefaults) Would IsInstantiatedOnEachOptimizationIteration provide any performance increases when running optimization?

          ​​

          Comment


            #6
            Hi tchen7, thanks for posting.

            It would still increase performance because less overall memory is being used. If you do not instantiate a new object every time an iteration occurs, then less memory will be used.

            Kind regards,
            -ChrisL​
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by heiheilau2000, 06-11-2024, 08:32 AM
            6 responses
            23 views
            0 likes
            Last Post heiheilau2000  
            Started by franjcy, Today, 01:23 PM
            0 responses
            9 views
            0 likes
            Last Post franjcy
            by franjcy
             
            Started by tony_28217, Today, 12:55 PM
            0 responses
            6 views
            0 likes
            Last Post tony_28217  
            Started by thumper57, Today, 12:12 PM
            0 responses
            16 views
            0 likes
            Last Post thumper57  
            Started by yertle, Today, 11:03 AM
            0 responses
            8 views
            0 likes
            Last Post yertle
            by yertle
             
            Working...
            X