OPEN-SOURCE SCRIPT

Liquidity Depth [UAlgo]

5 384
Liquidity Depth is a price distribution and participation map designed to show where market activity has concentrated across a recent trading range. Instead of focusing only on candle by candle direction, the script builds a structured profile of how volume has been allocated across price levels inside a rolling lookback window. The result is a visual depth curve that helps identify areas where buyers or sellers may have shown stronger relative presence.

The indicator works by taking the highest and lowest prices inside the selected lookback, dividing that range into evenly spaced bins, and then assigning bar volume into those bins using one of two distribution models. This transforms raw volume into a spatial map of activity, allowing traders to see where liquidity has accumulated rather than simply when it appeared.

A central strength of the script is that it separates participation into buy side and sell side estimates using candle direction as a practical heuristic. Bullish candles contribute to the buy side profile and bearish candles contribute to the sell side profile. While this is not exchange level bid ask data, it creates a highly usable approximation of directional participation that is often more intuitive for chart based analysis.

The profile is drawn directly on the chart as a right side structure with smoothed depth curves, shaded fills, a Point of Control line, contextual range framing, and automatically detected strong liquidity pockets. This makes the tool especially useful for traders who want to study where activity is clustering, where resistance or support may be forming, and which parts of the recent range are attracting stronger participation.

Because the output is overlay based and visually compact, Liquidity Depth can be used in a wide variety of workflows. It can complement trend analysis, help frame pullback entries, identify acceptance and rejection zones, or simply provide a clearer understanding of where recent market interest has been strongest.

🔹 Features

🔸 Price Range Liquidity Mapping
The script scans a rolling lookback window, identifies the active price range, and divides that space into a configurable number of bins. Each bin becomes a small price segment where participation is accumulated. This produces a clear distribution style view of liquidity across the full recent range.

🔸 Two Distribution Modes
The indicator supports two ways of assigning volume into the profile.

Close Bin places the full bar volume into the single bin that contains the closing price. This creates a sharper and more concentrated structure that emphasizes where bars finished.

Wick Spread distributes the bar volume evenly across all bins touched by the candle from low to high. This produces a broader and more spatially balanced profile that better represents the full path of the bar through price.

These two modes give the user control over whether the profile should be more precise and concentrated or more inclusive and range aware.

🔸 Buy Side and Sell Side Separation
The script maintains separate depth values for buying and selling participation. Bullish candles add volume to the buy side and bearish candles add volume to the sell side. This creates two distinct distribution curves that help reveal whether the lower part of the range is showing stronger buying interest or whether the upper part is attracting stronger selling interest.

🔸 Smoothed Liquidity Curves
Instead of plotting raw bin values only, the script applies curve smoothing to the side distributions. This creates a cleaner, more readable shape that reduces visual noise and highlights the underlying structure of participation. The result is a profile that feels fluid and analytical rather than fragmented.

🔸 Glow Enhanced Curve Rendering
The current build uses a glow style rendering around the main liquidity curves. This improves visual separation on the chart and makes strong participation bulges easier to recognize at a glance, especially when the profile is viewed on darker chart themes.

🔸 Automatic Strong Pocket Detection
One of the most practical parts of the script is its ability to detect strong liquidity pockets. These are clusters of consecutive bins where smoothed participation exceeds a chosen strength threshold. When found, the script highlights the zone and labels it as a strong buy pocket or strong sell pocket. These pockets can be useful for identifying areas of acceptance, defense, or possible future reaction.

🔸 Point of Control Highlighting
The indicator finds the price bin with the highest total participation and marks it as the Point of Control. This is the most active price area inside the profile and often serves as an important reference for equilibrium, attraction, or repeated interaction.

🔸 Range Frame and Midpoint Context
A visual frame is drawn around the active profile range, including the highest level, the lowest level, and the midpoint. This gives the distribution a clear structure and helps the user understand where participation is concentrated relative to the center of the recent range.

🔸 Side Summary Readout
The script prints a compact summary that shows estimated buy side and sell side percentages, along with total side volumes. This provides a quick interpretation layer so the user can understand the current balance of participation without needing to inspect each curve manually.

🔸 Theme Adaptive Colors
Colors are selected dynamically according to the chart background tone. This helps the profile remain readable across both light and dark themes while preserving clear differentiation between buy side, sell side, frame lines, and Point of Control.

🔸 Efficient Object Management
All boxes, lines, fills, and labels are refreshed on the last visible bar so the profile stays clean and up to date. Internal object arrays are actively cleared and rebuilt, which keeps the display organized and avoids uncontrolled accumulation of chart objects.

🔹 Calculations

1) Active Range Construction
The script begins by defining the working range from the highest high and lowest low across the selected lookback window. This creates the vertical space where the full profile will be built.

The total span is then divided into the configured number of bins, which creates evenly spaced price segments from the bottom of the range to the top. Each bin stores its lower boundary, upper boundary, midpoint, buy volume, sell volume, and total volume.

In practical terms, this means the indicator converts the recent market range into a structured ladder of price levels so activity can be measured spatially.

2) Bin Initialization
Once the range is known, every bin is reset and rebuilt. Each bin receives:
its lower boundary,
its upper boundary,
its midpoint,
and empty participation values for buy, sell, and total activity.

This reset process ensures that the profile always reflects only the current rolling window rather than carrying stale values from older bars.

3) Volume Assignment Logic
For every bar inside the lookback, the script reads the volume and determines whether the candle is bullish or bearish. From there, distribution depends on the selected mode.

With Close Bin, the full bar volume is assigned to the bin that contains the close. If the candle is bullish, that volume is counted on the buy side. If the candle is bearish, it is counted on the sell side.

With Wick Spread, the script finds every bin touched between the candle low and candle high. The bar volume is divided evenly across those crossed bins. That distributed share is then assigned entirely to the buy side for bullish candles or entirely to the sell side for bearish candles.

This approach creates a practical estimate of where participation occurred across price, while also preserving directional context.

4) Total Participation and Point of Control
After all bars are processed, each bin contains a buy volume, a sell volume, and a total volume equal to the sum of the two. The script then scans the full array of bins to find the highest total value. The bin with that maximum total becomes the Point of Control.

The Point of Control represents the most concentrated participation zone inside the profile and is drawn as a dedicated horizontal reference line.

5) Midpoint Split and Side Totals
The active range midpoint is calculated as the average of the range high and range low. This midpoint is used as the divider between the lower half and upper half of the profile.

For summary purposes, buy side totals are accumulated from bins at or below the midpoint, while sell side totals are accumulated from bins above the midpoint. The script also records the highest buy side bin value and the highest sell side bin value.

This design gives the profile a simple structural interpretation:
lower range strength is associated with buying participation,
upper range strength is associated with selling participation.

That makes the summary especially useful for understanding whether the range is showing stronger support style accumulation below or stronger supply style pressure above.

6) Smoothing Engine
To reduce jaggedness, the script smooths each side of the profile with a local weighted kernel built from five neighboring bins. The center bin carries the highest influence, adjacent bins carry moderate influence, and outer bins carry smaller influence.

The smoothed result is then blended with the raw bin value according to the user selected smoothing factor. A low smoothing value preserves more of the original structure, while a high smoothing value creates a softer and more continuous curve.

This process helps reveal the true shape of participation without overreacting to isolated bin spikes.

7) Curve Projection and Shape Refinement
Once a side is smoothed, its value is normalized against the maximum strength of that side. The normalized result is converted into horizontal width inside the selected profile width. This is what determines how far the curve extends to the right from its anchor point.

The script also applies an additional running refinement to the horizontal curve position from one bin to the next. This makes the drawn path more fluid and helps eliminate abrupt lateral jumps between neighboring levels.

The final effect is a polished depth curve that communicates intensity clearly while remaining visually smooth.

8) Strong Pocket Detection
Strong liquidity pockets are found by scanning for consecutive bins where normalized smoothed participation exceeds the pocket threshold.

For the upper half of the profile, the script searches for strong sell side runs.
For the lower half of the profile, the script searches for strong buy side runs.

When a qualifying run lasts for at least the minimum required number of bins, a zone is drawn across that price region and labeled accordingly. The horizontal size of the zone is linked to the peak strength found inside that run.

This means the pocket logic is not simply marking a single peak. It is identifying sustained participation clusters, which often carry more analytical value than isolated extremes.

9) Visual Frame and Range Guides
The script adds a top guide at the range high, a bottom guide at the range low, and a midpoint guide through the center of the profile. These references help the user interpret the shape of liquidity in relation to the broader active range.

A curve concentrated near the midpoint suggests balance or repeated acceptance.
A strong bulge in the upper section can imply stronger supply style participation.
A strong bulge in the lower section can imply stronger demand style participation.

10) Summary Metrics
The summary label presents estimated buy side and sell side percentages along with total side volumes. These percentages are derived from the midpoint based side totals described above.

This gives the user a fast read on the internal balance of the profile without needing to inspect the full shape manually. It is especially useful when comparing one instrument or one session structure to another.

免責事項

これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。