Calculate time(seconds) of each bar on tick chart

Created at 19 Sep 2014, 22:29
EM

emeeder

Joined 06.05.2014 Blocked

Calculate time(seconds) of each bar on tick chart
19 Sep 2014, 22:29


I am not sure how to use the Timeseries data to get a Result that will simply return the time (in seconds) of each bar on a tick chart.

Can someone maybe let me know how to do this so that i can use it in an indicator.

Thanks


Replies

Spotware
22 Sep 2014, 09:27

You can use MarketSeries.OpenTime collection. Example:

            Print("Last bar time: " + MarketSeries.OpenTime.Last(0));
            Print("Previous bar time: " + MarketSeries.OpenTime.Last(1));
            //etc.

 


@Spotware

emeeder
22 Sep 2014, 19:32

Thanks for that.

Right now I have this:

 Print("current bar" + (Server.Time - MarketSeries.OpenTime.Last(0)));

 Print("Last bar time: " + (MarketSeries.OpenTime.Last(0) - MarketSeries.OpenTime.Last(1)));

It gives me the data i want to use, but i can not output it as a number because it is in a time stamp format.

22/09/2014 12:24:58.903 | current bar 00:00:40.8500000

I guess my question is how can i use this result and plot it?

This for instance will not work:

Result[index] = (Server.Time - MarketSeries.OpenTime.Last(0));

is there a way that my result (in this case 00:00:40.8500000) can be converted to a number of 40.8500000 (seconds).

and also a number like 00:02:28.7800000 can be converted to a number 148.7800000 (seconds)

Thanks

 


Invalid
23 Sep 2014, 09:17

RE:

emeeder said:

This for instance will not work:

Result[index] = (Server.Time - MarketSeries.OpenTime.Last(0));

is there a way that my result (in this case 00:00:40.8500000) can be converted to a number of 40.8500000 (seconds).

and also a number like 00:02:28.7800000 can be converted to a number 148.7800000 (seconds)

Thanks

 

TimeSpan has Property "TotalSeconds"

Result[index] = (Server.Time - MarketSeries.OpenTime.Last(0)).TotalSeconds; (as double). you can cast it to integer if you wish.

For more details take a look on MSDN


@Invalid

emeeder
23 Sep 2014, 15:25

Thanks!

That's exactly what i needed.