Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

protected override void OnTermination()

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

    protected override void OnTermination()

    Hi,

    I want to let a strategy write some data to a file
    at the end of a backtest during an optimization procedure (such as profit factor, number of trades, by accessing the performance tab / tradelist object.)
    .
    For this I thought to use protected override void OnTermination()
    since it's called every time one of the backtests is completed.

    It seems like the method's use is limited to certain actions.
    For example, it seems not to be possible to
    declare variables within the method. The following snippet causes errors:

    Code:
    protected override void OnTermination()
            {
                private string header = "";
                
                Print("header");
            }
    What would be the way to go to force the script to do something at the
    end of every backtest?

    Thanks in advance, Stephan

    #2
    Hi Stephan,

    If you declare the variables in the variables region, then it will be available in all places in the script, even OnTermination()

    If variable use is local to OnTermination(), remove the private qualifier.

    protected override void OnTermination()
    {
    string header = "";

    Print("header");
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Stephan123 View Post
      Hi,

      I want to let a strategy write some data to a file
      at the end of a backtest during an optimization procedure (such as profit factor, number of trades, by accessing the performance tab / tradelist object.)
      .
      For this I thought to use protected override void OnTermination()
      since it's called every time one of the backtests is completed.

      It seems like the method's use is limited to certain actions.
      For example, it seems not to be possible to
      declare variables within the method. The following snippet causes errors:

      Code:
      protected override void OnTermination()
              {
                  private string header = "";
                  
                  Print("header");
              }
      What would be the way to go to force the script to do something at the
      end of every backtest?

      Thanks in advance, Stephan
      Local variables should be declared without an access qualifier.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      639 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      572 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X