Pine Script Accumulation/Distribution Line

Master this powerful volume-based indicator in TradingView's Pine Script that reveals hidden buying (accumulation) and selling (distribution) pressure to confirm trends and anticipate price movements.

Subscribe now @ $99/month

What is the Accumulation/Distribution Line?

The Accumulation/Distribution Line (A/D Line) is a volume-based momentum indicator that attempts to gauge the cumulative flow of money into and out of an asset. Developed by Marc Chaikin, it is a running total of each period's Money Flow Volume (MFV), which considers the closing price's relation to the high-low range of the period, multiplied by volume. The core idea is that the closer the closing price is to the period's high, the more buying (accumulation) occurred, and the closer to the low, the more selling (distribution).

A rising A/D Line indicates strong buying pressure (accumulation), suggesting that buyers are willing to push the price higher. A falling A/D Line indicates strong selling pressure (distribution), suggesting that sellers are in control. The A/D Line is primarily used to:

In Pine Script, the A/D Line is a valuable tool for understanding the underlying conviction behind price moves and anticipating future trends by observing money flow.

Components and Calculation

The calculation of the Accumulation/Distribution Line is cumulative and involves two main steps for each period:

  1. Money Flow Multiplier (MFM): This component determines the degree of buying or selling pressure within the bar's range. It is a value between -1 and +1.
    `MFM = ((Close - Low) - (High - Close)) / (High - Low)`
    * If `High - Low` is zero (a doji or zero-range bar), MFM is typically zero. * If `Close == High`, MFM = 1 (strong accumulation). * If `Close == Low`, MFM = -1 (strong distribution).
  2. Money Flow Volume (MFV): This multiplies the MFM by the period's volume.
    `MFV = MFM * Volume`
  3. Accumulation/Distribution Line (A/D Line): This is a running, cumulative total of the MFV.
    `A/D Line = Previous A/D Line + Current MFV`

The initial value of the A/D Line is usually zero for the first bar.

Basic Accumulation/Distribution Line Implementation in Pine Script

Pine Script v5 provides a convenient built-in function `ta.ad()` for calculating the Accumulation/Distribution Line.

//@version=5
indicator("My Accumulation/Distribution Line", overlay=false) // overlay=false to plot in a separate pane

// Calculate A/D Line using the built-in function
// ta.ad() implicitly uses 'high', 'low', 'close', and 'volume' for its calculation
adLineValue = ta.ad(high, low, close, volume)

// Plot the A/D Line
plot(adLineValue, title="Accumulation/Distribution Line", color=color.blue, linewidth=2)

// Optional: Add a Moving Average of the A/D Line to act as a signal line
// Common lengths for A/D MA are 10, 20, or 30
adMALength = input.int(21, title="A/D Line MA Length", minval=1)
adMA = ta.sma(adLineValue, adMALength)

// Plot the A/D Line Moving Average (signal line)
plot(adMA, title="A/D Line MA", color=color.orange, linewidth=1)
Money Flow, Not Just Volume: The A/D Line goes beyond raw volume by incorporating where the price closed within the bar's range, providing a more nuanced view of buying vs. selling pressure.

Practical Accumulation/Distribution Line Trading Strategies

1. Divergence (Key Strategy)

Divergence between price and the A/D Line is one of the most powerful signals, suggesting a weakening trend and potential reversal, as the volume flow is not confirming the price action.

//@version=5
strategy("A/D Line Divergence Strategy", overlay=true)

adLineValue = ta.ad(high, low, close, volume)

// Plot A/D Line in a separate pane
plot(adLineValue, "A/D Line", color=color.blue, display=display.pane_only)

// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This example looks for recent higher/lower swings in price and A/D Line.

// Bullish Divergence: Price makes a lower low, A/D makes a higher low
bullishDiv = close < close[1] and close[1] < close[2] and adLineValue > adLineValue[1] and adLineValue[1] > adLineValue[2]

// Bearish Divergence: Price makes a higher high, A/D makes a lower high
bearishDiv = close > close[1] and close[1] > close[2] and adLineValue < adLineValue[1] and adLineValue[1] < adLineValue[2]

// Plot shapes on the chart to indicate divergence
plotshape(bullishDiv, title="Bullish A/D Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDiv, title="Bearish A/D Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

if (bullishDiv)
    strategy.entry("Long Divergence", strategy.long)
if (bearishDiv)
    strategy.entry("Short Divergence", strategy.short)

// Basic exit after a few bars or on opposite signal
strategy.exit("Long Divergence Exit", from_entry="Long Divergence", profit=close*0.02, loss=close*0.01)
strategy.exit("Short Divergence Exit", from_entry="Short Divergence", profit=close*0.02, loss=close*0.01)

2. Trend Confirmation

The A/D Line is an excellent tool for confirming the strength and validity of a price trend. Ideally, price and the A/D Line should move in the same direction.

//@version=5
strategy("A/D Line Trend Confirmation", overlay=true)

adLineValue = ta.ad(high, low, close, volume)
adMALength = input.int(21, title="A/D MA Length", minval=1)
adMA = ta.sma(adLineValue, adMALength) // Moving Average of A/D Line

plot(adLineValue, "A/D Line", color=color.blue, display=display.pane_only)
plot(adMA, "A/D Line MA", color=color.orange, display=display.pane_only)

// Price trend filter (e.g., using a long-term EMA)
priceMALength = input.int(50, title="Price MA Length", minval=1)
priceMA = ta.ema(close, priceMALength)

// Conditions for trend confirmation based on A/D and Price
// Long: Price above MA AND A/D Line above its MA (or rising)
longConfirm = close > priceMA and adLineValue > adMA and adLineValue > adLineValue[1]

// Short: Price below MA AND A/D Line below its MA (or falling)
shortConfirm = close < priceMA and adLineValue < adMA and adLineValue < adLineValue[1]

if (longConfirm)
    strategy.entry("Long Confirm", strategy.long)

if (shortConfirm)
    strategy.entry("Short Confirm", strategy.short)

// Basic exit: Price crosses back over price MA OR A/D Line crosses its MA
strategy.close("Long Confirm", when=close < priceMA or adLineValue < adMA)
strategy.close("Short Confirm", when=close > priceMA or adLineValue > adMA)

3. Support and Resistance Breaks (on the A/D Line)

Just like price, the A/D Line can form its own support and resistance levels, and breaking these can be an early signal of price movement.

//@version=5
indicator("A/D Line S/R Breakouts", overlay=true)

adLineValue = ta.ad(high, low, close, volume)

plot(adLineValue, "A/D Line", color=color.blue, display=display.pane_only)

// A simple way to detect A/D Line S/R breaks (conceptually)
// This will require more complex pivot detection for robust S/R lines.
// For illustration, let's use a very simple high/low breakdown.

// Define recent high/low on A/D Line
adHighest = ta.highest(adLineValue, 20) // 20-period highest A/D
adLowest = ta.lowest(adLineValue, 20)   // 20-period lowest A/D

// Bullish A/D Line breakout: A/D crosses above its recent high
bullishAdBreakout = adLineValue > adHighest[1] and adLineValue[1] <= adHighest[1]

// Bearish A/D Line breakdown: A/D crosses below its recent low
bearishAdBreakdown = adLineValue < adLowest[1] and adLineValue[1] >= adLowest[1]

// Plot shapes on the price chart to indicate A/D Line signals
plotshape(bullishAdBreakout, title="Bullish A/D Breakout", location=location.belowbar, color=color.lime, style=shape.arrowup, size=size.small)
plotshape(bearishAdBreakdown, title="Bearish A/D Breakdown", location=location.abovebar, color=color.maroon, style=shape.arrowdown, size=size.small)

alertcondition(bullishAdBreakout, "A/D Line Bullish Breakout", "A/D Line has broken out upwards, anticipate price move.")
alertcondition(bearishAdBreakdown, "A/D Line Bearish Breakdown", "A/D Line has broken down, anticipate price move.")

Optimizing Accumulation/Distribution Line Performance

To get the most from the Accumulation/Distribution Line in Pine Script:

Underlying Conviction: The A/D Line helps you see if institutional money (or significant volume) is genuinely supporting a price move, or if the move is happening on thin volume and might be a "fakeout."

Common Accumulation/Distribution Line Pitfalls

Conclusion

The Accumulation/Distribution Line (A/D Line) is a fundamental and powerful volume-based technical indicator available in Pine Script for TradingView. By quantifying money flow through the relationship between closing price, high/low range, and volume, it provides traders with invaluable insights into the underlying buying (accumulation) and selling (distribution) pressure in the market. While its greatest strength lies in identifying divergences with price (signaling potential trend reversals), it is also highly effective at confirming existing trends and identifying early shifts in market conviction. By understanding its calculation, thoughtfully utilizing its signals, and integrating it strategically with price action and other technical analysis tools, you can leverage the A/D Line to enhance your trading decisions and gain a clearer understanding of smart money activity.

Enhance Your Trading

Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.

This strategy runs in live mode on TradingView, helping you identify potential opportunities.

Subscribe now @ $99/month