OPEN-SOURCE SCRIPT

Cumulative Delta Divergence Suite

1 334
## Cumulative Delta Divergence Suite

The underlying cumulative-delta calculation and CDV candle construction are adapted from “Cumulative Delta Volume” by LonesomeTheBlue, licensed under MPL 2.0. This version adds independently developed divergence detection, multi-factor scoring, higher-timeframe analysis, absorption and exhaustion conditions, alerts, timeframe presets, and historical target/stop outcome analysis.

### Overview

Cumulative Delta Divergence Suite is a multi-module volume-pressure analysis indicator built around a cumulative delta oscillator.

The script compares confirmed price pivots with confirmed cumulative-delta pivots and combines divergence analysis with configurable scoring, higher-timeframe context, absorption conditions, Z-score extreme zones, timeframe presets, alerts, and simplified historical target/stop outcome tables.

The purpose of combining these components is to examine disagreement between price structure and directional volume pressure from several related perspectives. The modules are not simply displayed independently. Divergence magnitude, delta momentum, relative volume, trend alignment, higher-timeframe agreement, and pivot spacing can contribute to a shared scoring and classification process.

The displayed conditions are analytical observations. They do not predict that price will reverse, continue, or reach a particular level.

### Cumulative delta calculation

Standard chart volume does not directly separate executed buying volume from executed selling volume.

The cumulative-delta calculation used by this script derives directional volume from each candle's:

* total volume;
* body size;
* upper wick;
* lower wick;
* closing direction.

The resulting directional volume value is accumulated over time to construct the cumulative delta series.

The oscillator is displayed as candles in a separate pane. Users can display either the raw cumulative delta candles or an internally calculated Heikin-Ashi representation.

The Heikin-Ashi option smooths the oscillator structure, but this additional averaging can delay changes and alter the location of oscillator pivots.

The calculation is derived from chart OHLCV data. It does not use exchange bid/ask transaction classifications, footprint data, or order-book data.

### Divergence framework

The script compares confirmed pivots in price with confirmed pivots in the cumulative delta oscillator.

It identifies four divergence structures:

* Regular bullish divergence occurs when price forms a lower low while cumulative delta forms a higher low.
* Regular bearish divergence occurs when price forms a higher high while cumulative delta forms a lower high.
* Hidden bullish divergence occurs when price forms a higher low while cumulative delta forms a lower low.
* Hidden bearish divergence occurs when price forms a lower high while cumulative delta forms a higher high.

Regular divergence highlights disagreement between a new price extreme and the cumulative-delta structure.

Hidden divergence highlights a different form of structural disagreement that traders commonly examine within an existing trend.

Neither type establishes what price will do afterward.

### How the modules work together

The script is designed as a cumulative-delta analysis workflow rather than a collection of unrelated indicators.

Divergence provides the primary structural condition by comparing price pivots with cumulative-delta pivots.

The scoring system then evaluates additional characteristics surrounding that divergence, including divergence magnitude, recent delta-momentum change, relative volume, trend alignment, higher-timeframe agreement, and the distance between the compared pivots.

Absorption conditions examine bars where comparatively strong directional volume occurs with limited price progress under the selected volume, range, body, and confluence filters.

Z-score zones identify cumulative-delta readings that are unusually high or low relative to their recent distribution.

Higher-timeframe analysis provides broader confirmed divergence, trend, and volume context.

These components therefore perform different roles within the same analysis process rather than simply duplicating one another.

### How to use the indicator

Apply the indicator to a symbol that provides usable volume data.

The cumulative delta candles appear in a separate pane below the price chart.

A practical workflow is:

1. Review the broader price trend and market structure.
2. Observe whether cumulative delta generally confirms or disagrees with price.
3. Wait for a confirmed regular or hidden divergence condition.
4. Inspect the optional price and oscillator divergence lines to see which pivots were compared.
5. Review the divergence strength score and A+, B, or C category.
6. Check whether confirmed higher-timeframe context agrees with the current structure.
7. Review nearby absorption conditions and Z-score extreme zones.
8. Examine support, resistance, volatility, liquidity, and candle structure separately.
9. Treat all markers as analytical conditions rather than automatic trade instructions.
10. Test settings, alerts, and historical outcome assumptions on the intended symbol and timeframe.

### Regular bullish divergence

Regular bullish divergence is confirmed when:

* price forms a lower confirmed low;
* cumulative delta forms a higher confirmed low.

Price has therefore reached a new lower pivot while the cumulative-delta oscillator has not produced a corresponding lower pivot.

Traders may examine this disagreement together with market structure, support, momentum, cumulative-delta behaviour after confirmation, Z-score context, absorption conditions, and higher-timeframe structure.

The condition can fail, and price can continue lower after confirmation.

### Regular bearish divergence

Regular bearish divergence is confirmed when:

* price forms a higher confirmed high;
* cumulative delta forms a lower confirmed high.

Price has therefore reached a new higher pivot while the cumulative-delta oscillator has not produced a corresponding higher pivot.

Traders may examine this disagreement together with market structure, resistance, momentum, cumulative-delta behaviour after confirmation, Z-score context, absorption conditions, and higher-timeframe structure.

The condition can fail, and price can continue higher after confirmation.

### Hidden bullish divergence

Hidden bullish divergence is confirmed when:

* price forms a higher confirmed low;
* cumulative delta forms a lower confirmed low.

This structure is commonly examined within an existing upward trend because price retains a higher low while cumulative delta makes a deeper retracement.

It does not guarantee that the upward trend will continue.

### Hidden bearish divergence

Hidden bearish divergence is confirmed when:

* price forms a lower confirmed high;
* cumulative delta forms a higher confirmed high.

This structure is commonly examined within an existing downward trend because price retains a lower high while cumulative delta makes a stronger retracement.

It does not guarantee that the downward trend will continue.

### Raw and Heikin-Ashi CDV candles

When Heikin-Ashi CDV candles are disabled, the script uses the raw cumulative delta candle values.

When they are enabled, the script applies an internal Heikin-Ashi transformation to the cumulative delta series.

This affects only the oscillator displayed by the indicator. It does not convert the main TradingView price chart to Heikin-Ashi candles.

The smoothed representation can make broader cumulative-delta structure easier to inspect, but it may also delay short-term changes and alter oscillator pivot locations.

### Pivot settings and confirmation delay

Pivot Left controls how many earlier bars participate in identifying a pivot.

Pivot Right controls how many later bars must pass before that pivot becomes confirmed.

Higher pivot values generally produce fewer pivots, filter more short-term movement, and confirm conditions later.

Lower pivot values generally produce more pivots and react more quickly, but they are also more sensitive to short-term movement.

A pivot-based divergence is not known on the original pivot bar.

The script must wait for the configured number of Pivot Right bars before the pivot can be confirmed.

After confirmation, divergence markers and optional connecting lines are drawn at the original pivot location so users can visually inspect the price-versus-CDV structure.

For example, when Pivot Right is 5, five subsequent bars are required before the pivot is confirmed.

Consequently, a historical divergence marker appears on the earlier pivot bar even though the condition only became known several bars later.

Alerts for pivot-based divergences occur after confirmation, not on the earlier pivot bar.

### Divergence lines

The script can draw oscillator pivot-to-pivot lines in the indicator pane and corresponding price pivot-to-pivot lines on the main chart.

These lines show the exact pair of pivots used for the divergence comparison.

For example, regular bullish divergence connects two price lows where the newer price pivot is lower while the corresponding cumulative-delta pivot is higher.

The lines can be disabled when a cleaner chart is preferred.

### Divergence strength score

The optional divergence strength value measures the relative displacement between the compared price pivots and cumulative-delta pivots.

It is derived from the magnitude of the price movement and the magnitude of the oscillator movement between the compared pivots.

It is not a probability, win rate, or forecast.

The Minimum Divergence Strength setting can suppress conditions whose calculated magnitude is below the selected value.

### Composite scoring

Each confirmed divergence can receive a configurable composite score.

The score combines several measurements:

* divergence strength;
* recent change in smoothed delta momentum;
* volume relative to its recent average;
* alignment with the script's EMA-based trend state;
* agreement with confirmed higher-timeframe divergence context;
* distance between the compared pivots.

Each component performs a different function.

Divergence strength measures the magnitude of the structural disagreement.

Delta momentum examines recent directional change in the smoothed delta series.

Relative volume measures participation around the evaluated pivot.

Trend alignment provides directional price context.

Higher-timeframe agreement measures whether the selected confirmed HTF divergence context supports the same side.

Pivot spacing distinguishes closely grouped pivots from structures developing across a wider interval.

Users can adjust the contribution of these components through the scoring weights.

The active weights are normalized before the final composite value is calculated.

The score organizes conditions according to the selected model. It is not a prediction of future performance.

### Score categories

The script assigns A+, B, or C categories according to the configured score thresholds.

These categories are internal classifications.

They are not probabilities, win rates, accuracy measurements, guarantees, or independently validated performance rankings.

An A+ category means only that the condition reached the highest configured score range.

A B category means that the condition reached the middle configured range.

A C category represents conditions below the B threshold that remain eligible under the selected filter.

The Minimum Grade setting can suppress conditions below the selected category.

### Score transformation

The Score Boost Power applies a nonlinear transformation to the composite score before the A+, B, and C thresholds are evaluated.

Lower values compress scores upward and therefore allow higher categories to occur more frequently.

Higher values keep transformed scores closer to the underlying composite values and make the upper categories more selective.

This setting changes the script's internal classification behaviour. It does not increase the probability that a condition will succeed.

### Adaptive score scaling

When Adaptive Grade Scaling is enabled, the script compares the current raw composite score with the recent distribution of composite scores.

It uses a rolling mean and standard deviation to place the current value in the context of recently observed values before the category thresholds are applied.

When adaptive scaling is disabled, category thresholds are applied to the unscaled composite score.

Because adaptive scaling is relative to recent observations, the same general type of structure can receive different categories under different market conditions.

### Higher-timeframe context

The script can evaluate divergence context from a user-selected higher timeframe.

The HTF module calculates its pivot structure, trend context, and relative-volume component using confirmed data from the requested higher timeframe.

The script uses the last fully closed higher-timeframe information rather than relying on a still-forming HTF candle.

This means higher-timeframe information becomes available only after the required higher-timeframe data has been confirmed.

The HTF module identifies regular bullish, regular bearish, hidden bullish, and hidden bearish cumulative-delta divergence structures.

Its scoring process combines HTF divergence strength with HTF trend context and HTF volume participation.

Higher-timeframe conditions can be displayed separately and can also contribute to the chart-timeframe composite score.

An independent HTF Minimum Grade setting determines which higher-timeframe categories are displayed.

Because confirmed HTF data is used, higher-timeframe conditions can appear later than chart-timeframe conditions.

Higher-timeframe context should therefore be interpreted as broader confirmed information rather than an earlier signal.

### Absorption conditions

The absorption module searches for bars where comparatively large directional delta occurs while price progress remains constrained under the selected filters.

The module evaluates:

* directional delta relative to its recent average;
* volume relative to its recent average;
* candle range relative to its average;
* candle body as a proportion of the complete range;
* an optional close opposing the delta direction;
* optional proximity to a recently graded divergence.

A bullish absorption condition is associated with comparatively strong negative delta while downward price progress remains limited under the configured filters.

A bearish absorption condition is associated with comparatively strong positive delta while upward price progress remains limited under the configured filters.

The module is derived from chart OHLCV information. It does not prove that passive limit orders absorbed aggressive market orders.

The markers should therefore be interpreted as absorption-style analytical conditions rather than direct measurements of order-book behaviour.

### Absorption confluence and filtering

Absorption conditions can be filtered using recent divergence proximity, minimum divergence category, cooldown bars, volume thresholds, delta thresholds, range thresholds, body-to-range limits, and optional opposite-close confirmation.

When divergence confluence is enabled, the absorption condition must occur within the configured number of bars following a qualifying divergence.

The absorption grade displayed with a condition is derived from the nearby qualifying divergence category.

These filters change which conditions are displayed. They do not guarantee a particular subsequent price outcome.

### Z-score extreme zones

The script calculates a Z-score from the cumulative-delta oscillator's rolling mean and standard deviation.

A lower extreme zone appears when the oscillator moves below the selected negative Z-score threshold.

An upper extreme zone appears when the oscillator moves above the selected positive threshold.

These zones identify values that are unusually high or low relative to the oscillator's recent statistical distribution.

The Z-Score Length determines how much history contributes to the rolling mean and standard deviation.

The Z-Score Threshold determines how many standard deviations the oscillator must move from its rolling mean before an extreme zone is displayed.

Higher thresholds produce fewer extreme zones. Lower thresholds produce more frequent zones.

An extreme value does not establish that buying or selling pressure is exhausted and does not establish that price will reverse.

Extreme readings can persist or become more extreme.

### Using divergence, absorption, and Z-score context together

The modules provide different forms of information.

Divergence compares price pivot structure with cumulative-delta pivot structure.

Absorption examines strong directional delta occurring with constrained price progress.

Z-score analysis measures whether cumulative delta is unusually high or low relative to recent values.

Higher-timeframe analysis provides broader confirmed structural context.

Composite scoring organizes divergence conditions according to multiple characteristics of the setup.

The purpose of combining these modules is to provide several related perspectives on price-versus-volume-pressure disagreement without treating any one module as a complete trading system.

Confluence between modules provides additional analytical context but does not automatically validate a condition or guarantee reversal or continuation.

### Timeframe presets

The script contains lower-, medium-, and higher-timeframe preset bundles.

The presets adjust selected settings including:

* pivot lengths;
* score transformation power;
* adaptive score scaling;
* Heikin-Ashi CDV display;
* absorption averaging lengths;
* absorption thresholds;
* absorption confluence lookback.

The presets are intended as starting configurations.

They are not automatically optimized for the active symbol and have not been fitted to guarantee particular historical results.

Users can disable Apply Timeframe Preset to configure the corresponding settings manually.

### Cooldown settings

Independent cooldown controls can reduce repeated conditions of the same type.

Separate cooldown settings are available for regular divergences, hidden divergences, higher-timeframe divergences, absorption conditions, and Z-score extreme conditions.

A value of zero disables the relevant cooldown.

Higher cooldown values reduce repeated same-direction markers but can also suppress nearby structures that would otherwise qualify.

### Historical target/stop outcome tables

Optional tables provide a simplified historical outcome study for confirmed divergence and absorption conditions.

When a condition is confirmed, the script records the confirmation-bar closing price and calculates a fixed percentage target and fixed percentage stop level.

The target and stop percentages are user configurable.

Outcome evaluation begins on the bar after the condition is confirmed.

This prevents price movement that occurred earlier within the confirmation bar from being counted as a subsequent target or stop event.

Each confirmed condition is tracked independently.

If another qualifying condition appears before an earlier condition has resolved, the newer condition does not replace the earlier unresolved condition in the historical study.

For each tracked condition, the script records whether the target or stop is reached first.

If both the target and stop are touched during the same evaluation candle, standard OHLC chart data does not reveal which level was reached first. In this situation the script uses a conservative convention and counts the stop as occurring first.

Separate tables are available for:

* regular bullish divergence;
* regular bearish divergence;
* hidden bullish divergence;
* hidden bearish divergence;
* bullish absorption;
* bearish absorption.

The tables display the number of target-first outcomes, stop-first outcomes, and the resulting target-first percentage for the available chart history.

These tables are intended as a basic chart-based comparison tool.

They are not TradingView Strategy Tester results and are not a complete strategy backtest.

They do not model commissions, slippage, bid/ask spread, realistic order execution, position sizing, portfolio equity, liquidity, partial fills, or complete intrabar price sequencing.

Historical results depend on the symbol, timeframe, available chart history, target and stop distances, filters, indicator settings, and available volume data.

The table percentages describe only the simplified historical study produced under those settings. They do not imply future performance.

### Evaluation target and stop lines

The script can display the fixed target and stop levels associated with the most recently confirmed qualifying condition.

The Target and Stop labels remain anchored at the left side of their respective lines. While the outcome is unresolved, the lines extend to the right. Once either the target or stop is reached, the lines end at the resolution bar and remain visible until a newer qualifying condition replaces them.

These levels use the same configurable percentage distances as the historical outcome study and are provided for visual evaluation rather than as trading recommendations.

Only the most recent Target/Stop pair is displayed to limit chart clutter, while historical conditions continue to be tracked independently by the outcome tables.

### Alerts

Alerts are available for configured divergence, absorption, and exhaustion conditions.

Pivot-based regular and hidden divergence alerts occur only after the required Pivot Right bars have confirmed the pivot.

A+ divergence alerts require the underlying divergence to qualify for the A+ category.

Absorption conditions can depend on values from the current chart bar and can therefore change while that bar is still forming.

Z-score extreme conditions can likewise change as the current chart bar develops.

Users who require closed-bar confirmation should configure their TradingView alert frequency accordingly.

Higher-timeframe divergence context uses confirmed higher-timeframe information.

### What makes the implementation distinct

The script extends a cumulative-delta framework into a broader price-versus-volume-pressure analysis workflow.

Its distinguishing structure includes:

* cumulative delta candle visualization;
* optional internal Heikin-Ashi smoothing;
* regular and hidden pivot-based price/CDV divergence analysis;
* configurable divergence strength filtering;
* multi-factor divergence scoring;
* user-adjustable scoring weights;
* nonlinear score transformation;
* adaptive score scaling;
* A+, B, and C classification and filtering;
* confirmed higher-timeframe divergence analysis;
* higher-timeframe trend and volume context;
* absorption conditions that can be linked to recently graded divergences;
* Z-score extreme analysis;
* timeframe-based parameter presets;
* independent cooldown controls;
* independent tracking of historical target/stop outcomes;
* configurable target and stop evaluation levels;
* divergence, absorption, exhaustion, and grade-based alerts.

The purpose of this combination is to evaluate price-versus-cumulative-delta disagreement using several related measurements within a single workflow.

The divergence module identifies the structural event. The score measures characteristics of that structure and its surrounding context. Higher-timeframe analysis supplies broader confirmed context. Absorption examines directional volume occurring with limited price progress. Z-score analysis identifies statistically unusual oscillator readings. The historical tables provide a simplified way to inspect what happened after past qualifying conditions.

This integration is the reason the components are combined rather than published merely as separate common indicators placed together.

### Limitations

Cumulative delta in this script is derived from candle structure and chart volume rather than exchange bid/ask transaction classifications.

Volume quality and interpretation vary between exchanges, brokers, instruments, and symbols.

Pivot-based divergences are delayed by the selected Pivot Right value.

Confirmed pivot markers and divergence lines are drawn on the earlier pivot location after confirmation, so historical marker placement is earlier than the time at which the condition became known.

Heikin-Ashi smoothing changes the cumulative-delta oscillator structure and can introduce additional delay.

Higher-timeframe analysis waits for confirmed HTF information, which can delay HTF conditions.

Divergence conditions can fail and price can continue in the same direction after a divergence has been confirmed.

Hidden divergence does not guarantee trend continuation.

Absorption conditions are OHLCV-based analytical approximations and do not directly identify passive order-book absorption.

Z-score extremes can persist or become more extreme.

Composite scores and A+, B, and C categories are model outputs, not probabilities, win rates, accuracy measurements, or independently validated performance rankings.

Adaptive scaling can change classifications as the recent score distribution changes.

Lower timeframes can produce more frequent and noisier conditions.

Timeframe presets are starting configurations and are not automatically optimized for a symbol.

Historical target/stop tables are simplified outcome studies and do not represent complete strategy backtests.

Historical target-first percentages depend heavily on the selected target/stop distances, indicator settings, symbol, timeframe, available history, and market conditions.

The indicator does not model commissions, slippage, spread, liquidity, or realistic execution.

No divergence, score category, absorption condition, Z-score reading, target/stop outcome, or combination of these elements guarantees future market behaviour.

The indicator should not be used as the sole basis for a trading decision.

This script is an analytical tool and does not provide financial advice or guaranteed trading outcomes.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน