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

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

          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?

              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.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by funk10101, Today, 12:02 AM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by GLFX005, Today, 03:23 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by nandhumca, Yesterday, 03:41 PM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by The_Sec, Yesterday, 03:37 PM
                  1 response
                  11 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by vecnopus, Today, 06:15 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post vecnopus  
                  Working...
                  X