Accumulation/Distribution Indicator — Free Pine Script v6 for TradingView
- accumulation-distribution-indicator.pine — the complete Pine Script v6 source
- README-FIRST.md — what it does and how to install it
- FREE-LICENSE.md — the free-edition license terms
About this product
Accumulation/Distribution Indicator is a free Pine Script v6 indicator by Script Master Labs. It computes the Accumulation/Distribution Line from its raw formula, with an EMA and pivot divergences. The complete source is printed in full on this page and in the free download — paste it into TradingView's Pine Editor and it runs on TradingView's free plan. No payment, no account, no subscription.
What it computes, in its own terms: it the Accumulation/Distribution Line (ADL) from its raw formula — where each bar's close sat inside that bar's range, weighted by volume, added up over time — plus an EMA of the ADL and confirmed-pivot divergences between price and the ADL. It makes no prediction and no profitability claim.
How to use it
Open TradingView's Pine Editor, create a new blank indicator, paste the source, save, and click Add to chart. Adjust the inputs from the gear icon. The full source is printed on this page below, and the free download carries the same source file with an install README and the free-edition license.
Free edition vs paid edition
The script file is the complete indicator — the same Pine Script v6 source sold in the paid edition (https://dual.scriptmasterlabs.com/product/accumulation-distribution-indicator, $19 one-time). The paid edition adds the full written user guide, the evidence receipt, and the licensing and security reviews. Nothing in the script is held back from the free edition.
More free tools — five free Pine Script v6 indicators and a free x402 pre-payment trust check — are collected on the Free Tools hub. Educational software, not financial advice: it measures and draws a stated rule; it does not predict price and shows no win rate.
The complete Pine Script v6 source — free, on this page
Accumulation/Distribution Indicator is a free Pine Script v6 indicator by Script Master Labs. It computes the Accumulation/Distribution Line from its raw formula, with an EMA and pivot divergences. The complete source is printed in full on this page and in the free download — paste it into TradingView's Pine Editor and it runs on TradingView's free plan. No payment, no account, no subscription.
// © 2026 Script Master Labs LLC — Accumulation Distribution Indicator for TradingView
// Research-based, original SML engineering. This indicator COMPUTES the
// Accumulation/Distribution Line (ADL) from its raw formula, plots an EMA of
// it, and marks confirmed-pivot divergences between price and the ADL.
// It makes no prediction and no profitability claim. The ADL describes where
// each bar's close sat inside that bar's range, weighted by volume, added up
// over time. It does not say what price will do next.
//
// Mechanical definition (implemented exactly, from the raw formula — the
// built-in accumulation/distribution shortcut is NOT called, so every
// value can be re-derived by hand from the guide):
// Money Flow Multiplier MFM = ((close - low) - (high - close)) / (high - low)
// MFM = 0 when high == low
// Money Flow Volume MFV = MFM * volume
// ADL = cumulative sum of MFV from the first bar
// This is the classic Chaikin Accumulation/Distribution Line definition.
//
// No repainting: divergences use CONFIRMED pivots only. A pivot at bar N is
// not known until bar N + pivotLen, so a divergence marker appears on the
// confirmation bar of the second pivot (pivotLen bars after that pivot
// itself) and never moves after that bar closes.
//@version=6
indicator("SML Accumulation Distribution Indicator", shorttitle = "SML A/D", overlay = false, max_labels_count = 500)
// ── Inputs ──────────────────────────────────────────────────────────────────
grpAdl = "ADL Line"
adlColor = input.color(color.teal, "ADL color", group = grpAdl)
adlWidth = input.int(2, "ADL line width", minval = 1, maxval = 4, group = grpAdl)
emaLen = input.int(21, "EMA length (bars)", minval = 1, maxval = 200, group = grpAdl)
emaColor = input.color(color.orange, "EMA color", group = grpAdl)
emaWidth = input.int(1, "EMA line width", minval = 1, maxval = 4, group = grpAdl)
grpDiv = "Divergence"
pivotLen = input.int(5, "Pivot length (bars each side)", minval = 1, maxval = 20, group = grpDiv)
showDiv = input.bool(true, "Show divergence markers", group = grpDiv)
grpMarker = "Markers"
markerShape = input.string("Arrow", "Marker shape", options = ["Arrow", "Triangle"], group = grpMarker)
markerSize = input.string("small", "Marker size", options = ["tiny", "small"], group = grpMarker)
labelMode = input.string("Buy/Sell", "Marker label mode", options = ["Buy/Sell", "Call/Put"], group = grpMarker)
bullMarkCol = input.color(color.teal, "Bullish divergence marker color", group = grpMarker)
bearMarkCol = input.color(color.red, "Bearish divergence marker color", group = grpMarker)
grpTable = "Table"
showTable = input.bool(true, "Show table", group = grpTable)
tableSize = input.string("normal", "Table size", options = ["tiny", "small", "normal"], group = grpTable)
tablePos = input.string(position.top_right, "Table position", options = [position.top_right, position.top_left, position.bottom_right, position.bottom_left, position.middle_right], group = grpTable)
// ── Accumulation / Distribution Line (raw formula) ──────────────────────────
hasVolume = not na(volume)
float barRange = high - low
float mfm = na
if hasVolume
mfm := barRange == 0 ? 0.0 : ((close - low) - (high - close)) / barRange
float mfv = hasVolume ? mfm * volume : na
float adl = ta.cum(mfv)
float emaAdl = ta.ema(adl, emaLen)
// ── State (a description of the two lines' relative position only) ─────────
string adlState = na(adl) or na(emaAdl) ? "—" : adl > emaAdl ? "Accumulation" : adl < emaAdl ? "Distribution" : "Equal"
// ── Confirmed-pivot divergence ──────────────────────────────────────────────
// A price pivot and an ADL pivot are "corresponding" when they are confirmed
// on the same bar, i.e. their pivot bars coincide (both use the same
// pivotLen, so both confirm pivotLen bars after the shared pivot bar).
// Bullish divergence: the newer paired pivot low is LOWER in price and
// HIGHER in ADL than the previous paired pivot low.
// Bearish divergence: the newer paired pivot high is HIGHER in price and
// LOWER in ADL than the previous paired pivot high.
float phPrice = ta.pivothigh(high, pivotLen, pivotLen)
float plPrice = ta.pivotlow(low, pivotLen, pivotLen)
float phAdl = ta.pivothigh(adl, pivotLen, pivotLen)
float plAdl = ta.pivotlow(adl, pivotLen, pivotLen)
var float lastLowPrice = na
var float lastLowAdl = na
var float lastHighPrice = na
var float lastHighAdl = na
var string lastDivText = "None"
var int lastDivBar = na
bool bullDiv = false
bool bearDiv = false
if barstate.isconfirmed
if not na(plPrice) and not na(plAdl)
if not na(lastLowPrice) and plPrice < lastLowPrice and plAdl > lastLowAdl
bullDiv := true
lastDivText := "Bullish divergence"
lastDivBar := bar_index
lastLowPrice := plPrice
lastLowAdl := plAdl
if not na(phPrice) and not na(phAdl)
if not na(lastHighPrice) and phPrice > lastHighPrice and phAdl < lastHighAdl
bearDiv := true
lastDivText := "Bearish divergence"
lastDivBar := bar_index
lastHighPrice := phPrice
lastHighAdl := phAdl
// ── Plots ───────────────────────────────────────────────────────────────────
plot(adl, "ADL", color = adlColor, linewidth = adlWidth)
plot(emaAdl, "EMA of ADL", color = emaColor, linewidth = emaWidth)
plot(mfm, "MFM (data window)", display = display.data_window)
// ── Divergence markers (shared marker settings) ─────────────────────────────
bool useArrow = markerShape == "Arrow"
string bullShape = useArrow ? shape.arrowup : shape.triangleup
string bearShape = useArrow ? shape.arrowdown : shape.triangledown
string markSize = markerSize == "tiny" ? size.tiny : size.small
string bullText = labelMode == "Buy/Sell" ? "BUY" : "CALL"
string bearText = labelMode == "Buy/Sell" ? "SELL" : "PUT"
plotshape(showDiv and bullDiv, title = "Bullish divergence", style = bullShape, location = location.bottom, color = bullMarkCol, size = markSize, text = bullText, textcolor = color.white)
plotshape(showDiv and bearDiv, title = "Bearish divergence", style = bearShape, location = location.top, color = bearMarkCol, size = markSize, text = bearText, textcolor = color.white)
// ── Smart table (all text white) ────────────────────────────────────────────
string tblSize = tableSize == "tiny" ? size.tiny : tableSize == "small" ? size.small : size.normal
var table tbl = table.new(tablePos, 2, 5, bgcolor = color.new(color.black, 15), border_width = 1, border_color = color.white, text_color = color.white)
if barstate.islast and showTable
string divCell = na(lastDivBar) ? "None" : lastDivText + " · " + str.tostring(bar_index - lastDivBar) + " bars ago"
table.cell(tbl, 0, 0, "SML A/D", text_color = color.white, text_size = tblSize)
table.cell(tbl, 1, 0, hasVolume ? "Volume OK" : "No volume data", text_color = color.white, text_size = tblSize)
table.cell(tbl, 0, 1, "ADL", text_color = color.white, text_size = tblSize)
table.cell(tbl, 1, 1, hasVolume ? str.tostring(adl, format.volume) : "No volume data", text_color = color.white, text_size = tblSize)
table.cell(tbl, 0, 2, "ADL vs EMA", text_color = color.white, text_size = tblSize)
table.cell(tbl, 1, 2, hasVolume ? adlState : "No volume data", text_color = color.white, text_size = tblSize)
table.cell(tbl, 0, 3, "MFM (last bar)", text_color = color.white, text_size = tblSize)
table.cell(tbl, 1, 3, hasVolume ? str.tostring(mfm, "#.00") : "No volume data", text_color = color.white, text_size = tblSize)
table.cell(tbl, 0, 4, "Last divergence", text_color = color.white, text_size = tblSize)
table.cell(tbl, 1, 4, hasVolume ? divCell : "No volume data", text_color = color.white, text_size = tblSize)
// ── Alerts (descriptive only — a detected pattern, not a signal to trade) ──
alertcondition(bullDiv, title = "Bullish divergence confirmed", message = "Bullish ADL divergence confirmed (pivot-confirmed) on {{exchange}}:{{ticker}} ({{interval}}).")
alertcondition(bearDiv, title = "Bearish divergence confirmed", message = "Bearish ADL divergence confirmed (pivot-confirmed) on {{exchange}}:{{ticker}} ({{interval}}).")
Questions about this product
Is there a free Pine Script for the Accumulation/Distribution Line on TradingView?
Yes. Script Master Labs publishes this Accumulation/Distribution Indicator as a free Pine Script v6 download on SML Dual Market (https://dual.scriptmasterlabs.com/product/free-accumulation-distribution-indicator). The complete source is printed in full on the product page and in the free download — no payment, no account, no subscription.
How do I use the Accumulation/Distribution Indicator?
Open TradingView's Pine Editor, create a new blank indicator, paste the source, click Save, then Add to chart. Adjust the inputs from the gear icon. TradingView's first-steps page shows where the editor opens: https://tradingview.com/pine-script-docs/primer/first-steps
Does it work on TradingView's free plan?
Yes. Paste the source into TradingView's Pine Editor and add it to your chart; the free plan runs custom indicators.
Is the free edition the complete script?
Yes — the same Pine Script v6 source file sold in the paid edition ($19 one-time). The paid edition adds the full written user guide, the evidence receipt, and the licensing and security reviews; nothing in the script itself is held back.
Does it repaint?
No. Its events are computed on confirmed bars only; a marker, once printed, does not move or disappear.