Skip to content

Look if TradingView script runs on weekly time frame with Pine Script

Look if TradingView script runs on weekly time frame with Pine Script

Section titled “Look if TradingView script runs on weekly time frame with Pine Script”

TL;DR
timeframe.isweekly returns true whenever the active chart resolution is expressed in weeks (1W, 2W, …). Use it to branch logic or show chart-aware labels.

DifficultyBeginner
Time to implement5-10 min
CategoryTime & Sessions
//@version=5
indicator("Weekly detector", overlay=true)
isWeekly = timeframe.isweekly
if barstate.islast
txt = isWeekly ? "You're on a weekly chart" : "Not a weekly chart"
label.new(bar_index, close, txt + "\nPeriod: " + timeframe.period,
style=label.style_label_left,
textcolor=color.white,
bgcolor=color.new(isWeekly ? color.green : color.orange, 70))
Tip. Time-frame flags are driven by resolution, not chart style. `timeframe.isweekly` works the same on candles, Renko, or Heikin Ashi—as long as the chart is set to a weekly interval.

Some strategies only make sense on weekly data, while others should disable themselves to avoid misleading signals. Detecting weekly charts lets you adjust defaults, run heavier calculations, or warn the user when they’re on an unsupported resolution.

  • How timeframe.isweekly behaves across chart resolutions.
  • Combine the weekly flag with other time-frame helpers and multipliers.
  • Present chart-aware labels, alerts, or parameter changes when weekly mode is active.
  • Best practices to avoid unnecessary checks each bar.
HelperPurpose
timeframe.isweeklytrue for weekly-based bars (1W, 2W, etc.).
timeframe.periodHuman-readable period string ("W", "2W").
timeframe.multiplierNumeric multiplier for the current period (1 for 1W, 4 for 4W).
barstate.islastconfirmedhistoryRuns logic once on the last historical bar—useful for labels.
request.security(symbol, timeframe, expression)Fetch higher/lower time frame data when weekly is detected.
  1. Check the weekly flag
    Evaluate timeframe.isweekly once per bar and cache the result.

    isWeekly = timeframe.isweekly
  2. Branch behaviour
    Use the flag to enable or skip logic, choose settings, or show notices.

    emaLen = isWeekly ? 13 : 55
    weeklyOnlySignal = isWeekly and ta.crossover(close, ta.ema(close, emaLen))
  3. (Optional) Fetch helper data
    Pair with timeframe.period or timeframe.multiplier for labels, or load additional series via request.security.

    weeklyMultiplier = timeframe.multiplier
//@version=5
indicator("Weekly-aware trend filter", overlay=true, max_labels_count=500)
fastLen = input.int(13, "EMA length (weekly)")
slowLen = input.int(55, "EMA length (non-weekly)")
isWeekly = timeframe.isweekly
ema = ta.ema(close, isWeekly ? fastLen : slowLen)
plot(ema, "Adaptive EMA", color=color.new(color.blue, 0))
trendUp = close > ema
bgcolor(isWeekly ? color.new(color.green, 88) : na, title="Weekly backdrop")
if barstate.islast
label.new(bar_index, close,
text="Weekly: " + (isWeekly ? "YES" : "NO") +
"\nPeriod: " + timeframe.period +
"\nMultiplier: " + str.tostring(timeframe.multiplier),
style=label.style_label_left,
textcolor=color.white,
bgcolor=color.new(isWeekly ? color.green : color.gray, 70))
Why this works.
  • EMA length adapts automatically, so the same script stays responsive on weekly and non-weekly charts.
  • Background colouring highlights when the chart runs in weekly mode.
  • A summary label confirms the active period and multiplier for quick debugging.
  • Weekly flags encompass “multi-week” resolutions (2W, 4W). Use timeframe.multiplier to differentiate them.
  • Combine with timeframe.isdwm to catch daily/weekly/monthly groupings in one conditional when needed.
  • If you only want to run heavy logic once per new week, pair timeframe.isweekly with ta.change(time("W")).
  • When disabling trades, ensure you also cancel pending orders to avoid unexpected fills.

Double-check the chart resolution; custom ranges (e.g., 10 range) are not weekly data. Switch to a weekly preset like 1W or 2W.

Use the other helpers: timeframe.ismonthly, timeframe.isdaily, etc. You can also compare timeframe.multiplier against thresholds (timeframe.isweekly and timeframe.multiplier >= 4).

No. The flag is based entirely on bar timing, so Renko, Line Break, and Heikin Ashi still honour the weekly interval behind the scenes.

  • timeframe.isweekly tells you when the chart uses a weekly-based resolution.
  • Use the flag to enable/disable logic, adjust parameters, or show user-facing guidance.
  • Pair with timeframe.period/timeframe.multiplier for richer context or to differentiate multi-week settings.
  • Keep weekly-specific work lightweight by running infrequent tasks on barstate.islast or ta.change(time("W")).

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