All pages
Powered by GitBook
1 of 1

Loading...

Advance/Decline Line

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

Key Features and Components

1

Inputs

  • 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

2

Calculation Methods

  • Net Advances: (Advancing Stocks - Declining Stocks)

  • A/D Line: Cumulative sum of net advances using ta.cum( )

  • Moving Average: Simple Moving Average of the A/D line for trend identification.

3

Diversion Detection

  • Bearish Divergence: Price Making higher highs while A/D line makes lower highs.

  • Bullish Divergence: Price making lower lows while A/D line makes higher lows.

Suggested Use

1

Timeframe

Daily charts for optimal market breadth analysis.

2

Moving Average Period

Definitely reccomend 20 trading days.

3

Alert Settings

Enable specifically for automated bullish and bearish divergence detection.

Interpretation Guidelines

1

Uptrending A/D Line

Indicates broader market strength.

2

Downtrending A/D Line

Suggests market weakness.

3

Divergences

Watch for potential trend reversals when price and A/D line move in opposite directions.