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

How to measure a Timespan in milliseconds in NT 7 ?

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

    How to measure a Timespan in milliseconds in NT 7 ?

    Hi NT,

    I'm able to obtain aTimespan in seconds but I'm still not able to get it in milliseconds.

    I've been trying to change properties to this script instruction
    td0 = t0.Subtract(t1).Seconds;
    but it doesn't work.

    Is there any simple way to achieve this ?

    Thanks in advance

    #2
    Hello pstrusi,

    Thank you for your inquiry.

    You would be able to obtain the total amount of milliseconds in a TimeSpan object by using the TotalMilliseconds property.

    More information about TotalMilliseconds can be found at this MSDN link: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    So, using your example:
    Code:
    td0 = t0.Subtract(t1);
    Print(td0.TotalMilliseconds);
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      It doesn't work in that simple manner that you suggest. Reading msdn, it seems that a Timespan variable type should be created first.

      Thanks anyway

      Comment


        #4
        Hello pstrusi,

        Yes, you would need to create a TimeSpan variable.

        I apologize as I thought that td0 was a TimeSpan object and t0 and t1 were DateTime objects.

        Code:
        private TimeSpan td0;
        private DateTime t0;
        private DateTime t1;
        
        // assign times to t0 and t1
        .....
        
        td0 = t0.Subtract(t1);
        Print(td0.TotalMilliseconds);
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Hi Zachary, thanks for your help.

          Well it works, BUT the milliseconds that it gives it's just the seconds x 1000, it doesn't measure with the precision of milliseconds. Is there any way to get the real precision of milliseconds ?

          Comment


            #6
            Originally posted by pstrusi View Post
            Hi Zachary, thanks for your help.

            Well it works, BUT the milliseconds that it gives it's just the seconds x 1000, it doesn't measure with the precision of milliseconds. Is there any way to get the real precision of milliseconds ?
            I think I got it. Simply using t0 = DateTime.Now; before I was using t0 = Time[0]

            Thanks for your help

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by timmbbo, Today, 08:59 AM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by KennyK, 05-29-2017, 02:02 AM
            2 responses
            1,281 views
            0 likes
            Last Post marcus2300  
            Started by fernandobr, Today, 09:11 AM
            0 responses
            2 views
            0 likes
            Last Post fernandobr  
            Started by itrader46, Today, 09:04 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by bmartz, 03-12-2024, 06:12 AM
            5 responses
            33 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Working...
            X