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

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.

    Converts the value of the current DateTime object to its equivalent string representation.




    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.

      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 prdecast, Today, 06:07 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by Christopher_R, Today, 12:29 AM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by chartchart, 05-19-2021, 04:14 PM
                3 responses
                577 views
                1 like
                Last Post NinjaTrader_Gaby  
                Started by bsbisme, Yesterday, 02:08 PM
                1 response
                15 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by i019945nj, 12-14-2023, 06:41 AM
                3 responses
                60 views
                0 likes
                Last Post i019945nj  
                Working...
                X