Appearance
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 boolTrue 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.
| Parameter | Default | Description |
|---|---|---|
timeframesimple string | "1D" | The period to watch, such as "1W". |
timeframe.from_seconds
pine
timeframe.from_seconds(seconds) → series stringThe 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".
| Parameter | Description |
|---|---|
secondsint | The length in seconds. |
timeframe.in_seconds
pine
timeframe.in_seconds(timeframe) → series intThe 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.
| Parameter | Description |
|---|---|
timeframesimple string | The timeframe to measure. The chart's if left out. |
timeframe.main_period
pine
string timeframe.main_periodThe chart's own timeframe, even inside request.security, where timeframe.period is the requested one.
timeframe.multiplier
pine
simple int timeframe.multiplierThe 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.periodThe 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.
| Name | What it means |
|---|---|
timeframe. | The timeframe is in days. |
timeframe. | The timeframe is in days, weeks or months. |
timeframe. | The timeframe is in seconds or minutes. |
timeframe. | The timeframe is in minutes, hours included. |
timeframe. | The timeframe is in months. |
timeframe. | The timeframe is in seconds. |
timeframe. | Always false: no chart here runs on ticks. |
timeframe. | The timeframe is in weeks. |