Skip to content

time_close - PineScript Variable

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.

  • Use together with timenow to 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_close respects the chart’s exchange timezone.
//@version=5
indicator("Seconds until close", overlay=false)
remaining = (time_close - timenow) / 1000.0
remaining := math.max(remaining, 0)
plot(remaining, "Seconds left", color=color.orange)
hline(0, "Close", color=color.gray)