Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Any way to exit backtest (without waiting for last bar) in C# strategy code?

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

    Any way to exit backtest (without waiting for last bar) in C# strategy code?

    Hello,

    I am running lengthy optimizations with multiple variables on dozens of futures contracts at once, and I would like to greatly speed up the process by by exiting out of the optimization's current backtest (current contract with current set of optimizable variables) before the last intraday bar of market data that is loaded in Ninja Trader for that contract.

    Can I do this in my Ninja Trader C# strategy code?

    More details: I am currently calculating the last date that I would like to test for each contract in the "Initialize()" method of my strategy, and I can write a Print() statement in the "OnBarUpdate()" that says "exit backtest now, since this contract has no more news events on future dates", but I an unable to exit the backtest at this point.

    Thanks in advance!
    ChiTrader2000

    #2
    ChiTrader2000,

    You cannot exit out of a backtest. You can only remove processing of your logic by an overarching if-statement. This will still mean you loop through all data points though. http://www.ninjatrader-support2.com/...ead.php?t=4804
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Josh,

      Thanks for the quick reply. I will "return;" on each OnBarUpate() event, per the samples in the link in your post.

      I am still, however, trying to think outside of the box for ways to make my optimizations run much faster.

      My tests are intraday tests that do not need 1 minute bar data on previous days, and we sometimes only trade a contract on a couple days of the year.

      What if I only imported one or two days of 1 minute bar data per year per contract (import only the days we have orders on), and skipped all the days in between? Would this make Ninja Trader proportionally faster (going from 100 days of data to 2 days)? Do you think that Ninja Trader would still work properly if I did this?

      Thanks again,
      ChiTrader2000

      Comment


        #4
        Hello,

        I will have Josh reply on Monday.
        DenNinjaTrader Customer Service

        Comment


          #5
          Sure. You can try it just don't connect to a data provider while you are doing it.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            NinjaTrader_Josh,

            Thanks for the info. I will give it a try.

            ChiTrader2000

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            558 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X