Code: Select all
//@version=5
indicator("ICT Silver Bullet - Sweeps & FVGs", overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500)
// --- 1. User Inputs ---
sb_time = input.session("1000-1100", title="Silver Bullet Time Window")
tz = input.string("America/New_York", title="Timezone")
box_length = input.int(5, title="Extend FVG Boxes (Bars)")
// Pivot inputs dictate how "major" the swing high/low needs to be.
// 5 left / 2 right is a fast, responsive setting for 1m/5m scalping.
pivot_left = input.int(5, title="Swing High/Low Lookback (Left)")
pivot_right = input.int(2, title="Swing High/Low Lookahead (Right)")
// --- 2. Time Window Logic ---
in_window = not na(time(timeframe.period, sb_time, tz))
bgcolor(in_window ? color.new(color.blue, 90) : na, title="Silver Bullet Background")
// --- 3. Liquidity Pools (Swing Highs / Lows) ---
// Identify pivot points
ph = ta.pivothigh(high, pivot_left, pivot_right)
pl = ta.pivotlow(low, pivot_left, pivot_right)
// Track the most recent pivot levels and their lines
var float last_ph = na
var float last_pl = na
var line active_ph_line = na
var line active_pl_line = na
var bool ph_swept = false
var bool pl_swept = false
// When a new Swing High forms, draw a dashed line forward
if not na(ph)
last_ph := ph
ph_swept := false
active_ph_line := line.new(x1=bar_index[pivot_right], y1=last_ph, x2=bar_index, y2=last_ph, color=color.new(color.red, 40), style=line.style_dashed, width=1)
// When a new Swing Low forms, draw a dashed line forward
if not na(pl)
last_pl := pl
pl_swept := false
active_pl_line := line.new(x1=bar_index[pivot_right], y1=last_pl, x2=bar_index, y2=last_pl, color=color.new(color.green, 40), style=line.style_dashed, width=1)
// --- 4. Detect Liquidity Sweeps ---
// Extend the lines forward until price sweeps them
if not na(active_ph_line) and not ph_swept
line.set_x2(active_ph_line, bar_index)
// Buy-side liquidity sweep (Price goes above swing high)
if high > last_ph
ph_swept := true
line.set_color(active_ph_line, color.new(color.red, 0))
line.set_style(active_ph_line, line.style_solid)
line.set_width(active_ph_line, 2)
if not na(active_pl_line) and not pl_swept
line.set_x2(active_pl_line, bar_index)
// Sell-side liquidity sweep (Price goes below swing low)
if low < last_pl
pl_swept := true
line.set_color(active_pl_line, color.new(color.green, 0))
line.set_style(active_pl_line, line.style_solid)
line.set_width(active_pl_line, 2)
// --- 5. Fair Value Gap (FVG) Logic ---
bull_fvg = low > high[2] and close[1] > open[1]
bear_fvg = high < low[2] and close[1] < open[1]
// --- 6. Execution: Draw Setups inside the Window ---
if in_window
if bull_fvg
// Draw the FVG box
box.new(left=bar_index[2], top=low, right=bar_index + box_length, bottom=high[2], border_color=color.new(color.green, 50), bgcolor=color.new(color.green, 85))
// If the Sell-Side Liquidity was swept recently (within last 10 bars), flag it as a prime setup
if pl_swept and bar_index - line.get_x2(active_pl_line) <= 10
label.new(bar_index[1], low[2], text="Sweep + FVG\n(Buy)", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.tiny)
if bear_fvg
// Draw the FVG box
box.new(left=bar_index[2], top=low[2], right=bar_index + box_length, bottom=high, border_color=color.new(color.red, 50), bgcolor=color.new(color.red, 85))
// If the Buy-Side Liquidity was swept recently (within last 10 bars), flag it as a prime setup
if ph_swept and bar_index - line.get_x2(active_ph_line) <= 10
label.new(bar_index[1], high[2], text="Sweep + FVG\n(Sell)", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.tiny)