Indicator · Pine Script v5 · Own pane

Detrended CVD Z-Score Oscillator

by tthanhvu002sgu· code credited to Quantified Detrended CVD (Z-Score)

A separate-pane indicator that estimates delta from each candle by adding volume on up candles and subtracting it on down candles, accumulates it into a cumulative value, and converts that to a Z-score over a rolling window.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code51
Settings2inputs
LicenceNone statedfile: MPL-2.0
Last update3 months ago14 Jul 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

51 lines of Pine Script v5 from indicator/cvd.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

cvd.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
// © Quantified Detrended CVD (Z-Score)

//@version=5
indicator("Detrended CVD (Z-Score Oscillator)", format=format.price, precision=2)

// 📊 1. THÔNG SỐ ĐẦU VÀO
grp_calc = "=== CẤU HÌNH Z-SCORE ==="
length = input.int(100, "Chu kỳ chuẩn hóa (Window Size)", minval=10, group=grp_calc, tooltip="Độ dài 'trí nhớ' của chỉ báo. Càng lớn, dữ liệu vĩ mô càng được giữ lại.")
limit_std = input.float(2.0, "Ngưỡng Cảnh báo (Standard Deviation)", group=grp_calc)

// 🧮 2. TÍNH TOÁN DELTA VÀ CVD THÔ (RAW CVD)
// Lưu ý: Đây là thuật toán nội suy Delta cơ bản từ OHLC và Volume. 
// Trên thị trường Futures/Crypto chuẩn, bạn nên dùng dữ liệu Up/Down Volume thực tế của sàn.
float tick_delta = 0.0
if close > open
    tick_delta := volume
else if close < open
    tick_delta := -volume
else
    tick_delta := 0

// Tính Cumulative Delta vô hạn
var float raw_cvd = 0.0
raw_cvd += tick_delta

// 🚀 3. CHUẨN HÓA Z-SCORE (NORMALIZATION & DETRENDING)
// Tính giá trị Trung bình (Mean) và Độ lệch chuẩn (StDev) của CVD trong N nến
mean_cvd = ta.sma(raw_cvd, length)
std_cvd = ta.stdev(raw_cvd, length)

// Công thức Z-Score: (Giá trị hiện tại - Giá trị trung bình) / Độ lệch chuẩn
// Giới hạn lỗi chia cho 0 khi thị trường đóng băng
float z_cvd = std_cvd != 0 ? (raw_cvd - mean_cvd) / std_cvd : 0.0

// 🖌️ 4. TRỰC QUAN HÓA (VISUALIZATION)
// Đổi màu Histogram dựa trên trạng thái Động lượng của CVD
color hist_color = z_cvd > limit_std ? color.new(color.lime, 0) : 
                   z_cvd < -limit_std ? color.new(color.red, 0) : 
                   z_cvd > 0 ? color.new(color.teal, 40) : color.new(color.maroon, 40)

plot(z_cvd, title="Z-Score CVD", style=plot.style_histogram, color=hist_color, linewidth=2)

// Vẽ các đường biên giới hạn (Bands)
hline(0, "Baseline", color=color.gray, linestyle=hline.style_dotted)
hline(limit_std, "Upper Band (+2 Std)", color=color.red, linestyle=hline.style_dashed)
hline(-limit_std, "Lower Band (-2 Std)", color=color.lime, linestyle=hline.style_dashed)

// Vẽ đường tín hiệu làm mượt (Signal Line)
signal_line = ta.ema(z_cvd, 9)
plot(signal_line, title="Signal Line", color=color.orange, linewidth=1)

Overview

A histogram is coloured by whether the score is beyond the standard deviation limit, with dotted bands and a 9-period EMA signal line. Window and limit are inputs. Delta is estimated from candles, not real order flow.

Details

Published by

tthanhvu002sgu on GitHub

Code credit

Quantified Detrended CVD (Z-Score), as written in the script's header

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Chu kỳ chuẩn hóa (Window Size)int100length
Ngưỡng Cảnh báo (Standard Deviation)float2.0limit_std
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Money Flow Index

by everget
947 stars

Calculates the standard Money Flow Index (MFI) oscillator alongside an exponential moving average signal line in a separate pane. The script visually highlights trend conditions through dynamic ribbon filling, optional difference histogram bars, and overbought

Indicator v4 Oscillators & momentumVolume
Updated 12 days ago · GPL-3.0 GitHub repository of Money Flow Index

Commitment Gauge

by harryguiacorn
220 stars

This indicator measures directional momentum by evaluating candlestick body proportions and volume over a user-defined lookback window. It computes the ratio of candle body to total range, weights the cumulative value by volume and absolute body size, and dete

Indicator v4 VolumeCandlestick patterns
Updated 1 year ago · None stated GitHub repository of Commitment Gauge

Aggregate Signal

by capissimo
114 stars

This indicator builds an aggregate oscillator in a separate pane. It scales open, high, low, close, and volume into a 0 to 1 range, then averages scaled readings from MACD, a MACD histogram, RSI, stochastic, CCI, momentum, OBV, a directional index, volume-weig

Indicator v4 Oscillators & momentumVolume Repaints
Updated 1 year ago · None stated GitHub repository of Aggregate Signal

This indicator calculates the Bill Williams Market Facilitation Index as the high-low range divided by volume, or zero when volume is zero. It compares the index and volume with the previous bar and assigns one of four zones: green for both rising, fade for bo

Indicator v6 VolumeOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Bill Williams Market Facilitation Index

PPO ATR Bands

by cryptorife
75 stars

PPO ATR Bands plots a percentage price oscillator in a separate pane. It compares a Hull average of typical price with a volume-weighted exponential average of Parabolic SAR, then scales three true-range bands around the slow average into matching oscillator l

Indicator v4 Oscillators & momentumMoving averages
Updated 3 years ago · GPL-3.0 GitHub repository of PPO ATR Bands

Chaikin Oscillator

by be-thomas
65 stars

Calculates the Chaikin Oscillator by taking the difference between a fast exponential moving average and a slow exponential moving average of the Accumulation/Distribution line. It plots the resulting line in a separate pane alongside a dashed zero reference l

Indicator v4 Oscillators & momentumVolume
Updated 6 days ago · GPL-3.0 GitHub repository of Chaikin Oscillator

More Volume scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers