PROTECTED SOURCE SCRIPT
Pivot Tops & Bottoms (Enhanced Accuracy)

User Inputs
pivotLen: how many bars to look back on each side when identifying a pivot.
showTops / showBottoms: toggles for drawing top- and bottom-markers.
useATRFilter & atrMult: whether to filter out tiny pivots by requiring their high-low range to exceed ATR×multiplier.
useRSIFilter, rsiLen, rsiOB, rsiOS: optional RSI filter that only permits tops when RSI≥overbought or bottoms when RSI≤oversold.
Raw Pivot Detection
ta.pivothigh(high, pivotLen, pivotLen) returns a true on the bar that confirms a local high (i.e. that bar’s high is higher than the preceding and following pivotLen bars).
ta.pivotlow(low, pivotLen, pivotLen) does the same for local lows.
ATR Filter
We compute ATR over the same lookback (ta.atr(pivotLen)).
We check that the pivot bar’s range (high[pivotLen] – low[pivotLen]) is at least atr * atrMult.
If useATRFilter is off, this check is skipped.
RSI Filter
We compute RSI over rsiLen bars.
For a top, we require rsi[pivotLen] ≥ rsiOB; for a bottom, rsi[pivotLen] ≤ rsiOS.
If useRSIFilter is off, this check is skipped.
Combining Conditions
validTop = raw pivot-high AND (ATR filter passes OR disabled) AND (RSI filter passes OR disabled).
validBottom = raw pivot-low AND (ATR filter passes OR disabled) AND (RSI filter passes OR disabled).
Plotting in Real Time
We call plotshape() with no offset, so as soon as the pivot is confirmed (i.e. once enough future bars exist), the marker appears immediately on that bar.
Red triangles above bars mark tops; green triangles below mark bottoms.
The result is a cleaner pivot indicator: it still only “knows” about a pivot once the lookahead window is filled, but noise is reduced by the ATR and/or RSI filters, and you see your markers as soon as they’re confirmed.
pivotLen: how many bars to look back on each side when identifying a pivot.
showTops / showBottoms: toggles for drawing top- and bottom-markers.
useATRFilter & atrMult: whether to filter out tiny pivots by requiring their high-low range to exceed ATR×multiplier.
useRSIFilter, rsiLen, rsiOB, rsiOS: optional RSI filter that only permits tops when RSI≥overbought or bottoms when RSI≤oversold.
Raw Pivot Detection
ta.pivothigh(high, pivotLen, pivotLen) returns a true on the bar that confirms a local high (i.e. that bar’s high is higher than the preceding and following pivotLen bars).
ta.pivotlow(low, pivotLen, pivotLen) does the same for local lows.
ATR Filter
We compute ATR over the same lookback (ta.atr(pivotLen)).
We check that the pivot bar’s range (high[pivotLen] – low[pivotLen]) is at least atr * atrMult.
If useATRFilter is off, this check is skipped.
RSI Filter
We compute RSI over rsiLen bars.
For a top, we require rsi[pivotLen] ≥ rsiOB; for a bottom, rsi[pivotLen] ≤ rsiOS.
If useRSIFilter is off, this check is skipped.
Combining Conditions
validTop = raw pivot-high AND (ATR filter passes OR disabled) AND (RSI filter passes OR disabled).
validBottom = raw pivot-low AND (ATR filter passes OR disabled) AND (RSI filter passes OR disabled).
Plotting in Real Time
We call plotshape() with no offset, so as soon as the pivot is confirmed (i.e. once enough future bars exist), the marker appears immediately on that bar.
Red triangles above bars mark tops; green triangles below mark bottoms.
The result is a cleaner pivot indicator: it still only “knows” about a pivot once the lookahead window is filled, but noise is reduced by the ATR and/or RSI filters, and you see your markers as soon as they’re confirmed.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.