Skip to content

See if TradingView uses hourly time frame with Pine Script

See if TradingView uses hourly time frame with Pine Script

Section titled “See if TradingView uses hourly time frame with Pine Script”

TL;DR
Pine Script doesn’t have a direct “is hourly” flag, but you can combine timeframe.isminutes and timeframe.multiplier >= 60 to detect hour-based charts.

DifficultyBeginner
Time to implement10-15 min
CategoryTime & Sessions
//@version=5
indicator("Hourly detector", overlay=true)
isHourlyTF() =>
timeframe.isminutes and timeframe.multiplier >= 60 and timeframe.multiplier < 1440
isHourly = isHourlyTF()
bgcolor(isHourly ? color.new(color.orange, 85) : na, title="Hourly background")
plotchar(isHourly, "Hourly flag", "H", location=location.top)
Tip. Include the `< 1440` check so the function distinguishes hourly charts from daily ones (which also use minute data when requested through `request.security`).

Strategies often treat 1H–12H charts differently from lower minute resolutions or higher daily ones. Detecting hourly resolutions lets you tweak indicator lengths, throttle alerts, or block trades that were optimised for intraday flows.

  • Combine Pine’s time-frame helpers to detect 60-minute-and-above charts that are still intraday.
  • Apply the helper to change visuals, inputs, or strategy behaviour.
  • Guard the logic against range charts and custom aggregations.
  • Use the same flag inside request.security() calls when pulling multi-time-frame data.
HelperPurpose
timeframe.isminutestrue for any minute-based resolution, including hourly and custom minute counts.
timeframe.multiplierNumber of minutes represented by each bar (e.g., 1, 60, 240, 1440).
isHourlyTF() (custom)Returns true when the bar multiplier is between 60 minutes and one day.
bgcolor, label.newOptional ways to surface the detection on chart.
  1. Define the helper
    A single function keeps the check reusable and readable.

    isHourlyTF() =>
    timeframe.isminutes and timeframe.multiplier >= 60 and timeframe.multiplier < 1440
  2. React to the flag
    Use the boolean to toggle visuals, change inputs, or enforce guardrails.

    emaLen = isHourlyTF() ? 34 : 55
  3. Integrate with strategy logic
    Skip trades, adjust risk, or fetch higher-time-frame data only when hourly mode is active.

    if isHourlyTF()
    strategy.entry("HourlyLong", strategy.long)
//@version=5
indicator("Hourly-aware parameter switch", overlay=true, max_labels_count=500)
isHourlyTF() =>
timeframe.isminutes and timeframe.multiplier >= 60 and timeframe.multiplier < 1440
fastLenHourly = input.int(21, "Fast EMA (hourly)")
fastLenNonHour = input.int(34, "Fast EMA (non-hourly)")
slowLenHourly = input.int(55, "Slow EMA (hourly)")
slowLenNonHour = input.int(89, "Slow EMA (non-hourly)")
emaFast = ta.ema(close, isHourlyTF() ? fastLenHourly : fastLenNonHour)
emaSlow = ta.ema(close, isHourlyTF() ? slowLenHourly : slowLenNonHour)
plot(emaFast, "Adaptive fast EMA", color=color.new(color.teal, 0))
plot(emaSlow, "Adaptive slow EMA", color=color.new(color.purple, 0))
bgcolor(isHourlyTF() ? color.new(color.orange, 88) : na, title="Hourly highlight")
if barstate.islast
label.new(bar_index, close,
text = "Resolution: " + timeframe.period +
"\nHourly? " + (isHourlyTF() ? "Yes" : "No") +
"\nFast EMA: " + str.tostring(isHourlyTF() ? fastLenHourly : fastLenNonHour),
style=label.style_label_left,
textcolor=color.white,
bgcolor=color.new(isHourlyTF() ? color.orange : color.gray, 70))
Why this works.
  • The helper abstracts the resolution test so it can be reused across the script.
  • EMA parameters adapt instantly when switching between hourly and non-hourly charts.
  • Background colour and label provide immediate confirmation of the detected mode.
  • Range charts always use 1-minute data under the hood—timeframe.multiplier reports 1, so the helper correctly returns false.
  • If you want to include multi-hour charts (like 4H, 8H, 12H), keep the >= 60 logic, but adjust the upper bound if you consider 24H part of the hourly family.
  • Pair the helper with request.security() to pull daily data when the chart is hourly: use the flag to decide which higher frame to request.
  • Cache the result in a var or evaluate once per bar if you call it repeatedly inside loops.

Ensure you didn’t set an upper bound of exactly 60. Use >= 60 to include all hourly multiples such as 120, 180, or 240 minutes.

Yes—those charts still rely on the underlying minute aggregation. The helper reads the data interval, not the visual chart type.

Replace the >= 60 check with timeframe.multiplier == 60 to match a single hour.

  • Pine doesn’t expose timeframe.ishourly, but the combination of timeframe.isminutes and timeframe.multiplier makes the check trivial.
  • Wrap the logic in a helper function so you can use it across entries, exits, and visual cues.
  • Hourly detection keeps parameter presets and guards aligned with the chart resolution your script supports.
  • Adjust the multiplier bounds if you consider multi-hour bars part of the same family.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.

  • So for Heikin Ashi, Renko, Line Break, Kagi, and Point & Figure charts, the function returns true or false based on the chart’s underlying data.

  • On Range charts the function always returns false. TradingView makes those charts from 1-minute data, no matter how many ranges we configure. So they can’t use hourly data.

  • IsHourlyTF() tells if the script runs on an hourly chart. But we can also pass this function to the request.security() function. When we do, we find out if that background data function calculates with hourly data.

  • So for Heikin Ashi, Renko, Line Break, Kagi, and Point & Figure charts, the function returns true or false based on the chart’s underlying data.

  • On Range charts the function always returns false. TradingView makes those charts from 1-minute data, no matter how many ranges we configure. So they can’t use hourly data.

  • With two Pine Script variables we see if the script uses an hourly time frame.

  • The timeframe.isminutes variable says if the time frame uses minute data. This is needed since TradingView makes hourly charts from minute data.

  • And the timeframe.multiplier variable has to be 60 or higher. That’s how we differentiate between minute time frames and hourly ones.

Ready to implement this in your own strategies?

This tutorial is based on content from TradingCode.net, adapted for Algo Trade Analytics users.

This tutorial is based on content from tradingcode.net, adapted for Algo Trade Analytics users.

//@version=5 indicator(title="Hourly time frame", overlay=true) // IsHourlyTF() returns 'true' if the script runs on data with an // hourly time frame (>= 60 minutes and below 1 day). Returns 'false' // otherwise. // <div class="callout callout-warning">
**Note** works on all chart types, including price-based ones.
</div>
IsHourlyTF() => timeframe.isminutes and timeframe.multiplier >= 60 // On the last historical bar, show if the chart uses an // hourly time frame or not if barstate.islastconfirmedhistory labelText = if IsHourlyTF() "This chart uses an\nhourly time frame!" else "This chart's is below 1 hour\nor 1 day and higher" label.new(bar_index + 2, hl2, style=label.style_label_lower_left, color=#D0F0C0, size=size.large, text=labelText)

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.