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

Understanding timeframe.multiplier Function in Pine Script

Photo of author
Published on

Introduction to timeframe.multiplier

Pine Script, the scripting language used on the TradingView platform, enables traders to create custom technical analysis tools and studies. In version 5 of Pine Script, a useful variable known as timeframe.multiplier has been introduced. This variable provides unique insights into the timeframe of the chart on which the script is running.

What is timeframe.multiplier?

timeframe.multiplier is a built-in variable in Pine Script v5 that returns an integer representing the multiplier of the current chart’s timeframe unit. This variable helps in understanding the period that each bar or candlestick on the chart represents.

How Does It Work?

  • Intraday Timeframes: For intraday charts (less than one day), timeframe.multiplier returns the number of minutes. For example, on an hourly chart, it will return 60.
  • Seconds Timeframe: For a 30-second chart, it will return 30, indicating 30 seconds.
  • Daily and Higher Timeframes: For daily charts, it returns 1 (day), for quarterly charts, it returns 3 (months), and for yearly charts, it returns 12 (months).


One important aspect to remember is that the value of timeframe.multiplier cannot be directly used as an argument in timeframe parameters of built-in functions in Pine Script. These functions usually require a string in a specific timeframe specification format.

Practical Example

Let’s consider an example to illustrate the use of timeframe.multiplier.

indicator("My Timeframe Multiplier Script", overlay=true)

// Using timeframe.multiplier
timeMultiplier = timeframe.multiplier

// Displaying the value on the chart
label.new(bar_index, high, text="Timeframe Multiplier: " + str.tostring(timeMultiplier), color=color.red)

Walkthrough of the Example Code

  1. Script Setup: The script begins //@version=5 to indicate that it’s using Pine Script version 5. The indicator function sets up the script with a title and an option to overlay it on the chart.
  2. Utilizing timeframe.multiplier: The variable timeMultiplier is assigned the value of timeframe.multiplier.
  3. Displaying the Value: A label is created on the chart using label.new which displays the value of timeMultiplier. The str.tostring function converts the integer value to a string for display.

Key Features and Takeaways

  • Functionality: timeframe.multiplier provides an integer value representing the timeframe’s unit multiplier.
  • Limitation: Its value cannot be used as a direct argument in the timeframe parameters of built-in functions.
  • Use Cases: Useful in scripts that need to adjust calculations or behaviors based on the chart’s timeframe.
  • Version Specific: Available in Pine Script version 5.

Leave a Comment