// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © AI_PIPS //@version=6 indicator("AIPIPS Liquidity Sweep Detector", overlay=true, max_lines_count=300, max_labels_count=300) lookback = input.int(5, "Swing lookback", minval=1) tolerancePct = input.float(0.05, "Equal level tolerance (%)", step=0.01, minval=0.01) showSweepsOnly = input.bool(false, "Only highlight sweeps") pctDiff(a, b) => math.abs(a - b) / nz(b == 0.0 ? na : b, a) * 100 ph = ta.pivothigh(high, lookback, lookback) pl = ta.pivotlow(low, lookback, lookback) prevPH = ta.valuewhen(not na(ph), ph, 1) prevPL = ta.valuewhen(not na(pl), pl, 1) isEqualHigh = not na(ph) and not na(prevPH) and pctDiff(ph, prevPH) <= tolerancePct isEqualLow = not na(pl) and not na(prevPL) and pctDiff(pl, prevPL) <= tolerancePct sweptHigh = isEqualHigh[1] and high > nz(prevPH[1]) sweptLow = isEqualLow[1] and low < nz(prevPL[1]) plotshape(isEqualHigh and not showSweepsOnly, title="Equal High", style=shape.triangledown, color=color.orange, offset=-lookback, text="EQH") plotshape(isEqualLow and not showSweepsOnly, title="Equal Low", style=shape.triangleup, color=color.teal, offset=-lookback, text="EQL") plotshape(sweptHigh, title="Liquidity Grab High", style=shape.labeldown, color=color.new(color.red, 0), text="Sweep↑", location=location.abovebar) plotshape(sweptLow, title="Liquidity Grab Low", style=shape.labelup, color=color.new(color.green, 0), text="Sweep↓", location=location.belowbar) bgcolor(sweptHigh ? color.new(color.red, 90) : sweptLow ? color.new(color.green, 90) : na)