timenow - PineScript Variable
timenow
Section titled “timenow”Overview
Section titled “Overview”timenow returns the current wall-clock timestamp in milliseconds since 1970-01-01 UTC. Unlike time, it reflects the actual moment the script executes, not the bar’s open or close.
Remarks
Section titled “Remarks”- Because
timenowchanges on every update, using it in realtime calculations may lead to repainting. - Useful for countdown timers or gating logic by absolute time (
timenow >= targetTs). - It always reflects UTC-based milliseconds; convert to human-readable strings with
str.format_time.
Example
Section titled “Example”//@version=5indicator("Wall-clock timestamp", overlay=false)
target = input.time(timestamp("UTC", 2024, 12, 31, 23, 59), "Deadline (UTC)")secondsToTarget = (target - timenow) / 1000.0
plot(secondsToTarget, "Seconds until deadline", color=color.purple)plot(0, color=color.gray)