Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to gracefully terminate backtest in NinjaScript?

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

    How to gracefully terminate backtest in NinjaScript?

    Hello,

    I would like to gracefully terminate backtest in NinjaScript (terminate before the duration of the test period is up), such that all the test results would still show up on the Summary screens on Strategy Analyzer. Please advise how I can achieve that.

    Thanks,

    Billy

    #2
    Hello billythekid72,

    The most simple way would be to make a bool variable and a return statement at the top of OnBarUpdate. That allows the test to finish but stops having to do work. That will still take some time o complete because it still has to run all iterations but that would prevent anything else from happening past that point to let the results be just what was happening before terminating.
    Code:
    private bool isCancelled;
    
    protected override void OnBarUpdate()
    {
        if(isCancelled == true) return;
    
        if(SomeCondition)
          isCancelled = true;

    Comment


      #3
      Thank you, Jesse, I was hoping for something more elegant that would terminate immediately.

      Billy

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      41 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      29 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      46 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      37 views
      0 likes
      Last Post CarlTrading  
      Working...
      X