Skip to content

timeframe namespace

The timeframe namespace describes the chart’s resolution and offers utilities for converting between timeframe strings, seconds, and timeframe categories (intraday, daily, weekly, etc.). These helpers are essential when building multi-timeframe logic that reacts differently on higher resolutions.

Timeframe strings follow TradingView’s format (e.g., "1", "15", "1H", "1D", "3M"). Use input.timeframe to gather user input in that format, then process it with `timeframe.*` utilities.

FunctionPurpose
timeframe.periodReturns the script’s current timeframe string.
timeframe.multiplierNumber of base units in the current timeframe (e.g., 5 for 5m).
timeframe.change(tf)true on the first bar of each new tf period.
timeframe.isintraday, timeframe.isdaily, timeframe.isweekly, timeframe.ismonthly, timeframe.isseconds, timeframe.isticksBoolean flags describing the current chart.
timeframe.in_seconds(tf)Convert a timeframe string into seconds.
timeframe.from_seconds(seconds)Produce the closest matching timeframe string for a number of seconds.
timeframe.main_periodUnderlying base period for composite ranges (e.g., 1D for a chart built from multiple days).
  • timeframe.change() is handy for drawing separators or resetting accumulators whenever a higher timeframe begins (daily on a 5-minute chart, etc.).
  • For custom resampling, multiply timeframe.in_seconds() by a factor to create strings with timeframe.from_seconds() before feeding them to request.security().
  • Category checks (e.g., timeframe.isseconds) help you guard code that only works on certain chart types, preventing runtime errors.
//@version=5
indicator("Timeframe utilities", overlay=true)
isNewDay = timeframe.change("1D")
isHigherTF = timeframe.in_seconds("1D") >= timeframe.in_seconds()
plotshape(isNewDay, style=shape.labelup, text="New day",
color=color.new(color.orange, 0), textcolor=color.white,
location=location.belowbar)
bgcolor(isHigherTF ? color.new(color.blue, 92) : na,
title="Chart timeframe ≤ daily")