OPEN-SOURCE SCRIPT

Cumulative Volume Delta with Divergence

1 052
🧠 Core Functionality:
1. Cumulative Volume Delta (CVD):
Purpose: Visualizes the difference between buying and selling pressure over time.

Mechanism:

It uses lower-timeframe volume delta data, retrieved from ta.requestVolumeDelta(), to build a candle-style visualization of the net volume movement.

Plotted candles show whether buying (up volume) or selling (down volume) was dominant within each period.

Teal candles: More buying than selling (CVD up).

Red candles: More selling than buying (CVD down).

Volume Source: Based on intrabar up/down volume approximation from lower timeframes.

🧭 Divergence Detection (New Feature):
2. Regular Bullish Divergence:
Condition:

Price makes a lower low.

CVD (lastVolume) makes a higher low.

Interpretation: Selling pressure is weakening despite price making new lows — a potential reversal signal to the upside.

Displayed As:

Green line and label "Bull" under the CVD at the divergence point.

3. Regular Bearish Divergence:
Condition:

Price makes a higher high.

CVD makes a lower high.

Interpretation: Buying pressure is fading despite price rising — a potential reversal signal to the downside.

Displayed As:

Red line and label "Bear" above the CVD at the divergence point.

🧰 User Controls:
Use custom timeframe: Overrides default volume delta resolution for finer or broader analysis.

Calculate Divergence: Turns the divergence detection on or off.

Adjustable via script inputs.

🔔 Alerts:
Two alert conditions are included:

One for bullish divergence.

One for bearish divergence.

Alerts trigger at the bar where the divergence is confirmed, not where it starts.

📈 Use Case:
This tool is ideal for traders looking to:

Spot early reversals or momentum shifts.

Combine volume analysis with price action.

Time entries or exits more accurately using volume-confirmed divergence.

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.