Tick Time Bar Indicator

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