本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("SMC Liquidity Suite - Sweeps, FVG, OB, Fake Breaks", shorttitle="Trade with abhishek SMC Liq Suite", overlay=true,
max_lines_count=500, max_boxes_count=500, max_labels_count=500)
// ============================================================
// KYA KYA MARK HOTA HAI
// 1) Swing High/Low liquidity: BSL (buy-side) / SSL (sell-side) lines + zones
// 2) EQH / EQL (equal highs / lows) = bhaari liquidity pool
// 3) Liquidity Grab (sweep): wick level ke bahar, close wapas andar
// 4) Fake Breakout / Fake Breakdown: close bahar, phir kuch candles me wapas andar (trap)
// 5) Displacement candles (bade body wali impulsive candle)
// 6) FVG (Fair Value Gap) - mitigate hone tak
// 7) Order Blocks - displacement + structure break se pehle ki last opposite candle
// 8) BOS / CHoCH (market structure)
// 9) Panel: Structure, Sentiment, Last event, Behaviour, Nearest BSL/SSL, FVG/OB count
// ============================================================
// ---------------- Inputs ----------------
gSw = "Swings & Liquidity"
swingLen = input.int(5, "Swing length (pivot left/right)", minval=2, maxval=30, group=gSw)
showLiq = input.bool(true, "Show liquidity levels (BSL / SSL)", group=gSw)
showZones = input.bool(true, "Show liquidity zones", group=gSw)
zoneATR = input.float(0.15, "Zone half-width (x ATR)", step=0.05, minval=0.02, group=gSw)
showEq = input.bool(true, "Detect equal highs / lows (EQH / EQL)", group=gSw)
eqTol = input.float(0.10, "Equal H/L tolerance (x ATR)", step=0.02, minval=0.01, group=gSw)
maxKeep = input.int(30, "Max liquidity levels kept", minval=5, maxval=100, group=gSw)
keepSwept = input.bool(true, "Keep swept / broken lines (faded)", group=gSw)
gGr = "Grabs & Fake Breaks"
showGrab = input.bool(true, "Show liquidity grab labels", group=gGr)
showFake = input.bool(true, "Show fake breakout / breakdown labels", group=gGr)
fakeBars = input.int(3, "Fake break: close wapas andar aane ki max bars", minval=1, maxval=10, group=gGr)
gDi = "Displacement"
showDisp = input.bool(true, "Show displacement candles", group=gDi)
dispMult = input.float(1.5, "Body > ATR x", step=0.1, minval=0.5, group=gDi)
bodyRatio = input.float(0.6, "Min body / range ratio", step=0.05, minval=0.3, maxval=1.0, group=gDi)
gFv = "Fair Value Gap"
showFVG = input.bool(true, "Show FVG", group=gFv)
fvgMin = input.float(0.10, "Min gap size (x ATR)", step=0.05, minval=0.0, group=gFv)
fvgDispOnly = input.bool(false, "Only FVG with displacement candle", group=gFv)
fvgMax = input.int(12, "Max FVG boxes", minval=2, maxval=40, group=gFv)
hideMit = input.bool(true, "Hide mitigated FVG / OB", group=gFv)
gOb = "Order Blocks"
showOB = input.bool(true, "Show order blocks", group=gOb)
obLookback = input.int(10, "OB lookback bars", minval=3, maxval=30, group=gOb)
obMax = input.int(6, "Max OB boxes", minval=2, maxval=30, group=gOb)
gSt = "Structure & Panel"
showStruct = input.bool(true, "Show BOS / CHoCH", group=gSt)
showTable = input.bool(true, "Show sentiment panel", group=gSt)
tblPosStr = input.string("Top Right", "Panel position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group=gSt)
sentLook = input.int(30, "Sentiment lookback (bars)", minval=5, maxval=200, group=gSt)
gCo = "Colors"
colBSL = input.color(color.red, "BSL (buy-side liquidity)", group=gCo)
colSSL = input.color(color.green, "SSL (sell-side liquidity)", group=gCo)
colEQ = input.color(color.orange, "Equal highs / lows", group=gCo)
colBull = input.color(color.teal, "Bullish (FVG / OB / BOS)", group=gCo)
colBear = input.color(color.maroon, "Bearish (FVG / OB / BOS)", group=gCo)
colFake = input.color(color.purple, "Fake break / trap", group=gCo)
// ---------------- Types & helpers ----------------
type Liq
float price
bool isHigh
bool active
int state // 0 = untouched, 1 = closed beyond (fake-break check), 2 = swept, 3 = broken
int brokeBar
line ln
box zn
label lb
f_lbl(int x, float y, string t, bool above, color c) =>
label.new(x=x, y=y, text=t, xloc=xloc.bar_index, yloc=yloc.price, color=color.new(c, 80),
style=above ? label.style_label_down : label.style_label_up, textcolor=c, size=size.tiny)
f_end(Liq L, int xEnd, color c, bool keep, bool zones) =>
line.set_x2(L.ln, xEnd)
if keep
line.set_style(L.ln, line.style_dashed)
line.set_color(L.ln, color.new(c, 65))
else
line.delete(L.ln)
label.delete(L.lb)
if zones
box.delete(L.zn)
f_row(table t, int r, string k, string v, color vc) =>
table.cell(t, 0, r, k, text_color=color.white, bgcolor=color.new(color.gray, 25), text_halign=text.align_left, text_size=size.small)
table.cell(t, 1, r, v, text_color=vc, bgcolor=color.new(color.black, 25), text_halign=text.align_left, text_size=size.small)
// ---------------- State ----------------
var array<Liq> liqs = array.new<Liq>()
var array<box> fvgBoxes = array.new<box>()
var array<bool> fvgBull = array.new<bool>()
var array<box> obs = array.new<box>()
var array<bool> obBull = array.new<bool>()
var array<int> obBars = array.new<int>()
var float lastSH = na
var int lastSHbar = na
var bool shBroken = true
var float lastSL = na
var int lastSLbar = na
var bool slBroken = true
var int trend = 0
var int lastEvBar = na
var int lastEvDir = 0
var string lastEvTxt = "None"
var string lastEvDesc = "-"
var int lastDispBar = na
var int lastDispDir = 0
// ---------------- Core series ----------------
atrv = ta.atr(14)
atrPrev = nz(atrv[1], atrv)
ema50 = ta.ema(close, 50)
hh = ta.highest(high, obLookback)
ll = ta.lowest(low, obLookback)
ph = ta.pivothigh(high, swingLen, swingLen)
pl = ta.pivotlow(low, swingLen, swingLen)
body = math.abs(close - open)
rng = high - low
dispUp = close > open and rng > 0 and body > atrPrev * dispMult and body / rng >= bodyRatio
dispDn = close < open and rng > 0 and body > atrPrev * dispMult and body / rng >= bodyRatio
bool evBslGrab = false
bool evSslGrab = false
bool evFakeUp = false
bool evFakeDn = false
bool evBosUp = false
bool evBosDn = false
bool evChochUp = false
bool evChochDn = false
bool evObBull = false
bool evObBear = false
bool evFvgBull = false
bool evFvgBear = false
// ---------------- 1) New swing liquidity ----------------
if showLiq and not na(ph)
float z = atrv * zoneATR
bool isEq = false
int ns = array.size(liqs)
if showEq and ns > 0
for i = 0 to ns - 1
Liq o = array.get(liqs, i)
if o.isHigh and o.active and math.abs(o.price - ph) <= atrv * eqTol
isEq := true
line.set_width(o.ln, 2)
line.set_color(o.ln, colEQ)
break
int x0 = bar_index - swingLen
color c0 = isEq ? colEQ : colBSL
line ln = line.new(x0, ph, bar_index, ph, color=c0, style=line.style_dotted, width=isEq ? 2 : 1)
box zn = showZones ? box.new(x0, ph + z, bar_index, ph - z, border_color=na, bgcolor=color.new(c0, 85)) : na
label lb = label.new(x0, ph, isEq ? "EQH" : "BSL", style=label.style_label_down, color=color.new(color.white, 100), textcolor=c0, size=size.tiny)
array.push(liqs, Liq.new(ph, true, true, 0, 0, ln, zn, lb))
if showLiq and not na(pl)
float z = atrv * zoneATR
bool isEq = false
int ns = array.size(liqs)
if showEq and ns > 0
for i = 0 to ns - 1
Liq o = array.get(liqs, i)
if (not o.isHigh) and o.active and math.abs(o.price - pl) <= atrv * eqTol
isEq := true
line.set_width(o.ln, 2)
line.set_color(o.ln, colEQ)
break
int x0 = bar_index - swingLen
color c0 = isEq ? colEQ : colSSL
line ln = line.new(x0, pl, bar_index, pl, color=c0, style=line.style_dotted, width=isEq ? 2 : 1)
box zn = showZones ? box.new(x0, pl + z, bar_index, pl - z, border_color=na, bgcolor=color.new(c0, 85)) : na
label lb = label.new(x0, pl, isEq ? "EQL" : "SSL", style=label.style_label_up, color=color.new(color.white, 100), textcolor=c0, size=size.tiny)
array.push(liqs, Liq.new(pl, false, true, 0, 0, ln, zn, lb))
if array.size(liqs) > maxKeep
Liq old = array.shift(liqs)
line.delete(old.ln)
label.delete(old.lb)
if showZones
box.delete(old.zn)
// ---------------- 2) Market structure (BOS / CHoCH) ----------------
if not na(ph)
lastSH := ph
lastSHbar := bar_index - swingLen
shBroken := false
if not na(pl)
lastSL := pl
lastSLbar := bar_index - swingLen
slBroken := false
if showStruct
if not na(lastSH) and not shBroken and close > lastSH
shBroken := true
string tag = trend == -1 ? "CHoCH" : "BOS"
line.new(lastSHbar, lastSH, bar_index, lastSH, color=colBull, width=1)
f_lbl(int(math.round((lastSHbar + bar_index) / 2)), lastSH, tag, true, colBull)
if trend == -1
evChochUp := true
else
evBosUp := true
trend := 1
if not na(lastSL) and not slBroken and close < lastSL
slBroken := true
string tag = trend == 1 ? "CHoCH" : "BOS"
line.new(lastSLbar, lastSL, bar_index, lastSL, color=colBear, width=1)
f_lbl(int(math.round((lastSLbar + bar_index) / 2)), lastSL, tag, false, colBear)
if trend == 1
evChochDn := true
else
evBosDn := true
trend := -1
// ---------------- 3) Liquidity grabs & fake breaks ----------------
int nl = array.size(liqs)
if showLiq and nl > 0
for i = nl - 1 to 0
Liq L = array.get(liqs, i)
if L.active
line.set_x2(L.ln, bar_index)
if showZones
box.set_right(L.zn, bar_index)
if L.isHigh
if L.state == 0
if high > L.price
if close <= L.price
evBslGrab := true
L.active := false
L.state := 2
f_end(L, bar_index, colBSL, keepSwept, showZones)
if showGrab
f_lbl(bar_index, high, "BSL Grab", true, colBSL)
else
L.state := 1
L.brokeBar := bar_index
else if L.state == 1
if close < L.price
evFakeUp := true
L.active := false
L.state := 2
f_end(L, bar_index, colFake, keepSwept, showZones)
if showFake
f_lbl(bar_index, high, "Fake Breakout", true, colFake)
else if bar_index - L.brokeBar >= fakeBars
L.active := false
L.state := 3
f_end(L, L.brokeBar, colBSL, keepSwept, showZones)
else
if L.state == 0
if low < L.price
if close >= L.price
evSslGrab := true
L.active := false
L.state := 2
f_end(L, bar_index, colSSL, keepSwept, showZones)
if showGrab
f_lbl(bar_index, low, "SSL Grab", false, colSSL)
else
L.state := 1
L.brokeBar := bar_index
else if L.state == 1
if close > L.price
evFakeDn := true
L.active := false
L.state := 2
f_end(L, bar_index, colFake, keepSwept, showZones)
if showFake
f_lbl(bar_index, low, "Fake Breakdown", false, colFake)
else if bar_index - L.brokeBar >= fakeBars
L.active := false
L.state := 3
f_end(L, L.brokeBar, colSSL, keepSwept, showZones)
// event memory (sentiment / behaviour)
if evBslGrab
lastEvBar := bar_index
lastEvDir := -1
lastEvTxt := "BSL Grab"
lastEvDesc := "Highs ke upar stops hunt hue, price reject -> bearish reversal ka chance"
if evSslGrab
lastEvBar := bar_index
lastEvDir := 1
lastEvTxt := "SSL Grab"
lastEvDesc := "Lows ke neeche stops hunt hue, price reclaim -> bullish reversal ka chance"
if evFakeUp
lastEvBar := bar_index
lastEvDir := -1
lastEvTxt := "Fake Breakout"
lastEvDesc := "Breakout trap, longs fase -> bearish bias"
if evFakeDn
lastEvBar := bar_index
lastEvDir := 1
lastEvTxt := "Fake Breakdown"
lastEvDesc := "Breakdown trap, shorts fase -> bullish bias"
// ---------------- 4) Displacement ----------------
if dispUp
lastDispBar := bar_index
lastDispDir := 1
if dispDn
lastDispBar := bar_index
lastDispDir := -1
barcolor(showDisp and dispUp ? color.aqua : showDisp and dispDn ? color.fuchsia : na)
plotshape(showDisp and dispUp, "Displacement Up", shape.diamond, location.belowbar, color.aqua, size=size.tiny, text="Disp")
plotshape(showDisp and dispDn, "Displacement Down", shape.diamond, location.abovebar, color.fuchsia, size=size.tiny, text="Disp")
// ---------------- 5) Fair Value Gaps ----------------
if showFVG and bar_index >= 2
bool midBull = close[1] > open[1]
bool midBear = close[1] < open[1]
bool midDisp = math.abs(close[1] - open[1]) > atrPrev * dispMult
bool okDisp = (not fvgDispOnly) or midDisp
float gapUp = low - high[2]
float gapDn = low[2] - high
if gapUp > atrv * fvgMin and midBull and okDisp
box b = box.new(bar_index - 2, low, bar_index, high[2], border_color=na, bgcolor=color.new(colBull, 78),
text="FVG", text_size=size.tiny, text_color=colBull, text_halign=text.align_right)
array.push(fvgBoxes, b)
array.push(fvgBull, true)
evFvgBull := true
if gapDn > atrv * fvgMin and midBear and okDisp
box b = box.new(bar_index - 2, low[2], bar_index, high, border_color=na, bgcolor=color.new(colBear, 78),
text="FVG", text_size=size.tiny, text_color=colBear, text_halign=text.align_right)
array.push(fvgBoxes, b)
array.push(fvgBull, false)
evFvgBear := true
if array.size(fvgBoxes) > fvgMax
box.delete(array.shift(fvgBoxes))
array.shift(fvgBull)
int nf = array.size(fvgBoxes)
if nf > 0
for i = nf - 1 to 0
box b = array.get(fvgBoxes, i)
bool bu = array.get(fvgBull, i)
float fTop = box.get_top(b)
float fBot = box.get_bottom(b)
bool mit = bu ? close < fBot : close > fTop
if mit
if hideMit
box.delete(b)
else
box.set_right(b, bar_index)
box.set_bgcolor(b, color.new(color.gray, 92))
array.remove(fvgBoxes, i)
array.remove(fvgBull, i)
else
box.set_right(b, bar_index)
// ---------------- 6) Order Blocks ----------------
if showOB and bar_index > obLookback + 1
if dispUp and close > hh[1]
int idx = -1
for i = 1 to obLookback
if close[i] < open[i]
idx := i
break
if idx > 0
int cBar = bar_index - idx
if not array.includes(obBars, cBar)
box ob = box.new(cBar, high[idx], bar_index, low[idx], border_color=color.new(colBull, 40), bgcolor=color.new(colBull, 85),
text="Bull OB", text_size=size.tiny, text_color=colBull, text_halign=text.align_right)
array.push(obs, ob)
array.push(obBull, true)
array.push(obBars, cBar)
evObBull := true
if dispDn and close < ll[1]
int idx = -1
for i = 1 to obLookback
if close[i] > open[i]
idx := i
break
if idx > 0
int cBar = bar_index - idx
if not array.includes(obBars, cBar)
box ob = box.new(cBar, high[idx], bar_index, low[idx], border_color=color.new(colBear, 40), bgcolor=color.new(colBear, 85),
text="Bear OB", text_size=size.tiny, text_color=colBear, text_halign=text.align_right)
array.push(obs, ob)
array.push(obBull, false)
array.push(obBars, cBar)
evObBear := true
if array.size(obs) > obMax
box.delete(array.shift(obs))
array.shift(obBull)
array.shift(obBars)
int no = array.size(obs)
if no > 0
for i = no - 1 to 0
box b = array.get(obs, i)
bool bu = array.get(obBull, i)
float oTop = box.get_top(b)
float oBot = box.get_bottom(b)
bool inv = bu ? close < oBot : close > oTop
if inv
if hideMit
box.delete(b)
else
box.set_right(b, bar_index)
box.set_bgcolor(b, color.new(color.gray, 92))
array.remove(obs, i)
array.remove(obBull, i)
array.remove(obBars, i)
else
box.set_right(b, bar_index)
// ---------------- 7) Sentiment panel ----------------
var table tb = table.new(
tblPosStr == "Top Right" ? position.top_right : tblPosStr == "Top Left" ? position.top_left : tblPosStr == "Bottom Right" ? position.bottom_right : position.bottom_left,
2, 9, border_width=1, frame_color=color.gray, frame_width=1)
if showTable and barstate.islast
float nearBSL = na
float nearSSL = na
int nB = 0
int nS = 0
int lsz = array.size(liqs)
if lsz > 0
for i = 0 to lsz - 1
Liq L = array.get(liqs, i)
if L.active
if L.isHigh
nB += 1
if L.price > close and (na(nearBSL) or L.price < nearBSL)
nearBSL := L.price
else
nS += 1
if L.price < close and (na(nearSSL) or L.price > nearSSL)
nearSSL := L.price
int fb = 0
int fs = 0
int fsz = array.size(fvgBull)
if fsz > 0
for i = 0 to fsz - 1
if array.get(fvgBull, i)
fb += 1
else
fs += 1
int ob1 = 0
int ob2 = 0
int osz = array.size(obBull)
if osz > 0
for i = 0 to osz - 1
if array.get(obBull, i)
ob1 += 1
else
ob2 += 1
int sc = trend * 2 + (close > ema50 ? 1 : -1)
if not na(lastEvBar) and bar_index - lastEvBar <= sentLook
sc += lastEvDir * 2
if not na(lastDispBar) and bar_index - lastDispBar <= sentLook
sc += lastDispDir
sc += fb > fs ? 1 : fb < fs ? -1 : 0
string sentTxt = sc >= 3 ? "BULLISH" : sc <= -3 ? "BEARISH" : "NEUTRAL / RANGE"
color sentCol = sc >= 3 ? color.lime : sc <= -3 ? color.red : color.yellow
string trTxt = trend == 1 ? "Bullish (HH/HL)" : trend == -1 ? "Bearish (LH/LL)" : "Undefined"
color trCol = trend == 1 ? color.lime : trend == -1 ? color.red : color.gray
string evTxt = na(lastEvBar) ? "None" : lastEvTxt + " (" + str.tostring(bar_index - lastEvBar) + " bars ago)"
string behTxt = na(lastEvBar) ? "-" : lastEvDesc
string bslTxt = na(nearBSL) ? "-" : str.tostring(nearBSL, format.mintick) + " (+" + str.tostring((nearBSL - close) / close * 100, "#.##") + "%)"
string sslTxt = na(nearSSL) ? "-" : str.tostring(nearSSL, format.mintick) + " (-" + str.tostring((close - nearSSL) / close * 100, "#.##") + "%)"
table.cell(tb, 0, 0, "SMC Liquidity Suite", text_color=color.white, bgcolor=color.new(color.blue, 30), text_halign=text.align_left, text_size=size.small)
table.cell(tb, 1, 0, "", bgcolor=color.new(color.blue, 30))
f_row(tb, 1, "Structure", trTxt, trCol)
f_row(tb, 2, "Sentiment (" + str.tostring(sc) + ")", sentTxt, sentCol)
f_row(tb, 3, "Last liquidity event", evTxt, color.white)
f_row(tb, 4, "Behaviour", behTxt, color.white)
f_row(tb, 5, "Nearest BSL ^", bslTxt, colBSL)
f_row(tb, 6, "Nearest SSL v", sslTxt, colSSL)
f_row(tb, 7, "Open FVG (bull/bear)", str.tostring(fb) + " / " + str.tostring(fs), color.white)
f_row(tb, 8, "Active OB (bull/bear)", str.tostring(ob1) + " / " + str.tostring(ob2), color.white)
// ---------------- Alerts ----------------
alertcondition(evBslGrab, "BSL Grab", "Buy-side liquidity grab on {{ticker}} {{interval}}")
alertcondition(evSslGrab, "SSL Grab", "Sell-side liquidity grab on {{ticker}} {{interval}}")
alertcondition(evFakeUp, "Fake Breakout", "Fake breakout (trap) on {{ticker}} {{interval}}")
alertcondition(evFakeDn, "Fake Breakdown", "Fake breakdown (trap) on {{ticker}} {{interval}}")
alertcondition(evBosUp or evChochUp, "Bullish BOS/CHoCH", "Bullish structure break on {{ticker}} {{interval}}")
alertcondition(evBosDn or evChochDn, "Bearish BOS/CHoCH", "Bearish structure break on {{ticker}} {{interval}}")
alertcondition(evObBull, "Bullish OB formed", "Bullish order block on {{ticker}} {{interval}}")
alertcondition(evObBear, "Bearish OB formed", "Bearish order block on {{ticker}} {{interval}}")
alertcondition(evFvgBull, "Bullish FVG", "Bullish FVG on {{ticker}} {{interval}}")
alertcondition(evFvgBear, "Bearish FVG", "Bearish FVG on {{ticker}} {{interval}}")