top of page

Thinkscript 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 alerts for zero crosses and signal-line crosses, ready to wire into thinkorswim notifications


## Recommended settings

- Reset period: **DAY** (intraday) or **WEEK** (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.


## thinkScript code

```

# ─────────────────────────────────────────────

# │ 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.


declare lower;


input resetPeriod = {default "DAY", "WEEK", "MONTH", "NONE"};

input signalLength = 20;

input showZeroLine = yes;

input showFlipArrows = yes;


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

def rng = high - low;

def buyShare = if rng > 0 then (close - low) / rng else 0.5;

def sellShare = if rng > 0 then (high - close) / rng else 0.5;

def buyVol = volume * buyShare;

def sellVol = volume * sellShare;

def delta = buyVol - sellVol;


# Session / period reset

def newPeriod;

switch (resetPeriod) {

case "DAY":

newPeriod = GetDay() != GetDay()[1];

case "WEEK":

newPeriod = GetWeek() != GetWeek()[1];

case "MONTH":

newPeriod = GetMonth() != GetMonth()[1];

default:

newPeriod = no;

}


# Anchored cumulative delta

def cvd = if !IsNaN(cvd[1]) and !newPeriod then cvd[1] + delta else delta;


# CVD histogram, colored by sign

plot CVD = cvd;

CVD.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

CVD.SetLineWeight(3);

CVD.AssignValueColor(if cvd >= 0 then Color.GREEN else Color.RED);


# Signal line (EMA of CVD)

plot Signal = ExpAverage(cvd, signalLength);

Signal.SetDefaultColor(Color.YELLOW);

Signal.SetLineWeight(2);


# Zero line

plot Zero = if showZeroLine then 0 else Double.NaN;

Zero.SetDefaultColor(Color.GRAY);

Zero.SetStyle(Curve.SHORT_DASH);


# Flip arrows on zero crosses

plot BullFlip = if showFlipArrows and cvd crosses above 0 then 0 else Double.NaN;

BullFlip.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

BullFlip.SetDefaultColor(Color.GREEN);

BullFlip.SetLineWeight(3);


plot BearFlip = if showFlipArrows and cvd crosses below 0 then 0 else Double.NaN;

BearFlip.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

BearFlip.SetDefaultColor(Color.RED);

BearFlip.SetLineWeight(3);


# Alerts

Alert(cvd crosses above 0, "MF CVD crossed ABOVE zero", Alert.BAR, Sound.Bell);

Alert(cvd crosses below 0, "MF CVD crossed BELOW zero", Alert.BAR, Sound.Bell);

Alert(cvd crosses above Signal, "MF CVD crossed ABOVE signal", Alert.BAR, Sound.Chimes);

Alert(cvd crosses below Signal, "MF CVD crossed BELOW signal", Alert.BAR, Sound.Chimes);

```


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


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