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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X