• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DateTime.Now

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

    DateTime.Now

    Hi, I need to compare the current time (I'm assuming that's contained in DateTime.Now) to an integer field in the forma HHmmss (military format). How do I convert DateTime.Nowinto an integer to make that comparison. thank you!

    #2
    Hello,

    Thank you for the question.

    In NinjaTrader there is the ability to use c# standard DateTime.Now (computer time) or there is also the bars time or Time

    If you are doing chart time comparisons you would want to use the Time object in NinjaTrader to ensure you are getting the correct times for the bar you are looking at.

    The Current bars time in NinjaTrader is:

    Code:
    Time[0]
    you can do comparisons with the Time object using integers by using ToTime or ToDay

    Time is just a datetime object except it is a series which you can use a BarsAgo value with much like the rest of the Price data objects in NinjaScript.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by FCatan View Post
      Hi, I need to compare the current time (I'm assuming that's contained in DateTime.Now) to an integer field in the forma HHmmss (military format). How do I convert DateTime.Nowinto an integer to make that comparison. thank you!
      Look up ToTime(). The output is military time, albeit NT does not actually say so.

      Comment


        #4
        Strategy delay by a couple of seconds

        I see on session template that you cannot change the session to 09:30:04 for example... is there a way to do this in code?


        if(ToTime(Time[0]) < 093004)
        return;

        doesnt work on my 390 minute chart based strategy.

        Regards and thx for assistance.

        Comment


          #5
          Hello everington_f,

          Thank you for your post.

          There would not be a way to do this in the Session Manager. And when using Minute bars, the timestamp will always be to the minute.

          You could add a 1 Tick series and then check against it. For example:
          Code:
          if(ToTime(Times[1][0]) < 093004)
          For information on multiple time frames in code please visit the following link: http://ninjatrader.com/support/helpG...nstruments.htm
          Patrick H.NinjaTrader Customer Service

          Comment


            #6
            or perhaps on the 390 minute primary chart series

            if bars.tickcount < 10;
            return;


            ?

            Comment


              #7
              Hello everington_f,

              This would not be the same, could you provide context to why you are using TickCount?
              Patrick H.NinjaTrader Customer Service

              Comment


                #8
                it was just an idea, I have a multi instrument strategy with ADD() 50 stocks... i just want to delay entry a couple of seconds until I am sure that all data is coming in..... i have found that if I fire it at 093000 some stocks trade as if it were yesterday... because the primary bar series is updating.. but other less liquid members of the list come on line a fraction later... and hence execute falsely.

                Could i use

                !Historical ? but how do i reference the bars in progress index for that?
                Last edited by elliot5; 07-10-2015, 10:05 AM.

                Comment


                  #9
                  Hello everington_f,

                  Thank you for your response.

                  You would use the following as an example:

                  Code:
                  if(BarsInProgress == 0 && !Historical) // primary series is no processing historical bars.
                  Patrick H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by indy73, Yesterday, 10:52 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post indy73
                  by indy73
                   
                  Started by martyn73, Yesterday, 07:04 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post martyn73  
                  Started by sergey_z, Yesterday, 02:56 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by samir, Yesterday, 02:46 PM
                  1 response
                  20 views
                  0 likes
                  Last Post NinjaTrader_Kate  
                  Started by neoikon, Yesterday, 02:24 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_ChristopherJ  
                  Working...
                  X