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

Understanding timeframe.isintraday Function in Pine Script

Photo of author
Published on

In this article, we will explore the timeframe.isintraday function in Pine Script Version 5, which is crucial for scripts that need to differentiate between intraday and longer timeframes.

Introduction to timeframe.isintraday

What is timeframe.isintraday?

The timeframe.isintraday function in Pine Script is a boolean function that returns true if the current chart’s timeframe is less than one day. This means it is used to identify whether the script is running on an intraday timeframe, such as 1-hour or 30-minute charts, as opposed to daily, weekly, or monthly timeframes.

Syntax

bool isCurrentlyIntraday = timeframe.isintraday

Utilizing timeframe.isintraday in a Script

Example Script

//@version=5
indicator("Intraday Checker", overlay = true)

isIntradayFrame = timeframe.isintraday

plotshape(series = isIntradayFrame, location = location.abovebar, color = color.green, style = shape.triangleup, title = "Intraday Timeframe")
plotshape(series = not isIntradayFrame, location = location.belowbar, color = color.red, style = shape.triangledown, title = "Longer Timeframe")
Example

Detailed Walkthrough

  1. Initialization of the Indicator:
    • indicator("Intraday Checker", overlay = true): This line sets up the script as an indicator named “Intraday Checker” that will overlay on the main chart.
  2. Determining the Timeframe:
    • isIntradayFrame = timeframe.isintraday: Here, we declare a boolean variable isIntradayFrame and assign the result of timeframe.isintraday to it. If the current timeframe is less than a day, isIntradayFrame will be true.
  3. Plotting Shapes Based on Timeframe:
    • plotshape(series = isIntradayFrame, ...): This line plots a green upward triangle above the bar if the timeframe is intraday.
    • plotshape(series = not isIntradayFrame, ...): Conversely, this line plots a red downward triangle below the bar if the timeframe is not intraday (i.e., daily, weekly, etc.).

Key Features and Takeaways

  • Function Usability: timeframe.isintraday is extremely useful for scripts that need different logic or calculations based on whether they are being applied to intraday or longer timeframes.
  • Syntax and Application: The function is straightforward, returning a simple boolean value, making it easy to integrate into conditional statements or logic flows.
  • Versatility: This function can be used in a wide range of scripts, from simple indicators like the example above to complex trading strategies that require different parameters for different timeframes.

In conclusion, timeframe.isintraday in Pine Script Version 5 is a versatile and straightforward function that adds significant flexibility to your scripting, allowing you to tailor your analysis or strategy to the specific nuances of intraday versus longer timeframes.

Leave a Comment