Converts a number of seconds to a timeframe string such as "5" for 300 seconds or "60" for 3600.
timeframe.from_seconds(300) returns "5" and timeframe.from_seconds(3600) returns "60"; a length of a day or more gives a day, week or month string. The result is the shortest standard form of the timeframe, ready to pass to request.security(), timeframe.change() or timeframe.in_seconds().
Use it when a timeframe is built by arithmetic, for example a higher timeframe that is four times the chart's: timeframe.from_seconds(timeframe.in_seconds() * 4).
Syntax
timeframe.from_seconds(seconds: simple int) -> simple string
timeframe.from_seconds(seconds: series int) -> series stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| seconds | simple/ | required | The length of one bar in seconds, such as 300 for five minutes or 86400 for a day. |
Returns
simple string: The timeframe string for that many seconds.series string: The timeframe string for that many seconds, recalculated per bar.
Remarks
- Pass a length that matches a real timeframe, such as 60, 300, 3600 or 86400.
- The result is a simple string when the input is a simple int, and a series string otherwise.
- On Sidechair: under 60 seconds gives "30S" style text, under a day gives the minutes, and a day or more gives "1D", "1W" or "1M" style text in v6 ("D" and "W" in v5).
Example
//@version=6
indicator("Higher timeframe name", overlay = true)
higher = timeframe.from_seconds(timeframe.in_seconds() * 4)
plot(close, "Close", color.gray)
if barstate.islast
label.new(bar_index, high, timeframe.period + " x4 = " + higher, style = label.style_label_down)See also
Runs on Sidechair