Here is the fully rebuilt Institutional Liquidity & Sweep [PRO] script.
Code: Select all
//@version=5
indicator("Institutional Liquidity: EQH/EQL Sweeps [PRO]", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=100)
// ==============================================================================
// 1. INPUTS & SETTINGS
// ==============================================================================
grp_liq = "Liquidity & Structure"
pLen = input.int(10, "Pivot Lookback", group=grp_liq, tooltip="Bars needed on each side to form a swing point.")
tickTol = input.float(15.0, "Equal Tolerance (Ticks)", group=grp_liq, tooltip="Max distance between two pivots to be considered 'Equal'.")
grp_ses = "Session & Context"
useSession = input.bool(true, "Highlight Accumulation Session", group=grp_ses)
sessTime = input.session("1800-0200", "Accumulation Session (Exchange Time)", group=grp_ses, tooltip="E.g., Asian session. Sweeps of highs/lows formed here are high probability.")
sessColor = input.color(color.new(color.blue, 90), "Session Color", group=grp_ses)
grp_ui = "Visuals & Alerts"
showLabels = input.bool(true, "Show Entry & Stop Loss Labels", group=grp_ui)
// ==============================================================================
// 2. USER-DEFINED TYPES (UDT) FOR STATE MANAGEMENT
// ==============================================================================
type LiquidityLevel
float price = na
int timeStart = na
bool isActive = false
bool isSwept = false
float sweepExtr = na // Highest high (EQH) or Lowest low (EQL) of the sweep
float triggerBOS = na // Micro structure to break for BOS entry
line visualLine = na
var LiquidityLevel eqh = LiquidityLevel.new()
var LiquidityLevel eql = LiquidityLevel.new()
// ==============================================================================
// 3. SESSION HIGHLIGHTING
// ==============================================================================
inSession = not na(time(timeframe.period, sessTime))
var int sessStart = na
if inSession and not inSession[1]
sessStart := time
if not inSession and inSession[1] and useSession
box.new(sessStart, high, time, low, xloc=xloc.bar_time, bgcolor=sessColor, border_color=na)
// ==============================================================================
// 4. CORE LOGIC: IDENTIFYING EQUAL HIGHS (EQH) & EQUAL LOWS (EQL)
// ==============================================================================
threshold = tickTol * syminfo.mintick
// Find Pivots
ph = ta.pivothigh(high, pLen, pLen)
pl = ta.pivotlow(low, pLen, pLen)
// Track previous pivots to compare against
var float last_ph = na, var int time_ph = na
var float last_pl = na, var int time_pl = na
// Evaluate EQH
if not na(ph)
if not na(last_ph) and math.abs(ph - last_ph) <= threshold
// Valid EQH Found
eqh.price := math.max(ph, last_ph)
eqh.timeStart := time_ph
eqh.isActive := true
eqh.isSwept := false
if not na(eqh.visualLine)
line.delete(eqh.visualLine)
eqh.visualLine := line.new(eqh.timeStart, eqh.price, time, eqh.price, xloc=xloc.bar_time, color=color.new(color.red, 20), width=2, style=line.style_solid)
line.extend(eqh.visualLine, extend.right)
last_ph := ph
time_ph := time[pLen]
// Evaluate EQL
if not na(pl)
if not na(last_pl) and math.abs(pl - last_pl) <= threshold
// Valid EQL Found
eql.price := math.min(pl, last_pl)
eql.timeStart := time_pl
eql.isActive := true
eql.isSwept := false
if not na(eql.visualLine)
line.delete(eql.visualLine)
eql.visualLine := line.new(eql.timeStart, eql.price, time, eql.price, xloc=xloc.bar_time, color=color.new(color.blue, 20), width=2, style=line.style_solid)
line.extend(eql.visualLine, extend.right)
last_pl := pl
time_pl := time[pLen]
// ==============================================================================
// 5. THE TAPE: SWEEP, RECLAIM, AND BOS EXECUTION
// ==============================================================================
// Helper Function for Entry UI
draw_entry(txt, extPrice, isShort) =>
if showLabels
clr = isShort ? color.red : color.blue
lblY = isShort ? high : low
sty = isShort ? label.style_label_down : label.style_label_up
slText = "\nSL: " + str.tostring(extPrice, format.mintick)
label.new(time, lblY, txt + slText, xloc=xloc.bar_time, color=clr, textcolor=color.white, style=sty, size=size.small)
// --- PROCESS EQH (SHORT SCENARIOS) ---
if eqh.isActive
// Initial Sweep
if high > eqh.price and not eqh.isSwept
eqh.isSwept := true
eqh.sweepExtr := high
eqh.triggerBOS := low
line.set_style(eqh.visualLine, line.style_dashed)
line.set_color(eqh.visualLine, color.new(color.gray, 50))
line.set_extend(eqh.visualLine, extend.none)
line.set_x2(eqh.visualLine, time)
// Instant Reclaim (Thin Tape)
if close < eqh.price
draw_entry("RECLAIM", eqh.sweepExtr, true)
alert("EQH Instant Reclaim Short. SL: " + str.tostring(eqh.sweepExtr), alert.freq_once_per_bar_close)
eqh.isActive := false
// Swept, now waiting for Delayed Reclaim or BOS
else if eqh.isSwept
// Trail extreme and micro-structure low
if high > eqh.sweepExtr
eqh.sweepExtr := high
if high > high[1] and low > eqh.triggerBOS
eqh.triggerBOS := low
// Trigger 1: Delayed Reclaim
if close < eqh.price and close[1] >= eqh.price
draw_entry("RECLAIM", eqh.sweepExtr, true)
alert("EQH Delayed Reclaim Short. SL: " + str.tostring(eqh.sweepExtr), alert.freq_once_per_bar_close)
eqh.isActive := false
// Trigger 2: Micro BOS (Displacement Filter)
else if close < eqh.triggerBOS and close[1] >= eqh.triggerBOS
draw_entry("BOS", eqh.sweepExtr, true)
alert("EQH Micro BOS Short. SL: " + str.tostring(eqh.sweepExtr), alert.freq_once_per_bar_close)
eqh.isActive := false
// --- PROCESS EQL (LONG SCENARIOS) ---
if eql.isActive
// Initial Sweep
if low < eql.price and not eql.isSwept
eql.isSwept := true
eql.sweepExtr := low
eql.triggerBOS := high
line.set_style(eql.visualLine, line.style_dashed)
line.set_color(eql.visualLine, color.new(color.gray, 50))
line.set_extend(eql.visualLine, extend.none)
line.set_x2(eql.visualLine, time)
// Instant Reclaim (Thin Tape)
if close > eql.price
draw_entry("RECLAIM", eql.sweepExtr, false)
alert("EQL Instant Reclaim Long. SL: " + str.tostring(eql.sweepExtr), alert.freq_once_per_bar_close)
eql.isActive := false
// Swept, now waiting for Delayed Reclaim or BOS
else if eql.isSwept
// Trail extreme and micro-structure high
if low < eql.sweepExtr
eql.sweepExtr := low
if low < low[1] and high < eql.triggerBOS
eql.triggerBOS := high
// Trigger 1: Delayed Reclaim
if close > eql.price and close[1] <= eql.price
draw_entry("RECLAIM", eql.sweepExtr, false)
alert("EQL Delayed Reclaim Long. SL: " + str.tostring(eql.sweepExtr), alert.freq_once_per_bar_close)
eql.isActive := false
// Trigger 2: Micro BOS (Displacement Filter)
else if close > eql.triggerBOS and close[1] <= eql.triggerBOS
draw_entry("BOS", eql.sweepExtr, false)
alert("EQL Micro BOS Long. SL: " + str.tostring(eql.sweepExtr), alert.freq_once_per_bar_close)
eql.isActive := false