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 CaptainJack, 05-29-2026, 05:09 AM
          0 responses
          51 views
          0 likes
          Last Post CaptainJack  
          Started by CaptainJack, 05-29-2026, 12:02 AM
          0 responses
          31 views
          0 likes
          Last Post CaptainJack  
          Started by charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          99 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          177 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          170 views
          0 likes
          Last Post CarlTrading  
          Working...
          X