OPEN-SOURCE SCRIPT
CTZ Accumulation/Distribution

**CTZ Accumulation/Distribution**
A volume-based indicator that tracks whether money is flowing into or out of an asset by measuring where price closes within each bar's range, weighted by volume.
**How it works**
Each bar, a Money Flow Multiplier is calculated from the close's position between the high and low (–1 to +1). This is multiplied by volume to produce Money Flow Volume, which is added to a running cumulative total — the A/D line. Closes near the high on heavy volume push the line up (accumulation); closes near the low on heavy volume push it down (distribution).
**Features**
- **A/D Line with trend colouring** — teal when above the signal EMA, red when below, giving an at-a-glance read on money flow direction
- **Signal EMA (default 21)** — smooths the A/D line and acts as a trend filter; crosses can be used as early momentum shifts
- **Automatic divergence detection** — pivot-based logic flags bullish divergence (price makes a lower low while A/D makes a higher low = hidden accumulation) and bearish divergence (price makes a higher high while A/D makes a lower high = distribution into strength)
- **Built-in alerts** — divergence signals and signal-line crosses in both directions
**How to use it**
Confirmation: when price and the A/D line rise together, the uptrend is supported by real buying pressure. When they fall together, the downtrend is genuine.
Divergence: when price and the A/D line disagree, treat it as an early warning. Bull labels suggest smart money is accumulating into weakness; Bear labels suggest distribution into rising prices. These work best on higher timeframes and near key levels — not as standalone entries.
**Settings**
Signal EMA length, pivot lookback (sensitivity of divergence detection), and max bars between pivots (how far apart two pivots can be and still count as a divergence) are all adjustable.
**Limitations**
The A/D line ignores gaps between bars — an asset gapping up overnight registers nothing if it then closes mid-range. Pivot-confirmed divergence labels print a few bars after the pivot by design. Best used alongside momentum tools (RSI, MFI) rather than in isolation.
A volume-based indicator that tracks whether money is flowing into or out of an asset by measuring where price closes within each bar's range, weighted by volume.
**How it works**
Each bar, a Money Flow Multiplier is calculated from the close's position between the high and low (–1 to +1). This is multiplied by volume to produce Money Flow Volume, which is added to a running cumulative total — the A/D line. Closes near the high on heavy volume push the line up (accumulation); closes near the low on heavy volume push it down (distribution).
**Features**
- **A/D Line with trend colouring** — teal when above the signal EMA, red when below, giving an at-a-glance read on money flow direction
- **Signal EMA (default 21)** — smooths the A/D line and acts as a trend filter; crosses can be used as early momentum shifts
- **Automatic divergence detection** — pivot-based logic flags bullish divergence (price makes a lower low while A/D makes a higher low = hidden accumulation) and bearish divergence (price makes a higher high while A/D makes a lower high = distribution into strength)
- **Built-in alerts** — divergence signals and signal-line crosses in both directions
**How to use it**
Confirmation: when price and the A/D line rise together, the uptrend is supported by real buying pressure. When they fall together, the downtrend is genuine.
Divergence: when price and the A/D line disagree, treat it as an early warning. Bull labels suggest smart money is accumulating into weakness; Bear labels suggest distribution into rising prices. These work best on higher timeframes and near key levels — not as standalone entries.
**Settings**
Signal EMA length, pivot lookback (sensitivity of divergence detection), and max bars between pivots (how far apart two pivots can be and still count as a divergence) are all adjustable.
**Limitations**
The A/D line ignores gaps between bars — an asset gapping up overnight registers nothing if it then closes mid-range. Pivot-confirmed divergence labels print a few bars after the pivot by design. Best used alongside momentum tools (RSI, MFI) rather than in isolation.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.