TradingView indicator guides

52-Week High and Low: Completed Weeks and Lookahead

A weekly range needs an explicit cutoff. This example plots extremes from the previous 52 completed weekly bars, excluding the current week. It is a stable reference for the current week, not a live measure that incorporates each new high or low. The distinction matters when comparing price against a breakout threshold.

Inspect the Pine Script

Use a window definition that can be checked

At the start of a new weekly bar, take the highest high and lowest low among the preceding 52 weekly bars. A close-only option instead takes the maximum and minimum of those weekly closes. Neither calculation averages away a wick in high/low mode: a single valid spike can determine the upper boundary.

Fifty-two weekly bars are a bar-count window, approximately a year, not an exact trailing calendar-year filter. Exchange sessions, partial weeks and missing observations affect which dates it covers. A 364-daily-bar window is a different selection; its calendar span depends on the instrument’s trading calendar.

The script requires 52 available completed weekly observations with valid selected prices before showing levels. A shorter listing can still produce a partial-window maximum in an unguarded highest/lowest calculation, but this adaptation deliberately hides it rather than labeling it a complete 52-week range.

Why the earlier unshifted request is unsuitable for historical signals

The product helper inspected for this guide requests the current weekly highest/lowest with lookahead_on and no expression offset. On historical lower-timeframe bars, that can expose a final weekly extreme before it was known. This is more than the ordinary movement of an unfinished realtime week.

The teaching example below changes that contract: each weekly expression is shifted by one weekly bar inside the requested context, then paired with lookahead_on. It follows TradingView’s confirmed higher-timeframe request pattern. A shift applied after the request would mean a chart-bar delay, not necessarily a weekly delay.

This page adaptation does not establish that the shared product helper has been changed. Compare generated source before using it for historical conditions. The example rejects timeframes above one week; it is intended for standard time-based charts at or below one week, not lower-timeframe sampling inside monthly or synthetic bars.

Check a weekly update with hypothetical prices

Assume the previous 52 completed weekly bars have an upper extreme of 110 and a lower extreme of 80. On Monday, price reaches 112 and closes at 111. This example keeps the current week’s upper reference at 110, so 111 is above that prior threshold. A live high including Monday is at least 112, and the same close cannot exceed it.

Suppose Friday later raises the weekly high to 118. An unshifted weekly request with historical lookahead can place 118 back on Monday’s historical bar. Monday did not have that information. The confirmed example remains at 110 throughout the week and incorporates 118 only when the next week begins, assuming no higher retained high.

A rolling boundary can also fall without a new downward price move. In a shorter three-week analogy, completed highs 130, 110 and 112 give an upper level of 130. After a week with high 111 completes, the retained set becomes 110, 112 and 111, giving 112. The old maximum aged out. The same mechanism applies to a 52-bar window.

Separate a current extreme from a breakout threshold

On standard OHLC data, the current close cannot be strictly above a highest-high window that already includes the current bar’s high. Likewise it cannot be below a lowest-low window that includes its own low. A close-only maximum including the current close also cannot be strictly below that close. A breakout test therefore needs a prior threshold or another explicitly defined exclusion.

Being above a prior weekly level is a state. A newly crossed level, an intrabar touch and a close-confirmed crossing are different events. A boundary can change at the weekly rollover, so a cross can partly reflect the reference changing rather than price accelerating. This script supplies only levels; it has no alerts, entry rules, stops, orders or measured strategy results.

For a range position, use (price − lower) / (upper − lower) only when width is positive. With bounds 80 and 110, price 95 is halfway through the range; price 111 gives about 1.0333 and lies above it. That ratio is not a probability. Width relative to the lower price is a different measure and needs a valid, nonzero denominator.

Keep plotting and data adjustments separate

The example plots an unshifted step series so each historical level stays aligned with when it became available. In the earlier display, offset = −9999 moved plot points far into the past; it did not extend a historically valid range. trackprice supplies a last-value dotted guide. TradingView documents those separate plot controls.

Match the symbol, session, chart type and adjustment settings before comparing levels with another source. Do not assume dividend adjustments are always enabled: TradingView provides an optional dividend adjustment setting. Futures rolls, adjusted stock histories and data revisions can also change long-range extrema.

Close-only extrema ignore weekly wicks but are not proven more reliable support or resistance. A high or low reference does not reveal institutional order flow, guarantee a rebound or identify a full crypto cycle. Compare the highest-value function and Donchian window construction when you need a different cutoff or length.

Pine Script v6: implementation and limits

This educational adaptation intentionally differs from the shared helper: completed-week expressions, a valid-window gate, a close-only input, a timeframe restriction and historically aligned step plots. It does not add trading signals or claim immunity from data-provider revisions.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// (c) Pineify
//@version=6
// Educational adaptation: previous 52 completed weekly bars, no future leak.
indicator("Previous 52 completed weeks: high/low", overlay=true)
useClose = input.bool(false, "Use weekly closes instead of highs/lows")
if timeframe.in_seconds() > timeframe.in_seconds("1W")
    runtime.error("Use a time-based chart at or below one week.")
weeklyRange() =>
    upper = ta.highest(useClose ? close : high, 52)
    lower = ta.lowest(useClose ? close : low, 52)
    valid = useClose ? not na(close) : not na(high) and not na(low)
    validCount = math.sum(valid ? 1.0 : 0.0, 52)
    [upper[1], lower[1], validCount[1]]
[upper, lower, count] = request.security(syminfo.tickerid, "1W", weeklyRange(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
ready = not na(count) and count == 52
plot(ready ? upper : na, "Previous 52 weeks upper", color=color.orange, style=plot.style_stepline)
plot(ready ? lower : na, "Previous 52 weeks lower", color=color.teal, style=plot.style_stepline)
Existing indicator chart preview
Existing visual preview. Verify exact values against the source; the image is not a performance result.

Specify a checkable adaptation in Pineify

Specify whether your desired range includes the active week or only completed weeks. Ask the Pine Script AI Coding Agent to explain its request offset, supported chart timeframes, missing-history policy and any alert confirmation separately. Verify a weekly rollover and a new intraweek extreme against the source before testing order rules.

Open Pine Script AI Coding Agent

Educational indicator analysis. No measured trading performance is established here. Syntax validation does not prove formula equivalence, execution assumptions or profitability.

Implementation questions

No. It uses the previous 52 completed weekly bars and updates the reference when a new weekly bar begins. It is not the live current-inclusive 52-week range.

The offset retrieves already completed weekly data. Used together in the requested expression, the pair aligns those known values with the new week rather than leaking that week’s future result.

Not on consistent standard OHLC data when that current bar is included in the maximum. Use a prior reference and define exactly which bars it excludes.

No. It is a weekly bar-count window. Calendar boundaries, sessions and missing history can make it differ from a date-based trailing-year range.

This adaptation requires 52 valid completed weekly observations. An unguarded highest/lowest may return a shorter-history extreme, which is not a complete 52-week range.

This page provides a separate confirmed-week adaptation. The inspected shared helper uses unshifted weekly expressions, so inspect generated code independently before relying on historical signals.