This PineScript indicator implements a comprehensive A/D Line analysis tool with moving average overlay, divergence detection, and customizable alerts. It helps traders identify market breadth trends and potential reversals through visual and automated signals.
//@version=6
indicator("Advance/Decline Line Analysis", shorttitle="A/D Line", overlay=false)
// Input Parameters
advancingSymbol = input.symbol("NYSE:ADVN", title="Advancing Stocks Symbol")
decliningSymbol = input.symbol("NYSE:DECL", title="Declining Stocks Symbol")
smoothingLength = input.int(20, minval=1, title="Smoothing Length")
showMA = input.bool(true, title="Show Moving Average")
alertOn = input.bool(true, title="Enable Alerts")
// Fetch advancing and declining stocks data
advancing = request.security(advancingSymbol, "D", close)
declining = request.security(decliningSymbol, "D", close)
// Calculate Net Advances
netAdvances = advancing - declining
// Calculate A/D Line (Cumulative Sum)
adLine = ta.cum(netAdvances)
// Calculate Moving Average of A/D Line
adLineMA = ta.sma(adLine, smoothingLength)
// Detect Divergence
priceHigher = close > close[1]
adLineLower = adLine < adLine[1]
bearishDivergence = priceHigher and adLineLower
priceLower = close < close[1]
adLineHigher = adLine > adLine[1]
bullishDivergence = priceLower and adLineHigher
// Plotting
plot(adLine, title="A/D Line", color=color.blue, linewidth=2)
plot(showMA ? adLineMA : na, title="A/D Line MA", color=color.orange, linewidth=1)
// Plot divergence signals
plotshape(bearishDivergence and alertOn ? adLine : na, title="Bearish Divergence",
location=location.absolute, style=shape.triangledown, color=color.red, size=size.small)
plotshape(bullishDivergence and alertOn ? adLine : na, title="Bullish Divergence",
location=location.absolute, style=shape.triangleup, color=color.green, size=size.small)
// Alerts
if alertOn
if bearishDivergence
alert("Bearish Divergence Detected", alert.freq_once_per_bar)
if bullishDivergence
alert("Bullish Divergence Detected", alert.freq_once_per_bar
Advancing/Declining Symbols: defines how much higher the current volume must be in comparison to the average volume to trigger a "surge". Default is 1.5 (150% of the average volume)
Smoothing Length: adjustable period for the moving average (default:20)
Display Options: Toggle moving average visibility and alerts