Home » Ticker Functions » Understanding the timeframe.isminutes Function in Pine Script

Understanding the timeframe.isminutes Function in Pine Script

Photo of author
Published on

Pine Script, the scripting language used on the TradingView platform, offers a range of functions and features that enable traders and analysts to create customized technical analysis tools and indicators. One such feature is the timeframe.isminutes function. In this article, we will delve into the details of this function, exploring its use, syntax, and application in Pine Script programming.

What is timeframe.isminutes?


The timeframe.isminutes function in Pine Script is designed to check if the current chart’s timeframe is based on a minute interval. It returns a boolean value (true or false) indicating whether the chart’s timeframe is in minutes.


The basic syntax of timeframe.isminutes is straightforward:

isMinuteTimeframe = timeframe.isminutes

Here, isMinuteTimeframe is a variable that will hold the boolean result returned by timeframe.isminutes.

Example Usage


Suppose we want to create a script that behaves differently when the chart is on a minute-based timeframe compared to other timeframes.

Code Example

indicator("Minute Timeframe Check", shorttitle="MTC", overlay=true)

isMinuteTimeframe = timeframe.isminutes

// Displaying a different message based on the timeframe
plotMessage = isMinuteTimeframe ? "This is a minute-based timeframe." : "This is NOT a minute-based timeframe."
label.new(bar_index, high, plotMessage, color=color.red)

Detailed Walkthrough

  1. Indicator Declaration: indicator("Minute Timeframe Check", shorttitle="MTC", overlay=true) sets up the script as an indicator with the name “Minute Timeframe Check” and a short title of “MTC”. The overlay=true parameter allows the indicator to be plotted directly on the price chart.
  2. Timeframe Check: isMinuteTimeframe = timeframe.isminutes assigns the result of timeframe.isminutes to the variable isMinuteTimeframe. If the current timeframe is based on minutes, isMinuteTimeframe will be true; otherwise, it will be false.
  3. Conditional Message: The ternary operator ? : is used to choose between two strings based on the value of isMinuteTimeframe. If true, it sets plotMessage to “This is a minute-based timeframe.”; otherwise, it sets it to “This is NOT a minute-based timeframe.”
  4. Label Creation: label.new(bar_index, high, plotMessage, color=color.red) creates a new label on the chart. The label’s position is determined by bar_index and high, and it displays the plotMessage.

Key Features and Takeaways

  • Function Useability: timeframe.isminutes is useful for scripts that need to behave differently based on the chart’s timeframe, especially for strategies and indicators specific to minute-based timeframes.
  • Syntax Simplicity: The syntax is straightforward, making it easy to integrate into various scripts.
  • Conditional Logic Enhancement: This function is particularly effective when used in conjunction with conditional statements to customize script behavior.

In conclusion, timeframe.isminutes in Pine Script is a simple yet powerful tool for scripts that require awareness of the chart’s timeframe, particularly when differentiating between minute-based and other timeframes. Its ease of use and the clear boolean output make it a handy function for both beginner and advanced Pine Script programmers.

Leave a Comment