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

Timer for Constant Range Bars

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

    Timer for Constant Range Bars

    Hi

    I would like to develop a timer that counts the seconds between the open and the close of a constant range bar but I am having difficulties to find the appropriate syntax that calls the "seconds" variable.

    Thanks for pointing me in the right direction.

    #2
    Time[0] returns a DateTime structure - http://msdn2.microsoft.com/en-us/lib....datetime.aspx

    You can then subtract the current Time[0] from the prior Time[1] which gives you a TimeSpan object - http://msdn2.microsoft.com/en-us/lib....timespan.aspx

    A TimeSpan object has a "TotalSeconds" property on it.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hello Ray

      Thanks for your reply but I'm still having trouble with the following:
      The time format is the following:

      For example: open of the bar at 13.15 and 57 sec
      close of the bar 13.16 and 07 sec

      Total time of the bar is: 10 seconds. The problem is that the formula calculates the time like this: 131607-131557. The result obviously isn't correct.

      What can I do to correct that?

      Thanks a lot.

      Comment


        #4
        Not sure I follow.

        If you are working with the DateTime class in .NET and subtracting one time from another, you get back a TimeSpan object. The TimeSpan object has a TotalSeconds property on it that would return 10 seconds in your example.
        RayNinjaTrader Customer Service

        Comment


          #5
          Thanks for that, I managed to get the raw time with Total Seconds indeed.
          I'm still having trouble though linking the Current Time to the bar close and the Prior Time to the bar open, thus getting the total duration of the bar in seconds.

          Thanks a lot.

          Comment


            #6
            Unfortunatley I do not understand what you mean by linking current time to bar close etc...
            RayNinjaTrader Customer Service

            Comment


              #7
              The previous bar's close is generally the current bar's open time. This is why you can use Time[1] - Time[0]. The result is the time on the current bar, from open to close.
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              4 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              20 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Working...
              X