Liquidity Expansion Radar PRO [Thomas]

Thomas-Sterling · study · 231 行 · 点赞 1,397 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Thomas-Sterling
 
 
 //@version=6
indicator("Liquidity Expansion Radar PRO [Thomas]", overlay=true, max_lines_count=20, max_labels_count=30)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
groupMain = "Main Settings"
swingLen       = input.int(5, "Swing Length", minval=2, group=groupMain)
rangeLen       = input.int(20, "Breakout Range", minval=5, group=groupMain)
emaLen         = input.int(200, "Trend EMA", minval=1, group=groupMain)
useTrendFilter = input.bool(true, "Use EMA Trend Filter", group=groupMain)
 
groupSqueeze = "Expansion Settings"
bbLen          = input.int(20, "Bollinger Length", minval=5, group=groupSqueeze)
bbMult         = input.float(2.0, "Bollinger Multiplier", minval=0.5, step=0.1, group=groupSqueeze)
squeezeLen     = input.int(50, "Squeeze Average Length", minval=10, group=groupSqueeze)
squeezeFactor  = input.float(0.80, "Squeeze Sensitivity", minval=0.1, maxval=1.5, step=0.05, group=groupSqueeze)
squeezeLookback = input.int(10, "Recent Squeeze Bars", minval=1, group=groupSqueeze)
 
groupFilter = "Confirmation Filters"
useVolumeFilter = input.bool(false, "Use Volume Confirmation", group=groupFilter)
volumeLen       = input.int(20, "Volume Average Length", minval=1, group=groupFilter)
volumeMult      = input.float(1.2, "Minimum Relative Volume", minval=0.1, step=0.1, group=groupFilter)
cooldownBars    = input.int(8, "Signal Cooldown", minval=0, group=groupFilter)
 
groupTargets = "Target Settings"
atrLen = input.int(14, "ATR Length", minval=1, group=groupTargets)
tp1ATR = input.float(1.0, "TP1 ATR Multiplier", minval=0.1, step=0.1, group=groupTargets)
tp2ATR = input.float(2.0, "TP2 ATR Multiplier", minval=0.1, step=0.1, group=groupTargets)
tp3ATR = input.float(3.0, "TP3 ATR Multiplier", minval=0.1, step=0.1, group=groupTargets)
 
groupVisual = "Visual Settings"
showEMA       = input.bool(true, "Show Trend EMA", group=groupVisual)
showStructure = input.bool(true, "Show BOS / CHoCH", group=groupVisual)
showDashboard = input.bool(true, "Show Dashboard", group=groupVisual)
showTargets   = input.bool(true, "Show Entry & Targets", group=groupVisual)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CORE CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ema = ta.ema(close, emaLen)
atr = ta.atr(atrLen)
 
bbBasis = ta.sma(close, bbLen)
bbDev   = ta.stdev(close, bbLen) * bbMult
bbUpper = bbBasis + bbDev
bbLower = bbBasis - bbDev
 
bbWidth = bbBasis != 0 ? (bbUpper - bbLower) / bbBasis : 0.0
widthAverage = ta.sma(bbWidth, squeezeLen)
inSqueeze = not na(widthAverage) and bbWidth < widthAverage * squeezeFactor
 
barsSinceSqueeze = ta.barssince(inSqueeze)
recentSqueeze = not na(barsSinceSqueeze) and barsSinceSqueeze <= squeezeLookback
 
rangeHigh = ta.highest(high, rangeLen)[1]
rangeLow  = ta.lowest(low, rangeLen)[1]
 
volumeAverage = ta.sma(volume, volumeLen)
volumeOK = not useVolumeFilter or (not na(volumeAverage) and volume > volumeAverage * volumeMult)
 
bullTrend = close > ema
bearTrend = close < ema
bullTrendOK = not useTrendFilter or bullTrend
bearTrendOK = not useTrendFilter or bearTrend
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SWING LEVELS & LIQUIDITY SWEEPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pivotHigh = ta.pivothigh(high, swingLen, swingLen)
pivotLow  = ta.pivotlow(low, swingLen, swingLen)
 
var float lastSwingHigh = na
var float lastSwingLow  = na
 
if not na(pivotHigh)
    lastSwingHigh := pivotHigh
 
if not na(pivotLow)
    lastSwingLow := pivotLow
 
bullSweep = not na(lastSwingLow) and low < lastSwingLow and close > lastSwingLow and close > open
bearSweep = not na(lastSwingHigh) and high > lastSwingHigh and close < lastSwingHigh and close < open
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// EXPANSION BREAKOUTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullBreakout = recentSqueeze and not na(rangeHigh) and close > rangeHigh and close > open
bearBreakout = recentSqueeze and not na(rangeLow) and close < rangeLow and close < open
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BOS / CHoCH STRUCTURE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullStructureBreak = not na(lastSwingHigh) and ta.crossover(close, lastSwingHigh)
bearStructureBreak = not na(lastSwingLow) and ta.crossunder(close, lastSwingLow)
 
var int structureTrend = 0
 
bullChoch = bullStructureBreak and structureTrend == -1
bearChoch = bearStructureBreak and structureTrend == 1
bullBos = bullStructureBreak and structureTrend != -1
bearBos = bearStructureBreak and structureTrend != 1
 
if bullStructureBreak
    structureTrend := 1
else if bearStructureBreak
    structureTrend := -1
 
plotshape(showStructure and bullBos, title="Bullish BOS", style=shape.labelup, location=location.belowbar, color=color.new(color.green, 10), text="BOS", textcolor=color.white, size=size.tiny)
plotshape(showStructure and bearBos, title="Bearish BOS", style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 10), text="BOS", textcolor=color.white, size=size.tiny)
plotshape(showStructure and bullChoch, title="Bullish CHoCH", style=shape.labelup, location=location.belowbar, color=color.new(color.aqua, 5), text="CHoCH", textcolor=color.black, size=size.tiny)
plotshape(showStructure and bearChoch, title="Bearish CHoCH", style=shape.labeldown, location=location.abovebar, color=color.new(color.orange, 5), text="CHoCH", textcolor=color.black, size=size.tiny)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SIGNAL CONTROL
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var int lastSignalBar = na
cooldownOK = na(lastSignalBar) or bar_index - lastSignalBar > cooldownBars
 
buySetup = (bullBreakout or bullSweep) and bullTrendOK and volumeOK
sellSetup = (bearBreakout or bearSweep) and bearTrendOK and volumeOK
 
buySignal = buySetup and cooldownOK and barstate.isconfirmed
sellSignal = sellSetup and cooldownOK and barstate.isconfirmed
 
if buySignal or sellSignal
    lastSignalBar := bar_index
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ENTRY & TARGET LEVELS — LATEST SETUP ONLY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var line entryLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
 
var label entryLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na
 
var float activeEntry = na
var float activeTP1 = na
var float activeTP2 = na
var float activeTP3 = na
var string activeDirection = "WAITING"
var string activeSetup = "No setup"
 
if buySignal or sellSignal
    if not na(entryLine)
        line.delete(entryLine)
    if not na(tp1Line)
        line.delete(tp1Line)
    if not na(tp2Line)
        line.delete(tp2Line)
    if not na(tp3Line)
        line.delete(tp3Line)
 
    if not na(entryLabel)
        label.delete(entryLabel)
    if not na(tp1Label)
        label.delete(tp1Label)
    if not na(tp2Label)
        label.delete(tp2Label)
    if not na(tp3Label)
        label.delete(tp3Label)
 
    activeEntry := close
    activeTP1 := close + (buySignal ? 1 : -1) * atr * tp1ATR
    activeTP2 := close + (buySignal ? 1 : -1) * atr * tp2ATR
    activeTP3 := close + (buySignal ? 1 : -1) * atr * tp3ATR
 
    activeDirection := buySignal ? "BUY" : "SELL"
    activeSetup := buySignal ? (bullBreakout ? "Expansion Breakout" : "Liquidity Sweep") : (bearBreakout ? "Expansion Breakout" : "Liquidity Sweep")
 
    if showTargets
        entryLine := line.new(bar_index, activeEntry, bar_index + 15, activeEntry, color=color.yellow, width=2)
        tp1Line := line.new(bar_index, activeTP1, bar_index + 15, activeTP1, color=color.lime, width=1)
        tp2Line := line.new(bar_index, activeTP2, bar_index + 15, activeTP2, color=color.lime, width=1)
        tp3Line := line.new(bar_index, activeTP3, bar_index + 15, activeTP3, color=color.lime, width=2)
 
        entryLabel := label.new(bar_index + 15, activeEntry, "ENTRY " + str.tostring(activeEntry, format.mintick), style=label.style_label_left, color=color.yellow, textcolor=color.black)
        tp1Label := label.new(bar_index + 15, activeTP1, "TP1 " + str.tostring(activeTP1, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
        tp2Label := label.new(bar_index + 15, activeTP2, "TP2 " + str.tostring(activeTP2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
        tp3Label := label.new(bar_index + 15, activeTP3, "TP3 " + str.tostring(activeTP3, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
 
plot(showEMA ? ema : na, title="Trend EMA", color=color.orange, linewidth=2)
 
plotshape(buySignal, title="BUY Signal", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.black, size=size.small)
plotshape(sellSignal, title="SELL Signal", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.small)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table dashboard = table.new(position.top_right, 2, 5, border_width=1)
 
if barstate.islast and showDashboard
    trendText = bullTrend ? "BULLISH" : bearTrend ? "BEARISH" : "NEUTRAL"
    trendColor = bullTrend ? color.green : bearTrend ? color.red : color.gray
    volatilityText = inSqueeze ? "COMPRESSION" : recentSqueeze ? "EXPANSION WINDOW" : "NORMAL"
    setupText = activeDirection + " | " + activeSetup
 
    table.cell(dashboard, 0, 0, "THOMAS RADAR", bgcolor=color.rgb(25, 35, 55), text_color=color.white)
    table.cell(dashboard, 1, 0, "PRO", bgcolor=color.rgb(25, 35, 55), text_color=color.aqua)
    table.cell(dashboard, 0, 1, "Trend", text_color=color.white, bgcolor=color.new(color.gray, 75))
    table.cell(dashboard, 1, 1, trendText, text_color=color.white, bgcolor=trendColor)
    table.cell(dashboard, 0, 2, "Volatility", text_color=color.white, bgcolor=color.new(color.gray, 75))
    table.cell(dashboard, 1, 2, volatilityText, text_color=color.white, bgcolor=color.new(color.blue, 65))
    table.cell(dashboard, 0, 3, "Last Setup", text_color=color.white, bgcolor=color.new(color.gray, 75))
    table.cell(dashboard, 1, 3, setupText, text_color=color.white, bgcolor=color.new(color.gray, 55))
    table.cell(dashboard, 0, 4, "Volume Filter", text_color=color.white, bgcolor=color.new(color.gray, 75))
    table.cell(dashboard, 1, 4, volumeOK ? "PASSED" : "WAIT", text_color=color.white, bgcolor=volumeOK ? color.green : color.gray)
 
if barstate.islast and not showDashboard
    table.clear(dashboard, 0, 0, 1, 4)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, title="Thomas Radar BUY", message="Thomas Liquidity Expansion Radar: BUY setup confirmed.")
alertcondition(sellSignal, title="Thomas Radar SELL", message="Thomas Liquidity Expansion Radar: SELL setup confirmed.")
alertcondition(bullSweep, title="Bullish Liquidity Sweep", message="Bullish liquidity sweep detected.")
alertcondition(bearSweep, title="Bearish Liquidity Sweep", message="Bearish liquidity sweep detected.")
alertcondition(bullBreakout, title="Bullish Expansion", message="Bullish expansion breakout detected.")
alertcondition(bearBreakout, title="Bearish Expansion", message="Bearish expansion breakout detected.")
alertcondition(bullChoch, title="Bullish CHoCH", message="Bullish CHoCH detected.")
alertcondition(bearChoch, title="Bearish CHoCH", message="Bearish CHoCH detected.")

← 返回列表