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 Stanfillirenfro, Today, 07:23 AM
      8 responses
      23 views
      0 likes
      Last Post Stanfillirenfro  
      Started by DayTradingDEMON, Today, 09:28 AM
      2 responses
      15 views
      0 likes
      Last Post DayTradingDEMON  
      Started by navyguy06, Today, 09:28 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      8 responses
      32 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by helpwanted, Today, 03:06 AM
      2 responses
      22 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Working...
      X