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

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 fiddich, Today, 05:25 PM
        0 responses
        3 views
        0 likes
        Last Post fiddich
        by fiddich
         
        Started by gemify, 11-11-2022, 11:52 AM
        6 responses
        803 views
        2 likes
        Last Post ultls
        by ultls
         
        Started by ScottWalsh, Today, 04:52 PM
        0 responses
        4 views
        0 likes
        Last Post ScottWalsh  
        Started by ScottWalsh, Today, 04:29 PM
        0 responses
        7 views
        0 likes
        Last Post ScottWalsh  
        Started by rtwave, 04-12-2024, 09:30 AM
        2 responses
        22 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Working...
        X