Announcement

Collapse
No announcement yet.

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

        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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          157 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          91 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          143 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          131 views
          1 like
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          107 views
          0 likes
          Last Post CarlTrading  
          Working...
          X