Skip to content

How does a chart's time zone setting affect TradingView scripts?

How does a chart’s time zone setting affect TradingView scripts?

Section titled “How does a chart’s time zone setting affect TradingView scripts?”

TL;DR
Built-in date/time variables use the instrument’s exchange time zone, so script logic can appear “offset” if the chart uses a different zone.

DifficultyBeginner
Time to implement10-15 min
CategoryTime & Sessions
//@version=5
indicator("First bar of day", overlay=true)
firstBar = dayofmonth != dayofmonth[1]
bgcolor(firstBar ? color.new(color.teal, 80) : na)
Remember. `dayofmonth`, `time`, and session helpers reference the instrument’s exchange time zone, not the chart’s current display time.

Scripts that trigger “at the open” or inside a session rely on exchange time. If you change the chart time zone to something else (e.g., local time) the highlighted bars may look late or early—even though the logic still fires at the correct exchange timestamp. Understanding the distinction prevents false debugging hunts.

  • How exchange time interacts with date/time variables
  • Detecting session membership regardless of chart display time
  • Communicating the time zone difference to users
  • Overriding the chart display while keeping logic intact
CallPurpose
dayofmonthReturns the day number in exchange time.
time(resolution, session)Checks whether a bar falls inside a session (exchange time).
timenowCurrent exchange time (UTC timestamp).
input.timezone(Optional) Allow users to compare exchange time against their own zone.
  1. Detect day boundaries or sessions
    Use exchange-time variables and functions.

    isFirstBar = dayofmonth != dayofmonth[1]
    inSession = not na(time(timeframe.period, "0930-1600"))
  2. Colour or signal based on those checks
    Colour backgrounds or emit alerts without worrying about the chart’s visible time zone.

    bgcolor(isFirstBar ? color.new(color.teal, 85) : na)
    bgcolor(inSession ? color.new(color.orange, 85) : na)
  3. Optional: display both exchange and chart time
    Help users reconcile what they see by printing both times.

    label.new(
    bar_index, high,
    "Exchange: " + str.format("{0,time,HH:mm}", time) +
    "\nChart TZ: " + str.format("{0,time,HH:mm}", timenow)
    )
//@version=5
indicator("Exchange vs chart time helper", overlay=true)
isFirstBar = dayofmonth != dayofmonth[1]
inSession = not na(time(timeframe.period, "0930-1600"))
bgcolor(isFirstBar ? color.new(color.teal, 85) :
inSession ? color.new(color.orange, 85) : na)
if isFirstBar or inSession and barstate.islast
label.new(
bar_index, high,
str.format("Exchange: {0,time,HH:mm}\nChart: {1,time,HH:mm}",
time,
timenow),
style=label.style_label_left,
textcolor=color.white,
bgcolor=color.new(color.gray, 70)
)
Why this works.
  • The session logic stays anchored to exchange time even if you change the chart display zone.
  • The label provides context by showing both exchange time (script logic) and local chart time.
  • Colour cues make it obvious which bars the logic considers “day start” or “inside the session.”
  • Always document in your script description that exchange time drives the logic.
  • If you must trigger logic using a local time zone, convert with input.timezone and time(timeframe.period, session, timezone).
  • For multi-exchange instruments, verify which exchange TradingView associates with the symbol (see the symbol info dialog).
  • When comparing time values, use hour, minute, or time(timeframe, session) helpers rather than assuming uniform bar spacing.

My background highlights are shifted when I change the chart time zone—did I break something?

Section titled “My background highlights are shifted when I change the chart time zone—did I break something?”

No. The logic still uses exchange time; only the chart display changed. Verify by switching back to the exchange zone—your highlights should align again.

How can users compare exchange time with their local zone?

Section titled “How can users compare exchange time with their local zone?”

Print both times (as in the example playbook) or expose an input.timezone so they can supply their preferred zone and see the offset.

  • Pine’s date/time helpers use the instrument’s exchange time—not the chart display zone.
  • Changing the chart’s time zone only affects what you see in the footer, not the logic itself.
  • Colouring or signalling based on exchange time is reliable—just communicate it to end users.
  • Provide optional labels or settings if you want to bridge the gap between exchange and local times.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.