The GetTimeframe function in ProBuilder language is used to retrieve the current timeframe of the chart in seconds. This function is particularly useful when programming conditions or calculations that depend on the timeframe of the data being analyzed. It returns the timeframe in seconds if the timeframe is based on a linear time unit (like minutes or hours). If the timeframe is non-linear (like ticks or volume), it returns -1.
GetTimeframe()
To demonstrate how GetTimeframe works, consider the following example where we switch between different timeframes and retrieve their corresponding values in seconds:
timeframe(4 hour)
a = GetTimeframe
timeframe(1 hour)
b = GetTimeframe
timeframe(default)
c = GetTimeframe
return a as "seconds in 4 hours", b as "seconds in 1 hour", c as "seconds in current timeframe"
In this example:
It is important to note that GetTimeframe is only applicable for timeframes that are defined in terms of linear time units. For non-linear timeframes, such as those based on the number of trades (ticks) or traded volume, the function will return -1, indicating that the timeframe cannot be expressed in seconds.