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.
    https://ninjatrader.com/support/help...eries_time.htm
    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 Jeremytang, 07-14-2018, 06:45 PM
          21 responses
          439 views
          0 likes
          Last Post mav8rick  
          Started by LeonK, Yesterday, 09:26 PM
          1 response
          7 views
          0 likes
          Last Post bltdavid  
          Started by NicholasJoannette, Yesterday, 03:01 PM
          2 responses
          11 views
          0 likes
          Last Post NicholasJoannette  
          Started by rach1994, Yesterday, 12:20 PM
          1 response
          35 views
          0 likes
          Last Post bltdavid  
          Started by litamm89, Yesterday, 11:00 AM
          5 responses
          21 views
          1 like
          Last Post rafael_delima86  
          Working...
          X