Announcement

Collapse
No announcement yet.

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:	243
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:	202
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:	166
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

    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

        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​

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            81 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            150 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            79 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            52 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            59 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X