OPEN-SOURCE SCRIPT
Accumulation / Distribution Density (VD)

A volume indicator for TradingView (Pine Script v6), modeled after Mieczyslaw Siudek's "Accumulation / Distribution Density" (VD) from xStation (XTB). It hunts for candles where a disproportionately large volume produced a disproportionately small price move at a fresh local extreme - a classic footprint of a big player building (accumulation) or unloading (distribution) a position.
█ 🧠 THE IDEA: DENSITY
Density = volume / candle range (high - low) - "how much turnover per unit of movement".
Pine Script®
When such a candle also sets a new local low, buyers were absorbing the sell-off → accumulation (marker below the candle). At a new local high, sellers were absorbing the buying → distribution (marker above the candle).
Pine Script®
█ ⚙️ SIGNAL CONDITIONS
A marker appears on a candle only when all of these hold:
Both averages (range and density) use a window ending at the previous candle - the signal candle does not inflate its own threshold.
By default the conditions are checked only once the candle closes (Signal on closed candle only) - a marker never appears and then disappears on the live candle.
█ 🛠️ PARAMETERS
Parameters (as in xStation)
Appearance (Style tab)
Markers are plotshapes, so each signal gets its own row in the Style tab of the indicator settings - with a visibility checkbox, a marker-shape picker, a position dropdown (Above bar / Below bar), and a color:
█ 🔔 ALERTS
With Signal on closed candle only on (default) alerts fire at the candle close. If you turn that option off, set the alert trigger to Once Per Bar Close - otherwise an alert can fire on a live-candle signal that later vanishes.
█ 📤 SIGNAL OUTPUT
The script exposes a hidden Signal series: +1 (accumulation), -1 (distribution), 0 (none). It is visible in the Data Window and can be used as an external source in other indicators and strategies (any input.source field) - e.g. to build your own strategy on top of these signals.
█ ✅ CORRECTNESS - VERIFIED
The implementation was verified empirically (2026-08-18): signals recomputed independently (Node.js, same formulas) from OHLCV bars pulled off a live TradingView chart (COMEX:GC1!, 60m, 300 bars) and compared with the markers the Pine script actually drew:
The script does exactly what this note describes.
█ ⚠️ WHY MARKERS DIFFER FROM XSTATION
Even with identical parameter values, markers will not land 1:1 on xStation's. This is expected, not a bug:
Practical takeaway: compare the two on the same market data type (e.g. gold futures on both), expect agreement in character (markers cluster in the same spots), not in identical candles.
█ ⛔ LIMITATIONS
© Piotr Kowalski "piecioshka". License: Mozilla Public License 2.0.
█ 🧠 THE IDEA: DENSITY
Density = volume / candle range (high - low) - "how much turnover per unit of movement".
- 🚚 A lot of volume + a small candle = high density. Someone big is absorbing everything the market throws at them, so price cannot move.
- 🪶 A lot of volume + a big candle = normal. The volume simply traveled with the price.
When such a candle also sets a new local low, buyers were absorbing the sell-off → accumulation (marker below the candle). At a new local high, sellers were absorbing the buying → distribution (marker above the candle).
█ ⚙️ SIGNAL CONDITIONS
A marker appears on a candle only when all of these hold:
- 📉 New extreme - the candle's low is at or below the lowest low of the previous Max/Min of candles (accumulation), or its high is at or above the highest high of those candles (distribution).
- 🚚 High density - volume / range >= Density Factor x average density.
- 🤏 Small candle (optional, Spread condition) - range <= Spread Factor x average range.
- 🎯 Close position (optional, Bar close %) - for accumulation the close must sit at least X% above the low; for distribution at least X% below the high. 0 disables the filter.
- 🔊 volume > 0 - instruments without volume data never signal.
Both averages (range and density) use a window ending at the previous candle - the signal candle does not inflate its own threshold.
By default the conditions are checked only once the candle closes (Signal on closed candle only) - a marker never appears and then disappears on the live candle.
█ 🛠️ PARAMETERS
Parameters (as in xStation)
- Max/Min of (bars) (default 5) - how many previous candles the signal candle must out-low / out-high.
- Average Spread of (bars) (default 5) - window for the average range.
- Average Density of (bars) (default 5) - window for the average density.
- Spread condition (default on) - toggle for the "candle must not be too big" filter.
- Spread Factor (default 1.4) - how much larger than the average range the signal candle may be.
- Density Factor (default 2) - how many times the average density the candle must reach.
- Bar close (%) (default 0) - the close-position filter described above.
- Signal on closed candle only (default on) - evaluate signals only when a candle closes (no repainting). Turn off to watch signals form in real time on the unclosed candle - such a signal may vanish before the close.
Appearance (Style tab)
Markers are plotshapes, so each signal gets its own row in the Style tab of the indicator settings - with a visibility checkbox, a marker-shape picker, a position dropdown (Above bar / Below bar), and a color:
- Accumulation (default: triangle below the bar),
- Distribution (default: triangle above the bar).
█ 🔔 ALERTS
- Accumulation density - potential bullish signal (heavy volume, little movement, new low).
- Distribution density - potential bearish signal (heavy volume, little movement, new high).
With Signal on closed candle only on (default) alerts fire at the candle close. If you turn that option off, set the alert trigger to Once Per Bar Close - otherwise an alert can fire on a live-candle signal that later vanishes.
█ 📤 SIGNAL OUTPUT
The script exposes a hidden Signal series: +1 (accumulation), -1 (distribution), 0 (none). It is visible in the Data Window and can be used as an external source in other indicators and strategies (any input.source field) - e.g. to build your own strategy on top of these signals.
█ ✅ CORRECTNESS - VERIFIED
The implementation was verified empirically (2026-08-18): signals recomputed independently (Node.js, same formulas) from OHLCV bars pulled off a live TradingView chart (COMEX:GC1!, 60m, 300 bars) and compared with the markers the Pine script actually drew:
- default parameters → 1 signal, exact match (and 299 bars correctly without a marker),
- relaxed parameters (Max/Min 3, Spread Factor 2.5, Density Factor 1.2) → 63 signals, exact match, zero missing, zero extra.
The script does exactly what this note describes.
█ ⚠️ WHY MARKERS DIFFER FROM XSTATION
Even with identical parameter values, markers will not land 1:1 on xStation's. This is expected, not a bug:
- 📊 Different data. xStation runs on XTB's own CFD feed; its volume is XTB tick volume (count of price updates in XTB's book). TradingView shows real exchange volume (futures/stocks) or another provider's feed. Density = volume / range is extremely sensitive to both - different volume and different OHLC (session hours, timezone, weekend CFD candles) shift every threshold in the formula.
- 🔒 The original algorithm is closed source. XTB only published parameter descriptions, not formulas. Ambiguities the port had to decide (each can move single markers):
- averages computed over the window ending at the previous candle (the original may include the signal candle),
- new-extreme check uses <= / >= (the original may require a strict break),
- a zero-range candle (doji) divides by one tick instead of being skipped,
- "Bar close %" measured from the low (accumulation) / from the high (distribution).
- ⏳ Live-candle behavior. With Signal on closed candle only turned off, conditions are evaluated on live values, so a marker on an unclosed candle can disappear before the close. The default (on) evaluates only closed candles; xStation's behavior here is unknown.
Practical takeaway: compare the two on the same market data type (e.g. gold futures on both), expect agreement in character (markers cluster in the same spots), not in identical candles.
█ ⛔ LIMITATIONS
- Requires an instrument with volume data - many TVC CFDs (TVC:GOLD, TVC:USOIL) have zero volume and never signal; the script then shows a warning in the top-right corner of the chart. Check per symbol (e.g. TVC:UKOIL does have volume) or use futures (e.g. COMEX:GC1!).
- A signal on an unclosed candle may vanish before the close - only with Signal on closed candle only turned off (see above).
© Piotr Kowalski "piecioshka". License: Mozilla Public License 2.0.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.