View Full Version : Timer for Constant Range Bars
10-12-2007, 01:53 PM
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.
10-12-2007, 02:24 PM
Time returns a DateTime structure - http://msdn2.microsoft.com/en-us/library/system.datetime.aspx
You can then subtract the current Time from the prior Time which gives you a TimeSpan object - http://msdn2.microsoft.com/en-us/library/system.timespan.aspx
A TimeSpan object has a "TotalSeconds" property on it.
11-02-2007, 07:32 AM
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.
11-02-2007, 07:50 AM
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.
11-02-2007, 11:02 AM
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.
11-02-2007, 01:05 PM
Unfortunatley I do not understand what you mean by linking current time to bar close etc...
11-02-2007, 01:13 PM
The previous bar's close is generally the current bar's open time. This is why you can use Time - Time. The result is the time on the current bar, from open to close.