ICT SMC Liquidity Master Pro

Mr_Davidd7 · study · 320 行 · 点赞 713 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// Original implementation based on ICT / SMC concepts.
// Not affiliated with or endorsed by LuxAlgo.
// Educational use. Respect the source code license of any derivative work.
 
indicator("ICT SMC Liquidity Master Pro", shorttitle="ICT SMC Master", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=300)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
gStructure = "Market Structure"
swingLen = input.int(10, "Swing Length", minval=3, group=gStructure)
internalLen = input.int(3, "Internal Length", minval=2, group=gStructure)
showBOS = input.bool(true, "Show bos", group=gStructure)
showCHoCH = input.bool(true, "Show choch", group=gStructure)
showInternal = input.bool(true, "Show Internal Structure", group=gStructure)
history = input.int(80, "Historical Events", minval=10, maxval=200, group=gStructure)
 
gLiquidity = "Liquidity"
showERL = input.bool(true, "Show erl", group=gLiquidity)
showIRL = input.bool(true, "Show irl", group=gLiquidity)
showSweeps = input.bool(true, "Show Liquidity Sweeps", group=gLiquidity)
showEqual = input.bool(true, "Show EQH / EQL", group=gLiquidity)
 
gZones = "Zones"
showOB = input.bool(true, "Show Order Blocks", group=gZones)
showFVG = input.bool(true, "Show Fair Value Gaps", group=gZones)
zoneHistory = input.int(8, "Number of Active Zones", minval=1, maxval=30, group=gZones)
extendZones = input.int(30, "Zone Extension", minval=5, maxval=200, group=gZones)
 
gDisplay = "Display"
showDashboard = input.bool(true, "Show Dashboard", group=gDisplay)
bullColor = input.color(color.rgb(8,153,129), "Bullish Color", group=gDisplay)
bearColor = input.color(color.rgb(242,54,69), "Bearish Color", group=gDisplay)
internalColor = input.color(color.rgb(220,155,55), "Internal Color", group=gDisplay)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// STORAGE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var array<line> structureLines = array.new_line()
var array<label> structureLabels = array.new_label()
var array<label> sweepLabels = array.new_label()
var array<line> liquidityLines = array.new_line()
var array<label> liquidityLabels = array.new_label()
var array<box> obBoxes = array.new_box()
var array<box> fvgBoxes = array.new_box()
 
// Keep historical objects within user-selected limit.
f_addStructure(line ln, label lb) =>
    array.push(structureLines, ln)
    array.push(structureLabels, lb)
    if array.size(structureLines) > history
        line.delete(array.shift(structureLines))
        label.delete(array.shift(structureLabels))
 
f_addSweep(label lb) =>
    array.push(sweepLabels, lb)
    if array.size(sweepLabels) > history
        label.delete(array.shift(sweepLabels))
 
f_addLiquidity(line ln, label lb) =>
    array.push(liquidityLines, ln)
    array.push(liquidityLabels, lb)
    if array.size(liquidityLines) > history
        line.delete(array.shift(liquidityLines))
        label.delete(array.shift(liquidityLabels))
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SWING AND INTERNAL PIVOTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
swingPH = ta.pivothigh(high, swingLen, swingLen)
swingPL = ta.pivotlow(low, swingLen, swingLen)
 
internalPH = ta.pivothigh(high, internalLen, internalLen)
internalPL = ta.pivotlow(low, internalLen, internalLen)
 
var float swingHigh = na
var float swingLow = na
var int swingHighBar = na
var int swingLowBar = na
var bool swingHighBroken = false
var bool swingLowBroken = false
 
var float intHigh = na
var float intLow = na
var int intHighBar = na
var int intLowBar = na
var bool intHighBroken = false
var bool intLowBroken = false
 
if not na(swingPH)
    swingHigh := swingPH
    swingHighBar := bar_index - swingLen
    swingHighBroken := false
 
if not na(swingPL)
    swingLow := swingPL
    swingLowBar := bar_index - swingLen
    swingLowBroken := false
 
if not na(internalPH)
    intHigh := internalPH
    intHighBar := bar_index - internalLen
    intHighBroken := false
 
if not na(internalPL)
    intLow := internalPL
    intLowBar := bar_index - internalLen
    intLowBroken := false
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ERL AND IRL LEVELS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
if showERL and not na(swingPH)
    line ln = line.new(swingHighBar, swingHigh, bar_index + 10, swingHigh, color=color.new(bearColor, 30), width=1)
    label lb = label.new(bar_index + 2, swingHigh, "erl", style=label.style_none, textcolor=bearColor, size=size.tiny)
    f_addLiquidity(ln, lb)
 
if showERL and not na(swingPL)
    line ln = line.new(swingLowBar, swingLow, bar_index + 10, swingLow, color=color.new(bullColor, 30), width=1)
    label lb = label.new(bar_index + 2, swingLow, "erl", style=label.style_none, textcolor=bullColor, size=size.tiny)
    f_addLiquidity(ln, lb)
 
if showIRL and not na(internalPH)
    line ln = line.new(intHighBar, intHigh, bar_index + 5, intHigh, color=color.new(internalColor, 35), style=line.style_dashed)
    label lb = label.new(bar_index + 1, intHigh, "irl", style=label.style_none, textcolor=internalColor, size=size.tiny)
    f_addLiquidity(ln, lb)
 
if showIRL and not na(internalPL)
    line ln = line.new(intLowBar, intLow, bar_index + 5, intLow, color=color.new(color.aqua, 35), style=line.style_dashed)
    label lb = label.new(bar_index + 1, intLow, "irl", style=label.style_none, textcolor=color.aqua, size=size.tiny)
    f_addLiquidity(ln, lb)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MARKET STRUCTURE — BOS / CHOCH
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var int swingTrend = 0
var int internalTrend = 0
 
bullSwingBreak = barstate.isconfirmed and not na(swingHigh) and close > swingHigh and not swingHighBroken
bearSwingBreak = barstate.isconfirmed and not na(swingLow) and close < swingLow and not swingLowBroken
 
bullInternalBreak = barstate.isconfirmed and not na(intHigh) and close > intHigh and not intHighBroken
bearInternalBreak = barstate.isconfirmed and not na(intLow) and close < intLow and not intLowBroken
 
// Swing bullish structure
if bullSwingBreak
    swingHighBroken := true
    bool reversal = swingTrend == -1
    string tag = reversal ? "choch" : "bos"
 
    if (reversal and showCHoCH) or (not reversal and showBOS)
        int mid = int(math.round((swingHighBar + bar_index) / 2.0))
        line ln = line.new(swingHighBar, swingHigh, bar_index, swingHigh, color=bullColor, width=1)
        label lb = label.new(mid, swingHigh + ta.atr(14) * 0.12, tag, style=label.style_none, textcolor=bullColor, size=size.small)
        f_addStructure(ln, lb)
 
    swingTrend := 1
 
// Swing bearish structure
if bearSwingBreak
    swingLowBroken := true
    bool reversal = swingTrend == 1
    string tag = reversal ? "choch" : "bos"
 
    if (reversal and showCHoCH) or (not reversal and showBOS)
        int mid = int(math.round((swingLowBar + bar_index) / 2.0))
        line ln = line.new(swingLowBar, swingLow, bar_index, swingLow, color=bearColor, width=1)
        label lb = label.new(mid, swingLow - ta.atr(14) * 0.12, tag, style=label.style_none, textcolor=bearColor, size=size.small)
        f_addStructure(ln, lb)
 
    swingTrend := -1
 
// Internal structure
if showInternal and bullInternalBreak
    intHighBroken := true
    bool reversal = internalTrend == -1
    string tag = reversal ? "choch" : "bos"
 
    int mid = int(math.round((intHighBar + bar_index) / 2.0))
    line ln = line.new(intHighBar, intHigh, bar_index, intHigh, color=color.new(bullColor, 45), style=line.style_dashed)
    label lb = label.new(mid, intHigh + ta.atr(14) * 0.22, tag, style=label.style_none, textcolor=bullColor, size=size.tiny)
    f_addStructure(ln, lb)
 
    internalTrend := 1
 
if showInternal and bearInternalBreak
    intLowBroken := true
    bool reversal = internalTrend == 1
    string tag = reversal ? "choch" : "bos"
 
    int mid = int(math.round((intLowBar + bar_index) / 2.0))
    line ln = line.new(intLowBar, intLow, bar_index, intLow, color=color.new(bearColor, 45), style=line.style_dashed)
    label lb = label.new(mid, intLow - ta.atr(14) * 0.22, tag, style=label.style_none, textcolor=bearColor, size=size.tiny)
    f_addStructure(ln, lb)
 
    internalTrend := -1
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIQUIDITY SWEEPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
erlBuySweep = barstate.isconfirmed and not na(swingHigh) and high > swingHigh and close < swingHigh
erlSellSweep = barstate.isconfirmed and not na(swingLow) and low < swingLow and close > swingLow
 
irlBuySweep = barstate.isconfirmed and not na(intHigh) and high > intHigh and close < intHigh
irlSellSweep = barstate.isconfirmed and not na(intLow) and low < intLow and close > intLow
 
if showSweeps and erlBuySweep
    label lb = label.new(bar_index, high + ta.atr(14) * 0.15, "erl sweep", style=label.style_none, textcolor=bearColor, size=size.tiny)
    f_addSweep(lb)
 
if showSweeps and erlSellSweep
    label lb = label.new(bar_index, low - ta.atr(14) * 0.15, "erl sweep", style=label.style_none, textcolor=bullColor, size=size.tiny)
    f_addSweep(lb)
 
if showSweeps and irlBuySweep
    label lb = label.new(bar_index, high + ta.atr(14) * 0.30, "irl", style=label.style_none, textcolor=internalColor, size=size.tiny)
    f_addSweep(lb)
 
if showSweeps and irlSellSweep
    label lb = label.new(bar_index, low - ta.atr(14) * 0.30, "irl", style=label.style_none, textcolor=color.aqua, size=size.tiny)
    f_addSweep(lb)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// EQUAL HIGHS / EQUAL LOWS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
if showEqual and not na(swingPH) and not na(swingHigh[1])
    if math.abs(swingPH - swingHigh[1]) <= ta.atr(14) * 0.10
        label.new(bar_index - swingLen, swingPH, "eqh", style=label.style_none, textcolor=bearColor, size=size.tiny)
 
if showEqual and not na(swingPL) and not na(swingLow[1])
    if math.abs(swingPL - swingLow[1]) <= ta.atr(14) * 0.10
        label.new(bar_index - swingLen, swingPL, "eql", style=label.style_none, textcolor=bullColor, size=size.tiny)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ORDER BLOCKS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
atr = ta.atr(14)
 
if showOB and bullSwingBreak
    int found = na
    for i = 1 to 12
        if close[i] < open[i] and na(found)
            found := i
    if not na(found)
        box bx = box.new(bar_index - found, high[found], bar_index + extendZones, low[found], bgcolor=color.new(bullColor, 87), border_color=color.new(bullColor, 60))
        array.push(obBoxes, bx)
 
if showOB and bearSwingBreak
    int found = na
    for i = 1 to 12
        if close[i] > open[i] and na(found)
            found := i
    if not na(found)
        box bx = box.new(bar_index - found, high[found], bar_index + extendZones, low[found], bgcolor=color.new(bearColor, 87), border_color=color.new(bearColor, 60))
        array.push(obBoxes, bx)
 
if array.size(obBoxes) > zoneHistory
    box.delete(array.shift(obBoxes))
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// FAIR VALUE GAPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullFVG = barstate.isconfirmed and low > high[2]
bearFVG = barstate.isconfirmed and high < low[2]
 
if showFVG and bullFVG
    box bx = box.new(bar_index - 2, low, bar_index + extendZones, high[2], bgcolor=color.new(bullColor, 90), border_color=color.new(bullColor, 70))
    array.push(fvgBoxes, bx)
 
if showFVG and bearFVG
    box bx = box.new(bar_index - 2, low[2], bar_index + extendZones, high, bgcolor=color.new(bearColor, 90), border_color=color.new(bearColor, 70))
    array.push(fvgBoxes, bx)
 
if array.size(fvgBoxes) > zoneHistory
    box.delete(array.shift(fvgBoxes))
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var table dash = table.new(position.top_right, 2, 4, border_width=1)
 
trendText = swingTrend == 1 ? "bullish" : swingTrend == -1 ? "bearish" : "neutral"
internalText = internalTrend == 1 ? "bullish" : internalTrend == -1 ? "bearish" : "neutral"
 
if barstate.islast and showDashboard
    table.cell(dash, 0, 0, "ict smc master", bgcolor=color.rgb(30,38,48), text_color=color.white)
    table.cell(dash, 1, 0, "pro", bgcolor=color.rgb(30,38,48), text_color=color.aqua)
    table.cell(dash, 0, 1, "swing trend", text_color=color.white)
    table.cell(dash, 1, 1, trendText, text_color=swingTrend == 1 ? bullColor : swingTrend == -1 ? bearColor : color.gray)
    table.cell(dash, 0, 2, "internal trend", text_color=color.white)
    table.cell(dash, 1, 2, internalText, text_color=internalTrend == 1 ? bullColor : internalTrend == -1 ? bearColor : color.gray)
    table.cell(dash, 0, 3, "last price", text_color=color.white)
    table.cell(dash, 1, 3, str.tostring(close, format.mintick), text_color=color.white)
 
if barstate.islast and not showDashboard
    table.clear(dash, 0, 0, 1, 3)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
alertcondition(bullSwingBreak, "bullish structure break", "Bullish swing BOS / CHoCH")
alertcondition(bearSwingBreak, "bearish structure break", "Bearish swing BOS / CHoCH")
alertcondition(erlBuySweep, "erl buy-side sweep", "External buy-side liquidity swept")
alertcondition(erlSellSweep, "erl sell-side sweep", "External sell-side liquidity swept")
alertcondition(irlBuySweep, "irl buy-side sweep", "Internal buy-side liquidity swept")
alertcondition(irlSellSweep, "irl sell-side sweep", "Internal sell-side liquidity swept")
alertcondition(bullFVG, "bullish fvg", "Bullish Fair Value Gap formed")
alertcondition(bearFVG, "bearish fvg", "Bearish Fair Value Gap formed")

← 返回列表