• 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

Date and Time Formatting; Day of Week

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

    Date and Time Formatting; Day of Week

    Howdy All--

    I've built myself an indi that when a trade occurs, it prints various things about the trade to several lists, that I then print out to the output window for use in Excel.

    I'm currently using the following code to add the date and time of the trade:

    Code:
    listDate.Add(ToDay(Time[0]));
    listTime.Add(ToTime(Time[0]));
    Which in turn output:

    20130907 (ie, 09/07/2013)
    155759 (ie, 3:57:59p)

    I was curious if anyone had a slick way of formatting the above code to format the outputs accordingly:

    ToDay(Time[0]) --> mm/dd/yyyy --> EX: 9/7/2013 (ie, not 09/07/2013)
    ToTime(Time[0]) --> hh:mm am/pm --> EX: 11:15 am or 2:13 pm (ie, no seconds and not 02:13 pm)

    Also, I was curious if anyone knew of a way to grab the day of week from the Time[0] property.

    Finally, I would need to know what list type the newly formatted items would be (ie, int, double, string). For instance, ToDay() and ToTime() are current lists of type int, but would the newly formatted lists be of type string? Also, would the weekday list be a type string?

    I know, pretty boring stuff, but I appreciate your help if you have the time.

    Thanks for your help!

    Aventeren

    #2
    Googling "c# formatting date time" returns a lot of results.

    http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx



    Originally posted by aventeren View Post
    Howdy All--

    Also, I was curious if anyone knew of a way to grab the day of week from the Time[0] property.

    Finally, I would need to know what list type the newly formatted items would be (ie, int, double, string). For instance, ToDay() and ToTime() are current lists of type int, but would the newly formatted lists be of type string? Also, would the weekday list be a type string?

    I know, pretty boring stuff, but I appreciate your help if you have the time.

    Thanks for your help!

    Aventeren

    Comment


      #3
      Hello Aventeren,

      Thank you for your post.

      I would recommend familiarizing yourself with the C# DateTime structure: http://msdn.microsoft.com/en-us/libr....datetime.aspx

      You may need to do these conversions on your own through the script.

      Please let me know if I may be of further assistance.
      Patrick H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello Aventeren,

        Thank you for your post.

        I would recommend familiarizing yourself with the C# DateTime structure: http://msdn.microsoft.com/en-us/libr....datetime.aspx

        You may need to do these conversions on your own through the script.

        Please let me know if I may be of further assistance.
        Thanks, Patrick; I figured out a slick way to do it, and perhaps this will help other users in the future.

        I had been adding dates to the trade list, which I had initially created as an int type list, by:

        listDate.Add(ToDate(Time[0]));

        However, what that did was created a yyyymmdd format (ie, 20130910), which wasn't very useful. A little googling revealed that I could instead create the list as a string type list, and then use:

        listDate.Add(Time[0].ToShortDateString());

        The above then formatted the dates as mm/dd/yyyy format (ie, 9/10/2013), which is what I was after.

        Also, although I ended up binning my trades using the C# hhmmss format as the logical reference, I understand that the onboard C# DateTime Method has a similar way to clean up the time formatting via:

        listTime.Add(Time[0].ToShortTimeString());

        --although it should be noted that I did not try the time formatting.

        So in any event, perhaps other users will find this interesting if they are working on a similar problem in the future.

        All best,

        Aventeren

        Comment


          #5
          Formatting ToTime

          I want to Print on "Output Window" the Time with millisecond format.

          I am using Print(ToTime[0].ToString("HH:mm:ss.fff"); but is not printing the millisecond part.

          Is printing "11:23:45.000" , for example.

          What is wrong?

          Comment


            #6
            Originally posted by sasil View Post

            What is wrong?
            NT7 doesn't have millisecond.

            Comment


              #7
              But when you save the Trades of the Account Performance in excel, and format the columns "Input Time" and "Output Time" with "HH: mm: ss, 000" in this case the milliseconds appear.

              In the NT7 it is not possible to print milliseconds only on Output Window?

              Comment


                #8
                Originally posted by sasil View Post
                But when you save the Trades of the Account Performance in excel, and format the columns "Input Time" and "Output Time" with "HH: mm: ss, 000" in this case the milliseconds appear.

                In the NT7 it is not possible to print milliseconds only on Output Window?
                You cannot show data that you do not have.

                Time[0] is a reference to bar data, which has no millisecond component in NT7, because the bar time granularity is up to seconds only: Trades are marked off the system time, which has a much finer granularity.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by alfonso, Today, 10:21 AM
                0 responses
                1 view
                0 likes
                Last Post alfonso
                by alfonso
                 
                Started by saeed, Today, 10:20 AM
                1 response
                3 views
                0 likes
                Last Post saeed
                by saeed
                 
                Started by ntbone, Yesterday, 05:21 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by ntbone, Yesterday, 04:05 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by tonynt, Today, 09:35 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Working...
                X