OPEN-SOURCE SCRIPT
Liquidity Sweep + FVG Entry Model

//version=5
indicator("Liquidity Sweep + FVG Entry Model", overlay = true, max_labels_count = 500, max_lines_count = 500)
// Just to confirm indicator is loaded, always plot close:
plot(close, color = color.new(color.white, 0))
// ─────────────────────────────────────────────
// PARAMETERS
// ─────────────────────────────────────────────
len = input.int(5, "Liquidity Lookback")
tpMultiplier = input.float(2.0, "TP Distance Multiplier")
// ─────────────────────────────────────────────
// LIQUIDITY SWEEP DETECTION
// ─────────────────────────────────────────────
lowestPrev = ta.lowest(low, len)
highestPrev = ta.highest(high, len)
sweepLow = low < lowestPrev and close > lowestPrev
sweepHigh = high > highestPrev and close < highestPrev
// Plot liquidity levels
plot(lowestPrev, "Liquidity Low", color = color.new(color.blue, 40), style = plot.style_line)
plot(highestPrev, "Liquidity High", color = color.new(color.red, 40), style = plot.style_line)
// ─────────────────────────────────────────────
// DISPLACEMENT DETECTION
// ─────────────────────────────────────────────
bullDisp = sweepLow and close > open and close > close[1]
bearDisp = sweepHigh and close < open and close < close[1]
// ─────────────────────────────────────────────
// FAIR VALUE GAP (FVG)
// ─────────────────────────────────────────────
bullFVG = low > high[2]
bearFVG = high < low[2]
// we’ll store the last FVG lines
var line fvgTop = na
var line fvgBottom = na
// clear old FVG lines when new one appears
if bullFVG or bearFVG
if not na(fvgTop)
line.delete(fvgTop)
if not na(fvgBottom)
line.delete(fvgBottom)
// Bullish FVG box
if bullFVG
fvgTop := line.new(bar_index[2], high[2], bar_index, high[2], extend = extend.right, color = color.new(color.green, 60))
fvgBottom := line.new(bar_index[2], low, bar_index, low, extend = extend.right, color = color.new(color.green, 60))
// Bearish FVG box
if bearFVG
fvgTop := line.new(bar_index[2], low[2], bar_index, low[2], extend = extend.right, color = color.new(color.red, 60))
fvgBottom := line.new(bar_index[2], high, bar_index, high, extend = extend.right, color = color.new(color.red, 60))
// ─────────────────────────────────────────────
// ENTRY, SL, TP CONDITIONS
// ─────────────────────────────────────────────
var line slLine = na
var line tp1Line = na
var line tp2Line = na
f_deleteLineIfExists(line_id) =>
if not na(line_id)
line.delete(line_id)
if bullDisp and bullFVG
sl = low
tp1 = close + (close - sl) * tpMultiplier
tp2 = close + (close - sl) * (tpMultiplier * 1.5)
f_deleteLineIfExists(slLine)
f_deleteLineIfExists(tp1Line)
f_deleteLineIfExists(tp2Line)
slLine := line.new(bar_index, sl, bar_index + 1, sl, extend = extend.right, color = color.red)
tp1Line := line.new(bar_index, tp1, bar_index + 1, tp1, extend = extend.right, color = color.green)
tp2Line := line.new(bar_index, tp2, bar_index + 1, tp2, extend = extend.right, color = color.green)
label.new(bar_index, close, "BUY Entry\nFVG Retest\nSL Below Sweep",
style = label.style_label_up, color = color.new(color.green, 0), textcolor = color.white)
if bearDisp and bearFVG
sl = high
tp1 = close - (sl - close) * tpMultiplier
tp2 = close - (sl - close) * (tpMultiplier * 1.5)
f_deleteLineIfExists(slLine)
f_deleteLineIfExists(tp1Line)
f_deleteLineIfExists(tp2Line)
slLine := line.new(bar_index, sl, bar_index + 1, sl, extend = extend.right, color = color.red)
tp1Line := line.new(bar_index, tp1, bar_index + 1, tp1, extend = extend.right, color = color.green)
tp2Line := line.new(bar_index, tp2, bar_index + 1, tp2, extend = extend.right, color = color.green)
label.new(bar_index, close, "SELL Entry\nFVG Retest\nSL Above Sweep",
style = label.style_label_down, color = color.new(color.red, 0), textcolor = color.white)
indicator("Liquidity Sweep + FVG Entry Model", overlay = true, max_labels_count = 500, max_lines_count = 500)
// Just to confirm indicator is loaded, always plot close:
plot(close, color = color.new(color.white, 0))
// ─────────────────────────────────────────────
// PARAMETERS
// ─────────────────────────────────────────────
len = input.int(5, "Liquidity Lookback")
tpMultiplier = input.float(2.0, "TP Distance Multiplier")
// ─────────────────────────────────────────────
// LIQUIDITY SWEEP DETECTION
// ─────────────────────────────────────────────
lowestPrev = ta.lowest(low, len)
highestPrev = ta.highest(high, len)
sweepLow = low < lowestPrev and close > lowestPrev
sweepHigh = high > highestPrev and close < highestPrev
// Plot liquidity levels
plot(lowestPrev, "Liquidity Low", color = color.new(color.blue, 40), style = plot.style_line)
plot(highestPrev, "Liquidity High", color = color.new(color.red, 40), style = plot.style_line)
// ─────────────────────────────────────────────
// DISPLACEMENT DETECTION
// ─────────────────────────────────────────────
bullDisp = sweepLow and close > open and close > close[1]
bearDisp = sweepHigh and close < open and close < close[1]
// ─────────────────────────────────────────────
// FAIR VALUE GAP (FVG)
// ─────────────────────────────────────────────
bullFVG = low > high[2]
bearFVG = high < low[2]
// we’ll store the last FVG lines
var line fvgTop = na
var line fvgBottom = na
// clear old FVG lines when new one appears
if bullFVG or bearFVG
if not na(fvgTop)
line.delete(fvgTop)
if not na(fvgBottom)
line.delete(fvgBottom)
// Bullish FVG box
if bullFVG
fvgTop := line.new(bar_index[2], high[2], bar_index, high[2], extend = extend.right, color = color.new(color.green, 60))
fvgBottom := line.new(bar_index[2], low, bar_index, low, extend = extend.right, color = color.new(color.green, 60))
// Bearish FVG box
if bearFVG
fvgTop := line.new(bar_index[2], low[2], bar_index, low[2], extend = extend.right, color = color.new(color.red, 60))
fvgBottom := line.new(bar_index[2], high, bar_index, high, extend = extend.right, color = color.new(color.red, 60))
// ─────────────────────────────────────────────
// ENTRY, SL, TP CONDITIONS
// ─────────────────────────────────────────────
var line slLine = na
var line tp1Line = na
var line tp2Line = na
f_deleteLineIfExists(line_id) =>
if not na(line_id)
line.delete(line_id)
if bullDisp and bullFVG
sl = low
tp1 = close + (close - sl) * tpMultiplier
tp2 = close + (close - sl) * (tpMultiplier * 1.5)
f_deleteLineIfExists(slLine)
f_deleteLineIfExists(tp1Line)
f_deleteLineIfExists(tp2Line)
slLine := line.new(bar_index, sl, bar_index + 1, sl, extend = extend.right, color = color.red)
tp1Line := line.new(bar_index, tp1, bar_index + 1, tp1, extend = extend.right, color = color.green)
tp2Line := line.new(bar_index, tp2, bar_index + 1, tp2, extend = extend.right, color = color.green)
label.new(bar_index, close, "BUY Entry\nFVG Retest\nSL Below Sweep",
style = label.style_label_up, color = color.new(color.green, 0), textcolor = color.white)
if bearDisp and bearFVG
sl = high
tp1 = close - (sl - close) * tpMultiplier
tp2 = close - (sl - close) * (tpMultiplier * 1.5)
f_deleteLineIfExists(slLine)
f_deleteLineIfExists(tp1Line)
f_deleteLineIfExists(tp2Line)
slLine := line.new(bar_index, sl, bar_index + 1, sl, extend = extend.right, color = color.red)
tp1Line := line.new(bar_index, tp1, bar_index + 1, tp1, extend = extend.right, color = color.green)
tp2Line := line.new(bar_index, tp2, bar_index + 1, tp2, extend = extend.right, color = color.green)
label.new(bar_index, close, "SELL Entry\nFVG Retest\nSL Above Sweep",
style = label.style_label_down, color = color.new(color.red, 0), textcolor = color.white)
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.