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;
    JesseNinjaTrader Customer Service

    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 gyilaoliver, Today, 08:28 AM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Darkslide_Tom, 03-23-2025, 11:08 PM
      3 responses
      17 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by rtwave, 03-13-2025, 04:09 PM
      4 responses
      29 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by MiCe1999, 12-01-2024, 09:01 PM
      4 responses
      45 views
      0 likes
      Last Post Leeroy_Jenkins  
      Started by coopgrafik, Today, 07:57 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Working...
      X