top of page

Pine Script Library

Public·1 member

Cumulative Volume Delta (CVD) — Volume Drop


# Cumulative Volume Delta (CVD) — Volume Drop


Volume tells you *how much* changed hands, but Cumulative Volume Delta tells you *who was leaning on the tape*. This drop builds a session-anchored running total of approximated buying minus selling pressure so you can see when a move is backed by real participation — and when it isn't.


## What it does

- Splits each bar's volume into "buy" and "sell" shares using close-location within the high/low range

- Accumulates the net delta into a running total that resets at the start of every day, week, or month (your choice)

- Plots an EMA signal line over the CVD so you can read momentum at a glance

- Colors the histogram green above zero, red below — and drops flip arrows when CVD crosses the zero line

- Built-in `alertcondition` hooks for zero crosses and signal-line crosses, ready to wire into TradingView alerts


## Recommended settings

- Reset period: **D** (intraday) or **W** (swing)

- Signal EMA length: **20**

- Show zero line: **on**

- Show flip arrows: **on**


## Ideal timeframe

1-minute through 1-hour intraday, or daily for swing context. Avoid sub-minute charts on thin tickers — the buy/sell split gets noisy when range collapses.


## How to use

Trade in the direction of CVD vs. its signal line and respect the zero line as a regime gate — bullish flow above zero, bearish below. The highest-quality setups happen when price makes a higher high (or lower low) but CVD does not — that's a participation divergence and tends to mark exhaustion. Use it confluently with your structure framework; treat zero-cross arrows as a heads-up, not a standalone entry trigger.


## Pine Script v5 code

```

//@version=5

// ─────────────────────────────────────────────

// │ MarketFragments.com | DNA & Market │

// │ info@marketfragments.com │

// │ www.marketfragments.com │

// ─────────────────────────────────────────────

// Time →

// │

// █ █ █│ █

// █ █ █ │ █ █

// █ █ █ │ █ █ █ ╭─╮

// █ █ █ │ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ ╰─────╯

// ──────┴──────────────────────────────────────────────────────────────

// T1 T2 T3 T4 T5 T6

//

// Cumulative Volume Delta (CVD) — MarketFragments free drop

// Approximates per-bar buy vs sell pressure from bar-close location

// within the range, then accumulates the net delta into a session-anchored

// running total with an EMA signal line, zero-line, flip arrows, and alerts.

// Free for non-commercial use. Attribution appreciated.


indicator("MF Cumulative Volume Delta", shorttitle="MF CVD", overlay=false)


resetPeriod = input.string("D", "Reset Period", options=["D", "W", "M", "NONE"])

signalLength = input.int(20, "Signal EMA Length", minval=1)

showZeroLine = input.bool(true, "Show Zero Line")

showFlipArrows = input.bool(true, "Show Flip Arrows on Zero Cross")


// Proportional buy/sell split based on close location within the bar range

rng = high - low

buyShare = rng > 0 ? (close - low) / rng : 0.5

sellShare = rng > 0 ? (high - close) / rng : 0.5

buyVol = volume * buyShare

sellVol = volume * sellShare

delta = buyVol - sellVol


// Session / period reset

isReset = resetPeriod == "NONE" ? false : ta.change(time(resetPeriod)) != 0


// Anchored cumulative delta

var float cvd = 0.0

cvd := isReset ? delta : nz(cvd[1]) + delta


// CVD histogram, colored by sign

cvdColor = cvd >= 0 ? color.new(color.green, 25) : color.new(color.red, 25)

plot(cvd, "CVD", color=cvdColor, style=plot.style_columns)


// Signal line (EMA of CVD)

signal = ta.ema(cvd, signalLength)

plot(signal, "Signal", color=color.new(color.yellow, 0), linewidth=2)


// Zero line

plot(showZeroLine ? 0 : na, "Zero", color=color.new(color.gray, 30))


// Flip arrows on zero crosses

bullFlip = ta.crossover(cvd, 0)

bearFlip = ta.crossunder(cvd, 0)

plotshape(showFlipArrows and bullFlip, "Bull Flip", style=shape.triangleup, location=location.bottom, color=color.new(color.green, 0), size=size.tiny)

plotshape(showFlipArrows and bearFlip, "Bear Flip", style=shape.triangledown, location=location.top, color=color.new(color.red, 0), size=size.tiny)


// Alerts

alertcondition(bullFlip, "CVD Cross Above Zero", "MF CVD crossed ABOVE zero")

alertcondition(bearFlip, "CVD Cross Below Zero", "MF CVD crossed BELOW zero")

alertcondition(ta.crossover(cvd, signal), "CVD Cross Above Signal", "MF CVD crossed ABOVE signal")

alertcondition(ta.crossunder(cvd, signal), "CVD Cross Below Signal", "MF CVD crossed BELOW signal")

```


Drop your tweaks, screenshots, and questions below — that's how the library gets better.


1 View
Brain with financial data analysis.

Inquiries at :

Important Risk Notice: Trading involves substantial risk of loss. This is educational content only—not advice. Full details here  ------------>  

Proceed only if you're prepared.

tel#: (843) 321-8514

bottom of page