OPEN-SOURCE SCRIPT
已更新

Price Density S&R

1 009
Price Density S&R

Price Density S&R is a price-action based support and resistance indicator designed to identify levels where market activity has repeatedly concentrated over a selected historical period.

Instead of relying on pivot points, oscillators, or volume-based calculations, the script analyzes historical price interactions and groups nearby price points into density zones. Areas that receive repeated interactions are considered potentially significant market levels and are displayed as dynamic support and resistance lines.

How It Works

The indicator scans historical candles within a user-defined lookback range and collects high, low, and closing prices.

Nearby prices are automatically clustered into zones using a configurable merge threshold. Every time price revisits a zone, the interaction count increases. Zones with the highest interaction frequency are prioritized and displayed on the chart.

The result is a map of price levels that have historically attracted repeated market attention.

Features

• Automatic support and resistance detection

• Price-density clustering algorithm

• Adjustable lookback period

• Customizable zone sensitivity

• Minimum touch-count filtering

• Dynamic level ranking based on interaction frequency

• Visual distinction between support and resistance zones

• Optional touch-count labels

• Lightweight and chart-friendly design

Settings

Lookback Bars:
Defines how many historical bars are analyzed.

Zone Merge Threshold:
Controls how aggressively nearby prices are grouped together.

Minimum Touch Count:
Filters out weaker levels with insufficient historical interactions.

Maximum Levels:
Limits the number of displayed support and resistance levels.

Interpretation

Levels with higher touch counts indicate areas where price has historically interacted more frequently. These zones may represent areas of market interest, potential reactions, consolidation, or previous balance between buyers and sellers.

As with all technical analysis tools, historical interactions do not guarantee future market behavior. The indicator should be used alongside broader market context, trend analysis, and risk management techniques.

Notes

This indicator is designed as a visual market-structure tool and does not generate buy or sell signals. It is intended to help traders identify historically active price regions that may be relevant during future market analysis.
版本注释
### How It Works — Technical Details

This indicator builds support and resistance levels using a price density
approach rather than pivot detection. On each historical bar within the
lookback range, three price values are sampled: the high, the low, and
the close. This three-point sampling per bar means that every candle
contributes up to three data points to the density map, giving the
algorithm a more complete picture of where price has actually traded
rather than only where it reversed.

Each sampled price is passed through a zone-matching function. If the
incoming price falls within the Zone Merge Threshold (%) of an existing
zone center, it is merged into that zone and the interaction count
increments by one. The zone center is recalculated as a weighted average
of all contributing prices, so it naturally drifts toward the most
visited sub-region within the zone. If no existing zone is close enough,
a new zone is created with an initial count of one.

Once all bars are processed, zones are sorted in descending order by
interaction count using a bubble sort algorithm. The top-ranked zones
that meet the Minimum Touch Count threshold are then passed through a
secondary overlap filter: any candidate zone whose center falls within
2× the Zone Merge Threshold of an already-drawn level is skipped. This
two-stage filtering ensures that only the strongest, non-redundant levels
are rendered on the chart.

### How To Use

1. Set Lookback Bars to cover the market structure you want to analyze:
— 200–500 bars: short to medium-term structure
— 1000–3000 bars: major historical levels
2. Zone Merge Threshold controls zone sensitivity:
— Crypto: 0.4–0.8% works well for volatile assets
— Forex: 0.05–0.15% recommended for tight price action
— Equities: 0.2–0.4% recommended
3. Minimum Touch Count filters noise:
— Set higher (8–15) in trending markets to keep only the strongest levels
— Set lower (3–5) in ranging markets to capture more detail
4. Maximum Levels limits visual clutter — 8 to 13 is recommended for
readability on most chart layouts
5. Levels with the highest touch counts are drawn first — the top lines
on the chart represent the most historically significant price areas

### Originality

This script is an original work implementing a price density clustering
method for support and resistance detection. Unlike pivot-based approaches
that identify levels from swing highs and lows only, this indicator samples
high, low, and close on every bar and uses a weighted average zone-merging
algorithm to dynamically build and update zone centers. The combination of
three-point per-bar sampling, weighted centroid recalculation, and the
two-stage overlap filter (zone threshold + 2× secondary pass) represents
the author's own implementation and is not derived from any existing
published script.

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。