TradingView indicator guides

ta.highest() in Pine Script: Windows and Breakout Timing

ta.highest() returns a rolling maximum. This reference plots the highest high over five bars, including the current bar. It draws a price level; it does not place orders, establish resistance strength or detect a breakout above a prior range automatically.

Inspect the Pine Script

Choose the window and the source explicitly

On a complete window of valid observations, ta.highest(source, N) is max(source[0], source[1], …, source[N−1]). The current value is included. The one-argument overload ta.highest(N) uses high as its source; the two-argument form lets you choose a different numeric series.

The displayed helper call fixes high and length 5. Five is this example’s setting, not a built-in default length. The code does not expose a source or length input in Settings. If a rule requires a complete window of valid data, enforce that requirement explicitly; the snippet adds no readiness or missing-data policy beyond the built-in function.

The output has the same units as the source. Highest close is a closing-price maximum, while highest volume is a volume maximum and should not be interpreted as a price level. For valid OHLC over the same window, highest close cannot exceed highest high, but the two can be equal.

Worked window: a breakout above the previous range

Assume the five completed highs before the current bar are 100, 103, 101, 102 and 104, oldest to newest. Their maximum is 104. A new candle has high 106 and close 105. The current five-bar window drops 100 and includes 106, so its maximum is now 106.

The close of 105 exceeds the previous five-bar maximum of 104. It does not exceed the current maximum of 106. In valid OHLC data, close ≤ high ≤ ta.highest(high, N), making a strict close above that current maximum impossible. Equality at a new high is a touch, not a strict crossover above it.

For a previous-window reference with a fixed N, ta.highest(high, N)[1] takes yesterday’s completed rolling result; ta.highest(high[1], N) scans highs from one through N bars ago. Compute the rolling series consistently on every bar. These references exclude the developing current high but still advance when a new bar begins.

A state such as “close is above the previous range” differs from “first transition above it.” Specify which event you want, the treatment of equality and whether it must wait for bar close. The source below only draws the current-window maximum; it does not implement either breakout event.

A rolling maximum can fall without rewriting the past

Consider a five-bar high window [110, 105, 104, 103, 102]. Its maximum is 110. If the next high is 106, the oldest 110 leaves the window and the new maximum is 106. The maximum drops even though the newest high rose from 102 to 106. A line drop alone therefore does not prove that the current bar made a lower high.

That new value belongs to the new bar. It does not revise the maximum previously calculated on an earlier closed bar merely because the window moved. On the open bar, however, its high can develop and increase the current maximum. Changes to the source data, settings or chart context can also change results after recalculation.

TradingView’s repainting documentation distinguishes developing values from historical-data differences. Using a previous-bar range makes that reference fixed within the current bar; it is not a universal guarantee against all data revisions or other repainting logic elsewhere in a script.

Keep maximum values, offsets and namespace versions separate

ta.highest() returns the maximum value. ta.highestbars() returns the bar offset locating an occurrence of that maximum; it is not a price. ta.lowest() returns a minimum. TradingView’s time-and-date examples use the value and offset functions separately to locate extrema.

The ta namespace migration belongs to Pine v5, not v4. The official v5 migration guide maps the older highest name to ta.highest. Use the namespaced built-in in v6. An unqualified highest name would need an appropriate user definition; it is not a general backward-compatible alias in this source.

A function available in Pine is not necessarily a separately named built-in indicator in the chart’s search menu. Pasting this small reference makes the exact formula and window inspectable. No undocumented claim about TradingView’s internal deque or execution complexity is needed to use the function correctly.

A highest-high anchor is not a complete trailing stop

A long-position protective stop normally requires a level below the relevant market price and explicit order behavior. The current highest high is at or above the close, so using that value directly as a long sell-stop level is not a conventional protective trailing stop.

A high-minus-ATR level is a candidate construction. It can move down when an old high leaves the window or ATR increases. A one-way trailing rule must retain the maximum of the new candidate and the previously retained stop throughout a position, then reset correctly for the next position. Taking only the maximum of two recent raw candidates does not enforce an enduring ratchet.

A rule to exit after a close below a level is also different from an intrabar stop order. Define calculation timing, order submission, gaps, fills, position sizing and costs before testing. ATR does not guarantee that a stop avoids noise or limits the realized loss to its plotted distance.

Pair the maximum with ta.lowest() for range boundaries, or inspect Fibonacci Zone for levels inside a rolling range. A range is an observation, not a return forecast.

Pine Script v6: implementation and limits

Paste this complete indicator into Pine Editor and compare the green line with the maximum of five visible candle highs. It uses the current bar and has no alerts, trades or input controls. Use a separate previous-window reference if that is your intended signal.

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/
// © Pineify

//@version=6
indicator(title="Highest Value", overlay=true, max_labels_count=500)

// ta.highest(source, length) returns the highest value of the source series
// over the specified lookback period. Defaults: source=high, length=5
p_ta_highest(series float source, simple int length) =>
    ta.highest(source, length)

p_ind_1 = p_ta_highest(high, 5)  // 5-bar highest high

// Plot highest value as a continuous line overlaid on price
plot(p_ind_1, "Highest Value", color=color.new(color.green, 0), linewidth=1)

Specify a checkable adaptation in Pineify

Specify the source, positive lookback, inclusion or exclusion of the current bar and any complete-history requirement. For a breakout request, distinguish a persistent above-range state from a transition and require the intended confirmation timing. Request syntax checking and verify a known rolling window before adding orders.

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

For nested windows ending on the same bar with valid data, the larger window’s maximum is at least as high because it contains all observations in the smaller one. It can be equal. This does not guarantee a flatter path over time or fewer losing signals.

Not on valid OHLC when that maximum includes the current bar. Close is no higher than the current high, which is no higher than the window maximum. Use a precisely defined prior or fixed range if a breakout is intended.

Advancing the window calculates a result for the new bar; it does not itself rewrite earlier closed-bar outputs. Open-bar highs can develop. Revised data, changed settings and other code can still alter recalculated history.

It is a literal in the helper call. The snippet has no input controls. Change the call or request editable source and length with a positive minimum, then verify the resulting source.

For an available source value, the current source is the whole window. With high as source, the result is the current high. It is not a prior resistance level.

No. This page establishes the window arithmetic and implementation boundaries. Any trading filter needs explicit rules and a separate evaluation with execution costs and reserved data.