本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// =====================================================================================================
// SMC+ICT Liquidity Sweep
// =====================================================================================================
//
// ORIGINAL SCRIPT DECLARATION
// ---------------------------
// This script is an ORIGINAL work. The source code was written from scratch and is NOT copied,
// forked, re-used, translated or derived from any third-party script, library or open-source code.
// The logic (swing-based liquidity zones + sweep detection + box/label rendering) is an independent
// implementation created specifically for this indicator.
//
// AUTHOR VERIFICATION & CLARIFICATION
// -----------------------------------
// Script Name : SMC+ICT Liquidity Sweep
// Author : Michael_Fx_Trader
// Publisher : Michael_Fx_Trader
// Rights Holder : Michael_Fx_Trader
// Language/Version : Pine Script(R) v6
// Origin : 100% original implementation by the author named above.
//
// COPYRIGHT & RIGHTS
// ------------------
// (c) 2026 Michael_Fx_Trader. All Rights Reserved.
// All rights to this source code, its logic, its design and its published version belong
// exclusively to Michael_Fx_Trader. Copying, re-publishing, re-selling, re-distributing or
// claiming authorship of this code, in whole or in part, without the written permission of the
// author is strictly prohibited.
//
// WHAT THE INDICATOR DOES
// -----------------------
// 1) LIQUIDITY: Detects swing highs (buy-side liquidity) and swing lows (sell-side liquidity).
// Each one is marked with a box and the text "Liquidity". The box stays extended to the right
// until price trades through the level.
// 2) LIQUIDITY SWEEP: When price takes out a liquidity level, the liquidity box is closed at that
// candle and a new box is drawn on the sweep candle's extreme with the text "Liquidity Sweep".
// 3) Works on every timeframe and every market (Forex, Gold, Crypto, Indices, Stocks, Futures)
// because the box thickness is automatically scaled by ATR.
//
// NOTES
// -----
// - Liquidity is confirmed after "Swing Length" bars to the right (no repainting of confirmed zones).
// - All drawing/updating is done on confirmed (closed) bars only, so history and live behave the same.
// - This tool is for educational and analytical purposes only. It is not financial advice and does
// not guarantee any profit. Trading involves risk.
// =====================================================================================================
//@version=6
indicator("SMC+ICT Liquidity Sweep", shorttitle="SMC+ICT LS", overlay=true, max_boxes_count=500, max_labels_count=500)
// =====================================================================================================
// INPUTS
// =====================================================================================================
const string GRP_DET = "Liquidity Detection"
const string GRP_BOX = "Box Settings"
const string GRP_COL = "Colors & Text"
int swingLen = input.int(15, "Swing Length (left/right bars)", minval=2, maxval=100, group=GRP_DET, tooltip="Number of bars on each side used to confirm a swing high / swing low. Bigger value = fewer but stronger liquidity levels.")
string sweepMode = input.string("Wick + Close Back", "Sweep Mode", options=["Wick + Close Back", "Wick Only"], group=GRP_DET, tooltip="Wick + Close Back: price must break the level with a wick and close back inside (classic liquidity grab). If price closes beyond the level, it is treated as a breakout, not a sweep.\nWick Only: any wick through the level counts as a sweep.")
bool showHighs = input.bool(true, "Show Buy-side Liquidity (Swing Highs)", group=GRP_DET)
bool showLows = input.bool(true, "Show Sell-side Liquidity (Swing Lows)", group=GRP_DET)
int maxActive = input.int(20, "Max Active Liquidity Levels (per side)", minval=1, maxval=100, group=GRP_DET)
int maxHistory = input.int(100, "Max Stored Old Boxes", minval=10, maxval=240, group=GRP_DET, tooltip="How many old (already finished) boxes are kept on the chart.")
int atrLen = input.int(14, "ATR Length", minval=1, group=GRP_BOX)
float boxThick = input.float(0.25, "Box Thickness (x ATR)", minval=0.05, step=0.05, group=GRP_BOX, tooltip="Box height is calculated automatically as ATR x this value, so it fits every market and timeframe.")
int sweepExt = input.int(12, "Sweep Box Width (bars)", minval=2, maxval=100, group=GRP_BOX)
int borderW = input.int(1, "Border Width", minval=1, maxval=4, group=GRP_BOX)
color liqFill = input.color(#5C1A22, "Liquidity Box Fill", group=GRP_COL)
color liqBorder = input.color(#FFFFFF, "Liquidity Box Border", group=GRP_COL)
color swpFill = input.color(#5C1A22, "Sweep Box Fill", group=GRP_COL)
color swpBorder = input.color(#FFFFFF, "Sweep Box Border", group=GRP_COL)
color txtColor = input.color(#FFFFFF, "Text Color", group=GRP_COL)
string txtSize = input.string(size.small, "Text Size", options=[size.tiny, size.small, size.normal, size.large], group=GRP_COL)
string liqText = input.string("Liquidity", "Liquidity Text", group=GRP_COL)
string swpText = input.string("Liquidity Sweep", "Liquidity Sweep Text", group=GRP_COL)
// =====================================================================================================
// TYPES & STORAGE
// =====================================================================================================
type LiquidityZone
float price
int startBar
bool isHigh
float thick
box zone
label tag
var array<LiquidityZone> activeHighs = array.new<LiquidityZone>()
var array<LiquidityZone> activeLows = array.new<LiquidityZone>()
var array<box> oldBoxes = array.new<box>()
var array<label> oldLabels = array.new<label>()
// =====================================================================================================
// HELPER FUNCTIONS
// =====================================================================================================
// Creates a clear text tag. High-side tags sit above the box, low-side tags sit below the box.
f_tag(int x, float y, string txt, bool above) =>
label.new(x, y, txt, xloc.bar_index, yloc.price, color.new(color.white, 100), above ? label.style_label_down : label.style_label_up, txtColor, txtSize)
// Horizontal middle of a box (used to center the text).
f_mid(int leftBar, int rightBar) =>
int(math.round((leftBar + rightBar) / 2.0))
// Keeps the number of stored old drawings under control.
f_trim_history() =>
while oldBoxes.size() > maxHistory
box.delete(oldBoxes.shift())
while oldLabels.size() > maxHistory
label.delete(oldLabels.shift())
// Checks every active liquidity level. Extends it, or closes it when price trades through it.
// Returns true when at least one real liquidity sweep happened on this bar.
f_process(array<LiquidityZone> arr, bool isHigh) =>
bool anySweep = false
int i = arr.size() - 1
while i >= 0
LiquidityZone z = arr.get(i)
bool touched = isHigh ? high > z.price : low < z.price
// Always keep the liquidity box extended to the current bar
box.set_right(z.zone, bar_index)
label.set_x(z.tag, f_mid(z.startBar, bar_index))
if touched
bool closedBack = isHigh ? close < z.price : close > z.price
bool isSweep = sweepMode == "Wick Only" or closedBack
if isSweep
anySweep := true
// Draw the Liquidity Sweep box on the extreme of the sweep candle
float topP = isHigh ? high + z.thick : low
float botP = isHigh ? high : low - z.thick
box sb = box.new(bar_index, topP, bar_index + sweepExt, botP, border_color=swpBorder, border_width=borderW, bgcolor=swpFill)
label sl = f_tag(bar_index + int(sweepExt / 2), isHigh ? topP : botP, swpText, isHigh)
oldBoxes.push(sb)
oldLabels.push(sl)
// Liquidity level is finished (swept or broken) -> keep drawing as history
oldBoxes.push(z.zone)
oldLabels.push(z.tag)
arr.remove(i)
i -= 1
anySweep
// =====================================================================================================
// CALCULATIONS
// =====================================================================================================
float atrV = ta.atr(atrLen)
float ph = ta.pivothigh(high, swingLen, swingLen)
float pl = ta.pivotlow(low, swingLen, swingLen)
bool sweptHigh = false // buy-side liquidity swept on this bar
bool sweptLow = false // sell-side liquidity swept on this bar
if barstate.isconfirmed
float thick = math.max(nz(atrV) * boxThick, syminfo.mintick * 2)
int x1 = bar_index - swingLen
// ---- New buy-side liquidity (swing high) ----
if showHighs and not na(ph)
box b = box.new(x1, ph + thick, bar_index, ph, border_color=liqBorder, border_width=borderW, bgcolor=liqFill)
label t = f_tag(f_mid(x1, bar_index), ph + thick, liqText, true)
activeHighs.push(LiquidityZone.new(ph, x1, true, thick, b, t))
if activeHighs.size() > maxActive
LiquidityZone old = activeHighs.shift()
box.delete(old.zone)
label.delete(old.tag)
// ---- New sell-side liquidity (swing low) ----
if showLows and not na(pl)
box b = box.new(x1, pl, bar_index, pl - thick, border_color=liqBorder, border_width=borderW, bgcolor=liqFill)
label t = f_tag(f_mid(x1, bar_index), pl - thick, liqText, false)
activeLows.push(LiquidityZone.new(pl, x1, false, thick, b, t))
if activeLows.size() > maxActive
LiquidityZone old = activeLows.shift()
box.delete(old.zone)
label.delete(old.tag)
// ---- Update levels / detect sweeps ----
sweptHigh := f_process(activeHighs, true)
sweptLow := f_process(activeLows, false)
f_trim_history()
// =====================================================================================================
// ALERTS
// =====================================================================================================
alertcondition(sweptHigh, "Buy-side Liquidity Sweep", "SMC+ICT Liquidity Sweep: Buy-side liquidity (swing high) swept on {{ticker}} {{interval}}")
alertcondition(sweptLow, "Sell-side Liquidity Sweep", "SMC+ICT Liquidity Sweep: Sell-side liquidity (swing low) swept on {{ticker}} {{interval}}")
alertcondition(sweptHigh or sweptLow, "Any Liquidity Sweep", "SMC+ICT Liquidity Sweep: Liquidity swept on {{ticker}} {{interval}}")
// =====================================================================================================
// END OF SCRIPT | SMC+ICT Liquidity Sweep | Author & Publisher: Michael_Fx_Trader
// (c) 2026 Michael_Fx_Trader. All Rights Reserved. Original implementation.
// =====================================================================================================