Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Real Time ?

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

    Real Time ?

    Hello NT friends.

    I am trying to print the real time (include seconds) in my indicator, but only can show the bar time.

    This is my OnBarUpdate code:

    Time[0].Hour + ":" + Time[0].Minute + ":" + Time[0].Second

    I tried with this to:

    DateTime.Now..Hour + ":" +DateTime.Now..Minute + ":" + DateTime.Now..Second


    Could you help me please ?
    Thank you !

    #2
    Hello,

    You are on the right track with your idea to use a new DateTime object. It looks like the only thing you are missing is a call to ToString() after each property of the object, as in the code below:

    Code:
    private DateTime now = DateTime.Now;
    
    protected override void OnBarUpdate()
            {
    			Print(now.ToString());
    			Print(now.Hour.ToString());	
            }
    For more information on the properties and instantiation of DateTime objects, please see the link below:

    https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

    Please let me know if I can assist further.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Thanks Dave, but this not show the real time minutes and seconds but minute of bar and unknown second....

      How could i show the real time minutes and seconds?



      private DateTime now = DateTime.Now;

      protected override void OnBarUpdate()
      {
      Print(now.ToString());
      Print(now.Minute.ToString());
      Print(now.Second.ToString());
      }

      Comment


        #4
        Hello,

        If I'm understanding correctly, it sounds like you are looking for a timer that updates outside of OnBarUpdate(), so that it updates on a regular interval of one second.

        You can do this by creating a C# Timer object, then passing in an event handler that will draw the time on your chart (or wherever you would like to display it). I've uploaded a sample script that will show how to set this up.

        One thing to note -- I'm using standard numeric format strings in the calls to ToString(), so that the hour, minute, and second will always display two digits each. More information on standard numeric format strings can be found at the link below:

        https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx

        Please let me know if I can assist further.
        Attached Files
        Dave I.NinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        639 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        572 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X