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

ToDay & ToTime

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

    ToDay & ToTime

    I am recording a log and I need to register the date and the hour of event.

    I am using " string Key = ToDay(Time[0]).ToString() + ";" + ToTime(Time[0]).ToString() + ";" ..."

    What is recorded is a date of two days ago and a time that I do not know where it comes from.

    What should I do?

    #2
    Originally posted by sasil View Post
    What should I do?
    Try something like this,
    Code:
    Time[0].ToString("M/d/yy HH:MM:ss");
    See here for more examples:
    Learn to use custom date and time format strings to convert DateTime or DateTimeOffset values into text representations, or to parse strings for dates & times.
    Last edited by bltdavid; 06-15-2016, 05:15 PM.

    Comment


      #3
      Originally posted by sasil View Post
      I am recording a log and I need to register the date and the hour of event.

      I am using " string Key = ToDay(Time[0]).ToString() + ";" + ToTime(Time[0]).ToString() + ";" ..."

      What is recorded is a date of two days ago and a time that I do not know where it comes from.

      What should I do?
      Take off the ToString?

      Code:
      " string Key = ToDay(Time[0]) + ";" + ToTime(Time[0]) + ";" ..."

      Comment


        #4
        Hello sasil,

        Thanks for your post.

        If you haven't already gotten an answer regarding the use of time, using Time[0] will provide the end time of the current bar and if you are using long time frame bars the log may not accurately reflect the event time.

        If you are needing real time, you can use Print ("Date-Time: "+DateTime.Now); example: Date-Time: 6/16/2016 6:23:27 AM

        Member bltdavid provided a link for reference, here is another link of examples: http://www.dotnetperls.com/datetime
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your replies.
          I think I found the problem of the date and time wrong. I was running my routine into the OnStartup (). Now I put in the OnBarUpdate () and the date and time are correct.
          Now I will try to hit the formats.
          Thanks...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sightcareclickhere, Today, 01:55 PM
          0 responses
          1 view
          0 likes
          Last Post sightcareclickhere  
          Started by Mindset, 05-06-2023, 09:03 PM
          9 responses
          258 views
          0 likes
          Last Post ender_wiggum  
          Started by Mizzouman1, Today, 07:35 AM
          4 responses
          18 views
          0 likes
          Last Post Mizzouman1  
          Started by philmg, Today, 01:17 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by cre8able, Today, 01:01 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X