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

Possible error with DateTime in beginning of chart?

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

    Possible error with DateTime in beginning of chart?

    Guys,

    I think there may be a possible bug with DateTime when I try to set a DateTime object to a time before the chart begins.

    My chart session begins and ends at 12:00:00 am, I'm trading FX.

    My code is this:

    DateTime today = new DateTime(Time[0].Ticks);
    DateTime yesterday = new DateTime();
    yesterday = today.AddDays(-1);
    DateTime openingBell = new DateTime(yesterday.Year, yesterday.Month, yesterday.Day, 16, 0, 0);
    barsAgo = GetBar(openingBell);

    when backtesting, I Print("Opening Bell was at " + + Time[barsAgo].ToString() ); and I get 12:00:00, not 16:00:00 on the previous day.

    #2
    Not sure why you are doing this: DateTime today = new DateTime(Time[0].Ticks);

    Time[0] is already a DateTime.

    I suggest you debug what values you are actually getting for barsAgo. Then actually go back in the chart to that bar and see what the time stamp is on it.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      DateTime(Time[0]) won't compile

      Originally posted by NinjaTrader_Josh View Post
      Not sure why you are doing this: DateTime today = new DateTime(Time[0].Ticks);

      Time[0] is already a DateTime.

      I suggest you debug what values you are actually getting for barsAgo. Then actually go back in the chart to that bar and see what the time stamp is on it.

      Thanks Josh, but DateTime(Time[0]) won't compile. the problem seems to be that if my session start is say, 4:00pm, the day before the chart actually begins, (I set the date range for the back test to 8/3/09, for example so at 2:00 am on 8/3/09, the session began at 4:00pm on 8/2/09) then the system gives me a start time of 12:00:00 am instead of what I explicitly set.

      My CalculateOnBarUpdate = false. I think I get different behavior when it's set to true too.

      Comment


        #4
        Why are you trying to go DateTime(Time[0])? It already is a DateTime containing all methods and properties of a DateTime.

        DateTime someOtherDT = Time[0].AddDays(-1);
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          Why are you trying to go DateTime(Time[0])? It already is a DateTime containing all methods and properties of a DateTime.

          DateTime someOtherDT = Time[0].AddDays(-1);

          Damn, sorry. I thought I tried it and it didn't work. I must have done something wrong. sorry.

          Comment


            #6
            anyway, I still think there's an issue when the GetBar() tries to evaluate a DateTime that's off the chart.

            Comment


              #7
              GetBar() evaluates the DateTime you pass into it and gets the nearest bar number related to that DateTime. Maybe this reference can be of some use: http://www.ninjatrader-support2.com/...ad.php?t=19176
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Ok, thanks Josh, that explains it. I have seen GetBar() return 0 too. Is that the "cannot evaluate" response?

                Comment


                  #9
                  Correct. Or if the time you passed in is in the future.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Cool, thank you.

                    I have to say, after dealing with trading technologies, CQG and that "not so easy" language, you guys are the best support team out there.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bortz, 11-06-2023, 08:04 AM
                    47 responses
                    1,604 views
                    0 likes
                    Last Post aligator  
                    Started by jaybedreamin, Today, 05:56 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post jaybedreamin  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    6 responses
                    18 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by Jon17, Today, 04:33 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post Jon17
                    by Jon17
                     
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    13 views
                    0 likes
                    Last Post Javierw.ok  
                    Working...
                    X