timeframe.in_seconds() - Pine Script Function
timeframe.in_seconds()
Section titled “timeframe.in_seconds()”Overview
Section titled “Overview”Converts a timeframe string into seconds.
Syntax
Section titled “Syntax”timeframe.in_seconds(timeframe) → simple intParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| timeframe | simple string | Timeframe string in timeframe string specifications format. Optional. The default is timeframe.period. |
Returns
Section titled “Returns”The “int” representation of the number of seconds in the timeframe string.
Remarks
Section titled “Remarks”- When the timeframe is “1M” or more, calculations use 2628003 as the number of seconds in one month, which represents 30.4167 (365/12) days.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`timeframe_in_seconds()`"),// Get a user-selected timeframe.tfInput = input.timeframe("1D")// Convert it into an "int" number of seconds.secondsInTf = timeframe.in_seconds(tfInput)plot(secondsInTf)