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 cmoran13, Yesterday, 01:02 PM
            0 responses
            29 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            21 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            160 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            95 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            148 views
            2 likes
            Last Post CaptainJack  
            Working...
            X