OPEN-SOURCE SCRIPT
S/R Pivot-Cluster Zones

S/R Pivot-Cluster Zones draws support and resistance as zones, not single lines. Each zone is built from confirmed swing highs and lows that cluster at similar prices, and each zone is labelled with how strong it is. The goal is to replace subjective, hand-drawn levels with a fixed rule set. Two traders using the same settings on the same chart get the same zones.
HOW IT WORKS
Swing pivots. A bar is a swing high if its high is the highest of the bars on each side of it (default 5 bars on each side, an 11-bar window). Swing lows work the same way with the bar’s low. A pivot is confirmed only after those bars have closed. After that it never moves, so confirmed zones do not repaint.
Lookback. Only pivots from the last N bars are used (default 250, about one trading year on a daily chart). This keeps the zones relevant to current price.
Clustering. All pivot prices, highs and lows together, are sorted. A pivot joins the current group when it lies within a set distance of the previous one: 0.5 × ATR(14) by default. Because the distance is based on ATR, it adapts to each instrument’s volatility. A level that acted as resistance and later as support ends up in one zone.
Zone width. Each zone runs from the lowest pivot in its group to the highest, plus a padding of 0.25 × ATR on both sides.
Strength. Every zone is labelled with two numbers:
• piv: the number of swing pivots that formed the zone (separate turning points at this price).
• touches: the number of bars in the lookback whose range traded into the zone (how often the market returned to it).
Classification relative to the current close:
• Green = support (below price)
• Red = resistance (above price)
• Amber = price is currently inside the zone
By default, the nearest zones on each side are shown.
Unconfirmed swing. The most recent high and low, which cannot be confirmed as pivots yet, are drawn as dashed lines. The newest swing stays visible before it becomes a zone.
Table. A small table shows the nearest support and resistance zones and their distance from the current price in percent.
HOW TO USE IT
Use it as a map of where buyers or sellers acted before. It is not a buy or sell signal.
Zones with more pivots and more touches have been more significant in the past. Single-pivot zones are weaker.
A common approach: wait for price to reach a zone, then look for a reaction (a reversal candle, a lower-timeframe structure break, or a volume change) before acting.
A daily close beyond a zone suggests the level is breaking. A broken zone often flips role, so old resistance may act as support.
Daily and weekly charts give the most meaningful swing-trading levels. On intraday charts, zones are smaller and closer together.
SETTINGS
Pivot strength: bars on each side of a swing (default 5). Higher values give fewer, more significant pivots.
Lookback: number of bars to analyse (default 250).
ATR length: default 14.
Cluster distance: how close pivots must be to merge (default 0.5 × ATR).
Zone padding: extra width on each side of a zone (default 0.25 × ATR).
Min pivots per zone: set to 2 or more to show only zones formed by several turning points.
Zones on each side: how many supports and resistances to display.
Show the unconfirmed high/low lines and the summary table (on/off).
Colours for support, resistance and price-inside zones.
NOTES AND LIMITATIONS
Zones are computed on the last bar from confirmed historical pivots. The most recent swing appears as a zone only once it is confirmed (after the set number of bars).
When many pivots sit close together, clustering can produce a wide zone. Treat it as a broad area of interest, not one precise price.
Support and resistance describe past behaviour. Price can move through any zone.
This script is for educational and analytical purposes only and is not financial advice.
HOW IT WORKS
Swing pivots. A bar is a swing high if its high is the highest of the bars on each side of it (default 5 bars on each side, an 11-bar window). Swing lows work the same way with the bar’s low. A pivot is confirmed only after those bars have closed. After that it never moves, so confirmed zones do not repaint.
Lookback. Only pivots from the last N bars are used (default 250, about one trading year on a daily chart). This keeps the zones relevant to current price.
Clustering. All pivot prices, highs and lows together, are sorted. A pivot joins the current group when it lies within a set distance of the previous one: 0.5 × ATR(14) by default. Because the distance is based on ATR, it adapts to each instrument’s volatility. A level that acted as resistance and later as support ends up in one zone.
Zone width. Each zone runs from the lowest pivot in its group to the highest, plus a padding of 0.25 × ATR on both sides.
Strength. Every zone is labelled with two numbers:
• piv: the number of swing pivots that formed the zone (separate turning points at this price).
• touches: the number of bars in the lookback whose range traded into the zone (how often the market returned to it).
Classification relative to the current close:
• Green = support (below price)
• Red = resistance (above price)
• Amber = price is currently inside the zone
By default, the nearest zones on each side are shown.
Unconfirmed swing. The most recent high and low, which cannot be confirmed as pivots yet, are drawn as dashed lines. The newest swing stays visible before it becomes a zone.
Table. A small table shows the nearest support and resistance zones and their distance from the current price in percent.
HOW TO USE IT
Use it as a map of where buyers or sellers acted before. It is not a buy or sell signal.
Zones with more pivots and more touches have been more significant in the past. Single-pivot zones are weaker.
A common approach: wait for price to reach a zone, then look for a reaction (a reversal candle, a lower-timeframe structure break, or a volume change) before acting.
A daily close beyond a zone suggests the level is breaking. A broken zone often flips role, so old resistance may act as support.
Daily and weekly charts give the most meaningful swing-trading levels. On intraday charts, zones are smaller and closer together.
SETTINGS
Pivot strength: bars on each side of a swing (default 5). Higher values give fewer, more significant pivots.
Lookback: number of bars to analyse (default 250).
ATR length: default 14.
Cluster distance: how close pivots must be to merge (default 0.5 × ATR).
Zone padding: extra width on each side of a zone (default 0.25 × ATR).
Min pivots per zone: set to 2 or more to show only zones formed by several turning points.
Zones on each side: how many supports and resistances to display.
Show the unconfirmed high/low lines and the summary table (on/off).
Colours for support, resistance and price-inside zones.
NOTES AND LIMITATIONS
Zones are computed on the last bar from confirmed historical pivots. The most recent swing appears as a zone only once it is confirmed (after the set number of bars).
When many pivots sit close together, clustering can produce a wide zone. Treat it as a broad area of interest, not one precise price.
Support and resistance describe past behaviour. Price can move through any zone.
This script is for educational and analytical purposes only and is not financial advice.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.