Converts a timeframe string to the number of seconds in one of its bars; with no argument it uses the chart's timeframe.
timeframe.in_seconds("60") returns 3600, timeframe.in_seconds("15") returns 900 and timeframe.in_seconds("1D") returns 86400. Call it with no argument to get the length of one bar on the chart. Use it to compare two timeframes as numbers, which a string comparison cannot do.
Seconds, minutes, hours, days and weeks are exact. A month has no fixed length, so its value is an approximation in seconds, not the days of a particular month.
Syntax
timeframe.in_seconds(timeframe: simple string (optional)) -> simple int
timeframe.in_seconds(timeframe: series string (optional)) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| timeframe | simple/ | the chart's timeframe | The timeframe to convert, such as "1", "15", "60", "1D", "1W" or "1M". Omit it to use the chart's timeframe. |
Returns
simple int: The length of one bar of the timeframe, in seconds.series int: The length of one bar of the timeframe, in seconds, recalculated per bar.
Remarks
- The result is a simple int when you pass a simple string and a series int when the argument changes per bar. Divide two results to get how many bars of one timeframe fit in another.
- A string that is not a timeframe is a runtime error.
- On Sidechair: a missing or empty argument returns the chart's bar length, days are 86,400 seconds, weeks 604,800 and a month is 30 days (2,592,000), and an unreadable string returns na.
Example
//@version=6
indicator("Bars per hour")
perHour = timeframe.in_seconds("60") / timeframe.in_seconds()
plot(perHour, "Bars per hour", color.orange, 2)
plot(close, "Close", color.gray)See also
Runs on Sidechair