Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 LawrenHom, Today, 10:45 PM
      0 responses
      3 views
      0 likes
      Last Post LawrenHom  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      37 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Working...
      X