Skip to content

timeframe ​

How do you act on the first bar of each day or week? Test timeframe.change("1D"), which is true on the first bar of each new period. The timeframe.* values say what timeframe the script runs on.

pine
//@version=6
indicator("Weekly open", overlay = true)
var float weekOpen = na
if timeframe.change("1W") // the first bar of a new week
    weekOpen := open
plot(weekOpen, "Week's open", color.orange, style = plot.style_stepline)

A timeframe is written as TradingView writes it: "60" for 60 minutes, "240" for four hours, "1D", "1W", "1M", and "30S" for seconds. Inside request.security, the timeframe.* values describe the requested timeframe, and timeframe.main_period the chart's.

timeframe.change ​

pine
timeframe.change(timeframe) → series bool

True on the first bar of each new period of timeframe, false on the others and on the first call.

Periods are counted on UTC's calendar: days from each January 1st, weeks from each year's first Monday, months from each January, and an intraday period from each midnight. A timeframe that doesn't parse reads false.

ParameterDefaultDescription
timeframe
simple string
"1D"The period to watch, such as "1W".

timeframe.from_seconds ​

pine
timeframe.from_seconds(seconds) → series string

The shortest timeframe at least seconds long, as a timeframe string.

timeframe.from_seconds(3600) is "60". Below 1 second it is "1S", and above a year "12M".

ParameterDescription
seconds
int
The length in seconds.

timeframe.in_seconds ​

pine
timeframe.in_seconds(timeframe) → series int

The length of timeframe in seconds, the chart's own if you give none.

A month counts as 2,628,003 seconds, as on TradingView. A timeframe that doesn't parse reads 0.

ParameterDescription
timeframe
simple string
The timeframe to measure. The chart's if left out.

timeframe.main_period ​

pine
string timeframe.main_period

The chart's own timeframe, even inside request.security, where timeframe.period is the requested one.

timeframe.multiplier ​

pine
simple int timeframe.multiplier

The number in the timeframe: 4 on a 4-hour chart read as "240", so 240, and 1 on a daily chart.

timeframe.period ​

pine
simple string timeframe.period

The timeframe as a string, such as "60" or "1D". A daily chart reads "1D", not "D".

timeframe.is* ​

Tests of the timeframe's unit. Each is a simple bool.

Each is a simple bool.

NameWhat it means
timeframe.isdailyThe timeframe is in days.
timeframe.isdwmThe timeframe is in days, weeks or months.
timeframe.isintradayThe timeframe is in seconds or minutes.
timeframe.isminutesThe timeframe is in minutes, hours included.
timeframe.ismonthlyThe timeframe is in months.
timeframe.issecondsThe timeframe is in seconds.
timeframe.isticksAlways false: no chart here runs on ticks.
timeframe.isweeklyThe timeframe is in weeks.

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.