Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

time to string

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

    time to string

    Hello,

    sorry that question, looked in help guide but cant find an answer why in my email is shown only the hour like 1:00:00 PM but not the minutes with

    string text = subject + " at " + Time[0].ToString();

    Thank you
    Tony

    #2
    More than likely the Time[0] was at 1:00:00 PM exact.

    What timeframe are you running this on?

    Comment


      #3
      Hello,

      thank you for your reply. 15 min chart.

      The indicator is set COBC to false and I receive the email with gmail correctly after condition met.

      But in the email is showing the time only with 1:00:00.

      What should I code for having 1:12:34 instead of only 1:00:00?

      Thanks
      Tony

      Comment


        #4
        So the Time[0] is going to be the timestamp of the bar in which is the current bar you are working on but doesn't reflect the most current time from the PC clock

        If you want the exact time that it occurred and email was sent then use DateTime.Now.ToString()

        Comment


          #5
          Hello,

          thank you for your reply. But then I have Date + Time (so missing other informations in the line on my mobile then)

          Isn´t it possible to have "normal" time with hour:minute(:second) and not a.)only the hour or b.)time together with date?

          Thanks
          Tony

          Comment


            #6
            Just make a custom ToString for it.

            ToString("HH:mm:ss")

            https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

            Comment


              #7
              Hi Tony,

              You can format your datetime to a string showing seconds.

              Below is a link to microsoft's website on datetime tostring formats.
              https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

              For example:

              Print(Time[0].ToString("M/d/yyyy h:mm:ss"));
              or
              Print(DateTime.Now.ToString("M/d/yyyy h:mm:ss"));

              However, keep in mind if you are printing the bar time and the bar closes on the minute, the seconds will be 0.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello,

                thank you for your reply.

                I dont refer to the seconds.

                Simply hour:minute (and-not-important-if-seconds)

                Untill now I have

                * Hour

                * Date hour minute seconds

                but not simply the correct time (without date)

                Best
                Tony


                Originally posted by NinjaTrader_ChelseaB View Post
                Hi Tony,

                You can format your datetime to a string showing seconds.

                Below is a link to microsoft's website on datetime tostring formats.
                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.


                For example:

                Print(Time[0].ToString("M/d/yyyy h:mm:ss"));
                or
                Print(DateTime.Now.ToString("M/d/yyyy h:mm:ss"));

                However, keep in mind if you are printing the bar time and the bar closes on the minute, the seconds will be 0.

                Comment


                  #9
                  Hi Tony,

                  What is the string you are emailing?

                  When is this triggered? (Is your script running with Calculate on bar close?)

                  What are you trying to send? The time of the bar? The time of an order? The current time when a condition is true?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello,

                    thank you for your reply.

                    Its simply a horizontal line indicator with COBC=false and when touched (this works as I have an audio-alert also) then it sends an email. This works, and in the email I simply want to have the time with hour:minute (seconds if yes or no is not important)

                    I tried

                    string text = Instrument.FullName + price + Time[0].ToString();
                    string text = Instrument.FullName + DateTime.Now.ToString();

                    and I get eg 2:00:00
                    or date and 2:13:40
                    but not only time like 2:13:40 (or 2:13, would be also OK)

                    Thats it.

                    Thanks
                    Tony

                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hi Tony,

                    What is the string you are emailing?

                    When is this triggered? (Is your script running with Calculate on bar close?)

                    What are you trying to send? The time of the bar? The time of an order? The current time when a condition is true?

                    Comment


                      #11
                      See my post #6.

                      If you only want certain times to show such as your sceanrio for HH:MM then build the custom string to reflect that. The link I gave you shows you all the different things you can use to get the information you want out of the DateTime structure.

                      The question remains now is do you want the exact time the alert occurred or the Bar Timestamp time.

                      Bar Timestamp - Time[0].ToString("HH:mm");
                      Exact time - DateTime.Now.ToString("HH:mm");

                      Comment


                        #12
                        Hi Tony,

                        As I mentioned in post #7 if you are printing the time of the bar the second will always be 0 because the time of the bar happens at regular intervals.

                        If you want the current time when the condition is hit then use DateTime.Now.ToString() instead of the bar time.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by cre8able, Today, 03:20 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post cre8able  
                        Started by Fran888, 02-16-2024, 10:48 AM
                        3 responses
                        45 views
                        0 likes
                        Last Post Sam2515
                        by Sam2515
                         
                        Started by martin70, 03-24-2023, 04:58 AM
                        15 responses
                        114 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by The_Sec, Today, 02:29 PM
                        1 response
                        7 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        2 responses
                        31 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Working...
                        X