Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetTime while backtesting

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

    GetTime while backtesting

    Hi, in my strategy i need the date from today and i access it via "var time = DateTime.Today; ". Unfortunately when backtesting the strategy will always use the "real today" as the "time" and it wont use the actual date that is backtestet.

    How can i get the DateTime from the current bar [0]?
    it wont work like this:

    "var date1 = new DateTime();
    date1 = Time[0];
    Print(date1);
    "
    Also while compiling there is no error. Only when i backtest the strategy there comes an error like that:
    "The object reference was not set to an object instance"
    Thanks for your help
    Felix
    Last edited by FelixMMM; 09-29-2019, 03:12 PM.

    #2
    Hello Felix,

    The Time[0] series is a DateTime object for each bar.

    Below is a link to the help guide.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea,
      i have tried it several times also in different ways.
      Even the official example:
      "Print(Time[0].ToString());" doesnt give an error when compiling.But when i backtest the strategy there comes this error in the output. "The object reference was not set to an object instance". And it comes only if i add that Print() to the OnBarUpdate Method.
      I dont know what to do.
      Thanks Felix

      Comment


        #4
        Hello FelixMMM,

        Are you certain that is the line causing the error?

        Is that line of code in OnBarUpdate()?

        Attached is an export of a simple script with only that line of code in OnBarUpdate().

        Are you able to reproduce the behavior using this reduced test script to test only that code?
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea,
          error is solved. I had the line inside a method that i was calling in Onbarupdate(). When i created a DateTime object inside the OnBarUpdate() method itself and hand over that object to the method i am calling inside OnBarUpdate() the error was gone. I dont know why but that doesnt matter now xD.
          Thanks for your help, appreciate it
          Felix

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          25 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          121 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          64 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X