Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Dispose()

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

    Strategy Dispose()

    I would like to perform some tasks when a strategy running in the Strategies Tab, is stopped, or removed. 'public override void Dispose()' does no seem to be executed inside my strategy on these events. How do I perform cleanup tasks when a strategy is topped or removed?

    #2
    Will report back in the next day while we check into this.
    RayNinjaTrader Customer Service

    Comment


      #3
      Dispose should be called when the strategy is removed. Right now it's not which is a bug. This bug will be fixed with next update (likely early June). Thanks for reporting.

      Unfortunately NT does not support an event for starting/stopping a strategy.

      Comment


        #4
        Progress on Dispose( ) ?

        Hi guys,

        I too would like to run some cleanup code on strategy termination. Was the Dispose() bug fixed in 6.5.1000.3. If not when is it likely to be fixed?

        If you have any other suggestions for how to run code automatically once a strategy has been terminated I would welcome your suggestions.

        many thanks

        Comment


          #5
          Yes, is fixed.
          RayNinjaTrader Customer Service

          Comment


            #6
            Hi guys,

            I tried calling Dispose but its behaviour is not what I would have expected. This is how I've implemented it.

            public class myStrategy : Strategy
            {
            // variables go here
            // Initialize() goes here.

            public override void Dispose( )
            {
            // do useful things here

            MessageBox.Show( "Dispose() called." );
            base.Dispose( );
            }

            // OnBarUpdate goes here.
            }

            When I use Strategy Analyzer and execute the strategy in a backtest, the message box doesn't show once the strategy has finished running through all the data. If I then click on my chosen instrument and execute the backtest again, the message box does show and in fact does so 3 times before running the backtest.

            Am I not using this properly or is there some other explanation?

            many thanks

            Comment


              #7
              Please see this reference for how Dispose should be used: http://www.ninjatrader-support.com/v...ead.php?t=5965
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Sorry Josh but that doesn't help.

                I am already using Dispose() as demonstrated in your reference sample. It doesn't seem to be called unless I want to run a backtest on a strategy again.

                This suggests to me that in Strategy Analyser if you run a backtest, the strategy object is not destroyed even though it has run through the prescribed data set. Only when you want to run a backtest again does Dispose() seem to be called.

                Is there any other method I can use that can guarantee to execute code once the run through a data set in Strategy Analyzer is complete?

                many thanks

                Comment


                  #9
                  Expected behavior, since the strategy needed to stay in memory for reporting (clicking through tabs) until you decide to run a new backtest.

                  Unfortunately there is no other method to be called as backtest is finished.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  582 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  338 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  103 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  554 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  552 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X