time_close - PineScript Variable
time_close
Section titled “time_close”Overview
Section titled “Overview”time_close provides the close timestamp for the current bar, expressed in milliseconds since 1970-01-01 UTC. On price-based charts (Renko, Line Break, etc.) the latest realtime bar returns na because the closing moment is not known until completion.
Remarks
Section titled “Remarks”- Use together with
timenowto calculate time remaining in the bar:(time_close - timenow) / 1000. - Historical bars on price-based charts return valid timestamps even when realtime bars do not.
- When applying session filters,
time_closerespects the chart’s exchange timezone.
Example
Section titled “Example”//@version=5indicator("Seconds until close", overlay=false)
remaining = (time_close - timenow) / 1000.0remaining := math.max(remaining, 0)
plot(remaining, "Seconds left", color=color.orange)hline(0, "Close", color=color.gray)