Gate Levels (S/R Zones)

533
Gate Levels (S/R Zones) — True Swing-Pivot Zones

OVERVIEW
This indicator draws dynamic support and resistance bands from real swing pivots in price. It walks the chart with a percentage zigzag, saves every significant reversal origin, clusters nearby pivots into zones, ranks them by recency-weighted swing force, and extends the strongest + nearest-to-price levels as horizontal bands across the entire chart.


HOW IT WORKS

1. Percent zigzag swing detection
The script scans the last N bars and builds alternating up/down legs. A leg continues until price gives back a configurable percentage against the running extreme. When that happens:
- the completed leg's origin is saved as a candidate pivot
- a new opposite-direction leg is seeded from the extreme
This produces a clean sequence of true swing lows (up-leg origins) and true swing highs (down-leg origins), where each pivot is validated by an actual X% opposing move.

2. Provisional running pivot
The still-open leg's current extreme is also added as a candidate. This keeps the nearest developing level alive even before the swing fully matures.

3. Recency decay
Every pivot starts with a raw score equal to the size of the move that created it (in percent). That score is then decayed by the bar's age:
decayed_score = raw_score * decayBase ^ (bars_ago / 365.25)
The default base is 0.85, normalized to ~365 bars of the active timeframe. Recent swings outrank old ones, so the zones stay relevant to current market structure instead of being dominated by ancient history.

4. Clustering into zones
Pivots are sorted by price and merged when one lies within the Cluster merge % of the previous cluster's midpoint. The merged midpoint becomes a running average of the clustered pivots. Each zone tracks its high/low extremes, total decayed score, and number of touches.

5. Filtering and ranking
Zones with fewer than Min touches per zone are discarded. Remaining zones are ranked by total decayed score, and the top Top-ranked zones are selected.

6. Nearest-to-price guarantee
Even if the highest-score zones are far away, the script also forces the 2 nearest zones above price and the 2 nearest zones below price into the visible set. This ensures you always see the levels actually in play around current price.

7. Band drawing
Each selected zone is drawn as three horizontal lines (top, midpoint, bottom) that extend infinitely left and right. The midpoint is dashed; the upper/lower borders define the zone thickness.
- Zones above current price are tinted red (resistance)
- Zones below current price are tinted green (support)

TIMEFRAME HANDLING
A fixed 7% swing threshold produces almost nothing on low timeframes and too few levels on very high timeframes. To solve this, the script includes ATR-scaled swing mode (on by default):
effective_swing_pct = ATR(14) / close * 100 * ATR multiplier
Because ATR naturally scales with timeframe and volatility, the indicator produces meaningful zones on 15m, 1H, 4H, daily, and weekly charts without retuning.

INPUTS
Lookback bars : How many bars to scan for swing pivots. Limited to 500 by Pine's loop cap.
Fixed swing zigzag % : Manual swing threshold when ATR scaling is off.
Use ATR-scaled swing % : Auto-scale the threshold by volatility/timeframe.
ATR multiplier : Multiplier applied to the ATR%-of-price reading.
Cluster merge % : Maximum distance between two pivots to merge into the same zone.
Band thickness % : Half-thickness of each drawn band, as % of the zone midpoint.
Min touches per zone : Minimum clustered pivots before a zone is valid.
Top-ranked zones : How many top-scored zones to keep.
Recency decay base : Decay factor; higher = older pivots matter more.

HOW TO USE
1. Add the indicator to any chart.
2. Set the timeframe to the one you trade.
3. If no levels appear:
- lower ATR multiplier for smaller/more frequent levels
- lower Min touches per zone to 1
- increase Lookback bars to 500
4. Strong, widely-separated zones are high-probability S/R.
5. The nearest zones above and below current price are the most immediately relevant.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.