Tick Time Bar Indicator

I was hoping someone could point me in the right direction to create an indicator that displays the amount of time elapsed in a tick bar.

For example, using 4000 as the tick value, I’m looking to create an indicator that displays the time, most likely in seconds, for that current tick bar.

In outlining the indicator, I’d most likely create 2.

One is a separate panel that is a bar chart with time as an axis. It would probably have a SMA average plot as well as upper and lower bounds.

Another advanced one would take a few variables to identify or mark irregular tick candle combinations based on time.

These are current rules with my trade system I’m just looking to see if I can create an indicator that identifies these key areas.

I did quite a bit of searching and looking around here and on the web to find a starting point, but I wasn’t able to nail down the bar time or even another indicator with similar concepts.

Any help would be appreciated and I’d find some way to pay it forward. Thank you.

If you have map(d, i, history) as your indicator’s map method signature, you can get the time when the bar started with d.timestamp(). Then to get elapsed time since it started, just subtract that from the current time (const now = new Date();). That will give you the elapsed time in milliseconds.

And to get the time for each past bar, just do d.timestamp() - history.prior.timestamp(). You will have to check to make sure history.prior() is defined of course. Once you have that, you can use it in your SMA, etc.


Can’t thank you enough. This helps. I was partially there with some of this looking at other indicators. I’ll update the progress here as I go along.

No problem. I was looking through the Volume Delta Grid indicator you can get from the Community, it actually does this calculation and also formats it to be hh:mm:ss. I will post the snippet here, but not sure if the formatting will be right. The only difference I see is that this code stores the lastTs d.timestamp() in a state property instead of calling history.prior().timestamp().

        const last = d.isLast() ? new Date(d.timestamp()) : new Date(lastTs)
        const next = d.isLast() ? new Date() : new Date(d.timestamp())
        const diff = (next - last) / 1000
        const drawSecs = Math.floor(diff % 60)
        const drawMins = Math.floor(diff / 60) % 60
        const drawHrs = Math.floor(diff / 60 / 60)
        const timeStr = `${
            drawHrs < 10  ? '0'+drawHrs : drawHrs
            drawMins < 10 ? '0'+drawMins : drawMins
            drawSecs < 10 ? '0'+drawSecs : drawSecs
1 Like

Thank you again. That indicator provides the exact data as far as bar time and works on tick charts. Shame for this indicator; you have to be so zoomed in to see the data, but I think this will provide the data points to create the indicator and others around specific tick indicators I’m looking to create and release here in the Community.

1 Like