Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars in seconds

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

    Bars in seconds

    Hi, I need to find out how long a bar is in seconds. I'm using renko bars. Is there a function that can do this for me? tx

    #2
    pman777, there would not be a default function, you would need to take the difference of the bar timestamps and convert to seconds, C# offers a convenient TimeSpan struct for this job - http://www.dotnetperls.com/timespan

    Alternatively as starting point you could check into this study from our sharing - http://www.ninjatrader.com/support/f...d=1&linkid=230

    Comment


      #3
      thanks Bertrand! I will look into those resources. Another related question ... how do I know when a new renko bar has started so I can reset my elapse time counter to start tracking the new bar? Sorry if this is obvious but having an issue figuring this out ... thanks again!

      Comment


        #4
        You would go off the Time[0] reference which will give you the timestamp of the current most processed bar, this will update automatically if a new bar starts forming, thus it would update any calculations as well that you base of that. If you process in CalculateOnBarClose = false, then FirstTickOfBar would give you the start of the new bar directly.

        Comment


          #5
          I'm making progress ... but one more question

          Here's my current code:
          if (FirstTickOfBar) barStartTime = DateTime.Now;
          barElapsedTime = (DateTime.Now-barStartTime).TotalSeconds;
          SecondBar.Set(barElapsedTime);

          This is working fine but it only calculates the elapse time of the current bar. How can I get it to calculate the same for prior bars?

          Comment


            #6
            You would not want to base it off DateTime.Now for the historical bars, since that would be your current PC clock. Which could not server as a reference for history but only the current moment. You will need to work with Time[x] to access the historical timestamps of the bars for your task.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            161 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            308 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            245 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            349 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            179 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Working...
            X