Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 helpwanted, Today, 03:06 AM
          1 response
          7 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          7 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          5 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          384 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X