Home » Ticker Functions » Understanding timeframe.isseconds Function in Pine Script

Understanding timeframe.isseconds Function in Pine Script

Photo of author
Published on

Pine Script, the domain-specific language for coding custom indicators, strategies, and scripts in TradingView, has introduced several functionalities in its Version 5. One such feature is the timeframe.isseconds function. This article will explore this function, providing a detailed walkthrough of its use, syntax, and practical applications.

Introduction to timeframe.isseconds

What is timeframe.isseconds?

The timeframe.isseconds function in Pine Script Version 5 is designed to check if the current chart’s timeframe is in seconds. This function returns a boolean value (true or false), allowing script developers to create conditions or adjust functionalities based on the timeframe of the chart.

Example Usage of timeframe.isseconds

To demonstrate the use of timeframe.isseconds, let’s create a simple script that checks if the current chart’s timeframe is in seconds and then prints a message on the chart.

indicator("Timeframe Check", overlay=true)

// Using a variable with a similar but distinct name
isTimeframeInSeconds = timeframe.isseconds

// Displaying a message based on the timeframe
if isTimeframeInSeconds
    label.new(bar_index, high, "Timeframe is in seconds", color=color.green)
    label.new(bar_index, high, "Timeframe is not in seconds", color=color.red)

Walkthrough of the Code

  1. Setting the Script Version: We start by specifying //@version=5, ensuring we use Pine Script Version 5.
  2. Defining the Indicator: indicator("Timeframe Check", overlay=true) defines the script as an indicator and sets it to overlay on the price chart.
  3. Declaring the Variable: isTimeframeInSeconds = timeframe.isseconds assigns the result of timeframe.isseconds to a variable. This makes the code more readable and allows for easier modifications.
  4. Conditional Statement: The if-else statement checks whether isTimeframeInSeconds is true. If it is, a green label stating “Timeframe is in seconds” is created using label.new. Otherwise, a red label stating “Timeframe is not in seconds” is displayed.

Key Features of timeframe.isseconds

  • Functionality: Determines if the current chart’s timeframe is in seconds.
  • Return Type: Boolean (true or false).
  • Version: Available in Pine Script Version 5 and later.
  • Application: Useful in scripts where behavior changes based on the timeframe, especially for short-term strategies or high-frequency trading scripts.


  • timeframe.isseconds is an essential function for scripts that need to adapt based on the chart’s timeframe.
  • The function enhances the flexibility of Pine Script, allowing for more dynamic and responsive indicators and strategies.
  • By understanding and utilizing timeframe.isseconds, developers can create more sophisticated and tailored scripts in Pine Script Version 5.

Leave a Comment