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 Pattontje, Yesterday, 02:10 PM
            2 responses
            15 views
            0 likes
            Last Post Pattontje  
            Started by flybuzz, 04-21-2024, 04:07 PM
            17 responses
            229 views
            0 likes
            Last Post TradingLoss  
            Started by agclub, 04-21-2024, 08:57 PM
            3 responses
            17 views
            0 likes
            Last Post TradingLoss  
            Started by TradingLoss, 04-21-2024, 04:32 PM
            4 responses
            44 views
            2 likes
            Last Post TradingLoss  
            Started by cre8able, 04-17-2024, 04:16 PM
            6 responses
            57 views
            0 likes
            Last Post cre8able  
            Working...
            X