timeframe - Pine Script Variable
timeframe
Section titled “timeframe”Overview
Section titled “Overview”Flags and values describing the script’s active timeframe.
Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
timeframe.isdaily | simple bool | Returns true if current resolution is a daily resolution, false otherwise. |
timeframe.isdwm | simple bool | Returns true if current resolution is a daily or weekly or monthly resolution, false otherwise. |
timeframe.isintraday | simple bool | Returns true if current resolution is an intraday (minutes or seconds) resolution, false otherwise. |
timeframe.isminutes | simple bool | Returns true if current resolution is a minutes resolution, false otherwise. |
timeframe.ismonthly | simple bool | Returns true if current resolution is a monthly resolution, false otherwise. |
timeframe.isseconds | simple bool | Returns true if current resolution is a seconds resolution, false otherwise. |
timeframe.isticks | simple bool | Returns true if current resolution is a ticks resolution, false otherwise. |
timeframe.isweekly | simple bool | Returns true if current resolution is a weekly resolution, false otherwise. |
timeframe.main_period | simple string | A string representation of the script’s main timeframe. If the script is an indicator that specifies a timeframe value in its declaration statement, this variable holds that value. Otherwise, its value represents the chart’s timeframe. Unlike timeframe.period, this variable’s value does not change when used in the expression argument of a request.*() function call. |
timeframe.multiplier | simple int | Multiplier of resolution, e.g. ‘60’ - 60, ‘D’ - 1, ‘5D’ - 5, ‘12M’ - 12. |
timeframe.period | simple string | A string representation of the script’s main timeframe or a requested timeframe, depending on how the script uses it. The variable’s value represents the timeframe of a requested dataset when used in the expression argument of a request.*() function call. Otherwise, its value represents the script’s main timeframe (timeframe.main_period), which equals either the timeframe argument of the indicator declaration statement or the chart’s timeframe. |
Remarks
Section titled “Remarks”- Inside
request.*()expressions,timeframe.periodreflects the requested dataset. Usetimeframe.main_periodto access the script’s main timeframe consistently. timeframe.period: To always access the script’s main timeframe, even within another context, use the timeframe.main_period variable.
Example
Section titled “Example”//@version=6indicator("Timeframe-aware length", overlay=false)
len = timeframe.isintraday ? 20 : 50plot(ta.sma(close, len))