Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get From/Until of backtest

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

    Get From/Until of backtest

    How can I get From / Until date values from backtest programatically ?
    (I mean start / end datetime of backtest, which are set in backtest settings)

    #2
    Hi misova,

    While I am not aware of any undocumented (or documented) way of reading the Start date and End date when running a backtest directly, a work around would be to read the first and last bar's time.

    (edited to NinjaTrader 7 code)
    Code:
    protected override void OnStartUp()
    {
    	Print(string.Format("startTime: {0} | endTime: {1}", Bars.GetTime(0), Bars.GetTime(Count - 1) ));
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hi misova,

      While I am not aware of any undocumented (or documented) way of reading the Start date and End date when running a backtest directly, a work around would be to read the first and last bar's time.

      (edited to NinjaTrader 7 code)
      Code:
      protected override void OnStartUp()
      {
      	Print(string.Format("startTime: {0} | endTime: {1}", Bars.GetTime(0), Bars.GetTime(Count - 1) ));
      }
      Thank you, this solution works.

      By trial and error I found, these properties work and they are the exact values put into the GUI properties:
      • Strategy.BackTestFrom
      • Strategy.BackTestTo

      Comment


        #4
        Hi misova,

        I am not able to compile a strategy using that code.

        Attached is an uncompilable test script.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          Here is the quick fix: remove the "Strategy."

          I wrote Strategy.XXX just to underline idea, that XXX can be invoked on the Strategy class. That could cause confusion.

          Here is the corrected line (and full code in attachment):
          Code:
          Print(string.Format("{0} | {1}", BackTestFrom, BackTestTo));
          Best regards
          Misova
          Attached Files

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          563 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          329 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
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X