Confirmed Pivot Structure with an ATR Range Gate in Pine Script v6

Advanced Trading Tutorial · TradingView indicator architecture

Most pivot indicators make an old turning point look immediately obvious. In live trading it is not: a pivot needs future bars to confirm it. This study separates the historical pivot location from the actual confirmation event, then rejects small-range pivot candles relative to ATR. The result is a transparent market-structure research tool, not an order-entry system.

What is actually known at each bar?

A pivot high with four bars to its left and three to its right can only be confirmed after those three right-hand bars have closed. The marker is deliberately plotted on the confirmation bar, not retroactively on the turning-point candle. That avoids visually suggesting a signal was available earlier. The same logic applies to pivot lows.

Confirmed Pivot Structure with an ATR Range Gate in Pine Script v6
Illustrative logic: pivot confirmation, volatility gate, then closed-bar alert. Not historical prices.

Two distinct filters

First, structural confirmation requires a candidate high above the surrounding left/right highs, or a low below surrounding lows, as defined by TradingView's built-in pivot functions. Second, volatility qualification requires the pivot candle's high-low range divided by ATR at that same pivot candle to be at least the configured threshold. ATR is Wilder's average true range, which includes gaps in true range; the numerator here is simply high minus low. These are intentionally different measurements.

For a hypothetical pivot candle with high 105.20, low 103.70 and ATR 1.20, the ratio is 1.50 / 1.20 = 1.25. With a threshold of 1.00 it qualifies, assuming the pivot is confirmed three bars later. At a threshold of 1.50 it fails. A large wick can qualify without establishing a profitable directional opportunity.

Settings and interpretation

Input Default Research trade-off
Left bars 4 More bars emphasize larger structures
Right bars 3 More confirmation delay, fewer pivots
ATR length 14 Shorter lengths respond faster to volatility
Minimum range / ATR 1.0 Higher thresholds exclude quieter pivot candles

Resistance and support lines update only when a new qualifying pivot is confirmed. They are reference levels, not automatically executable breakout orders. An alert is triggered on the confirmation bar and should be configured as Once Per Bar Close. The code uses barstate.isconfirmed so historical and real-time behavior are closer at bar close; nonetheless historical intrabar sequences cannot be reconstructed from a standard bar chart.

Complete Pine Script v6 source

//@version=6
indicator("Confirmed Pivot ATR Gate", overlay=true, max_labels_count=300)
// Confirmation requires rightBars completed bars.
leftBars = input.int(4, "Pivot left bars", minval=1)
rightBars = input.int(3, "Pivot right bars", minval=1)
atrLength = input.int(14, "ATR length", minval=1)
minRangeATR = input.float(1.0, "Minimum pivot-bar range / ATR", minval=0.0, step=0.1)
showLevels = input.bool(true, "Show last confirmed levels")
atrNow = ta.atr(atrLength)
pivotHigh = ta.pivothigh(high, leftBars, rightBars)
pivotLow = ta.pivotlow(low, leftBars, rightBars)
pivotRange = high[rightBars] - low[rightBars]
pivotATR = atrNow[rightBars]
rangeOK = not na(pivotATR) and pivotATR > 0 and pivotRange / pivotATR >= minRangeATR
confirmedHigh = barstate.isconfirmed and not na(pivotHigh) and rangeOK
confirmedLow = barstate.isconfirmed and not na(pivotLow) and rangeOK
var float lastHigh = na
var float lastLow = na
if confirmedHigh
    lastHigh := pivotHigh
if confirmedLow
    lastLow := pivotLow
plot(showLevels ? lastHigh : na, "Confirmed resistance", color=color.red, style=plot.style_stepline)
plot(showLevels ? lastLow : na, "Confirmed support", color=color.teal, style=plot.style_stepline)
plotshape(confirmedHigh, title="High confirmation", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)
plotshape(confirmedLow, title="Low confirmation", style=shape.triangleup, location=location.belowbar, color=color.teal, size=size.tiny)
alertcondition(confirmedHigh, "High pivot confirmed", "Confirmed high pivot with ATR range filter")
alertcondition(confirmedLow, "Low pivot confirmed", "Confirmed low pivot with ATR range filter")

Install and inspect

  1. Open TradingView Pine Editor, create a new indicator, replace its content with the complete listing and add it to the chart.
  2. Start with liquid symbols and a familiar timeframe. Inspect each triangle: it should appear three bars after its associated pivot candle, not on the pivot itself.
  3. Change the ATR threshold from 0.5 to 1.5 and compare event counts over the same fixed historical sample.
  4. Create alerts for either confirmation condition and select Once Per Bar Close. Check the chart's exchange timezone and session settings.

Failure modes and validation protocol

Do not confuse a pivot's plotted historical level with an actionable signal on that historical candle. A rising market can generate repeated high pivots without a short opportunity. Low-volume instruments may have unreliable highs and lows. ATR is price-unit based and the ratio normalizes within one symbol but does not make every asset or timeframe comparable. Right-side confirmation adds unavoidable latency; lowering it increases noise. The pivot functions' equal-high handling should be reviewed on symbols with repeated prices.

For validation, manually record the candidate candle index, its high-low range, ATR at that index, the three subsequent candles and the confirmation candle. Recalculate the ratio independently. Compare bar-close alerts with the visual markers, test flat markets and gaps, and run a separate out-of-sample segment. There is no backtest performance claim here. Compile and review the code in your own TradingView environment before use.

Interested in adapting this free indicator to your own structure rules, alerts or execution workflow? Explore our Custom Trading Software Development Services to discuss requirements.

Trading involves substantial risk. This educational study does not predict prices, guarantee profitable signals, or replace independent risk controls.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.