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

How I can check current time ???

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

    How I can check current time ???

    Hello

    I want send orders when current time of my PC will be like 19.20
    I`m using function Now to compare current time with these constants (int Var1=19, int Var 2=20) like:

    Code:
    if (Now.Hour == Var1 && Now.Minutes ==Var2) =>Open Order


    But (Now.Minutes) always not equal system minutes.
    I`m did it and in OnBarUpdate and inside OnMarket. The same result!

    I don`t understand why !? How I can check current time ??

    #2
    Hello sergey_z,

    I would recommend using the ToTime() method.

    Below is a link to the help guide.


    For example:
    Code:
    if (ToTime(Time[0]) == 192000)
    {
    //execute code
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Ok, thanks.
      But I`m using H1 time-frame and I want open order inside H1 bar. For Time[0] minutes will be =0 inside hour. So, I need to know current minutes.

      Comment


        #4
        Hello sergey_z,

        I'm not understanding what you mean by H1 time-frame.

        However, ToTime() works with any DateTime object.

        DateTime.Now is the PC Clock time.

        Time[0] is the close time of the bar.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello sergey_z,

          I'm not understanding what you mean by H1 time-frame.

          However, ToTime() works with any DateTime object.

          DateTime.Now is the PC Clock time.

          Time[0] is the close time of the bar.
          And why DateTime.Now.Minutes not equal PC clock minutes?? . I`m using Dataseries 60Minutes

          Click image for larger version  Name:	5dca896c5b.png Views:	1 Size:	2.6 KB ID:	1045378

          Comment


            #6
            Hello sergey_z,

            DateTime.Now will not be using the dataseries on your chart. This ignores all bar information and just returns the time of your PC Clock.

            .Minutes (with a plural s) is not a valid property of DateTime objects.

            DateTime.Now.Minute would return the minute value of the PC Clock.

            Below is a link to a video that demonstrates.



            If you want to compare the bar time to a specific time to trigger an action, use ToTime(Time[0]).
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              ok. so If my Main timeframe(Dataseries) is 60minute and I need to know current time with minutes- I have to use second Dataseries with value=1minute for use Time[1][0]?
              I`m right?

              Comment


                #8
                Hello sergey_z,

                If you use DateTime.Now, this will not reflect bar information in anyway. This will only reflect the time of the PC Clock.

                If you are wanting intra-bar granularity for bar times that are smaller than the primary series, then yes, you would need to add a secondary series for those bar times.

                Below is a link to a forum post on intra-bar granularity.

                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, Yesterday, 09:53 PM
                2 responses
                49 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                192 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,234 views
                0 likes
                Last Post xiinteractive  
                Working...
                X