//@version=5
indicator("Absorption Indicator [Clean]", overlay=true)
// Input parameters
length = input.int(14, title="Lookback Period")
volumeThreshold = input.float(1.5, title="Volume Threshold (Multiplier of Average Volume)")
candleSizeThreshold = input.float(1.5, title="Candle Size Threshold (Multiplier of Average Candle Size)")
// Toggles for cleaner chart
showSignals = input.bool(true, title="Show Buy/Sell Signals")
highlightBackground = input.bool(true, title="Highlight Background")
showLabels = input.bool(true, title="Show Labels on Signals")
// Calculate average volume and candle size
avgVolume = ta.sma(volume, length)
avgCandleSize = ta.sma(math.abs(high - low), length)
// Identify absorption candles
absorptionBuy = (volume > volumeThreshold * avgVolume) and (close > open) and ((high - low) > candleSizeThreshold * avgCandleSize) and (close > (high + low) / 2)
absorptionSell = (volume > volumeThreshold * avgVolume) and (close < open) and ((high - low) > candleSizeThreshold * avgCandleSize) and (close < (high + low) / 2)
// Plot absorption signals with toggles
plotshape(series=showSignals and absorptionBuy, title="Buy Absorption", location=location.belowbar, color=color.new(color.green, 0), style=shape.labelup, text="BUY", size=size.small)
plotshape(series=showSignals and absorptionSell, title="Sell Absorption", location=location.abovebar, color=color.new(color.red, 0), style=shape.labeldown, text="SELL", size=size.small)
// Optional: Highlight absorption candles with toggles
bgcolor(highlightBackground and absorptionBuy ? color.new(color.green, 90) : na, title="Buy Absorption Background")
bgcolor(highlightBackground and absorptionSell ? color.new(color.red, 90) : na, title="Sell Absorption Background")
// Add alerts for buy and sell signals
alertcondition(absorptionBuy, title="Buy Signal", message="Buy Signal Detected - Absorption Candle")
alertcondition(absorptionSell, title="Sell Signal", message="Sell Signal Detected - Absorption Candle")