本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// 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("Ultimate SMC Targets PRO [Thomas ]", overlay=true, max_lines_count=100, max_labels_count=150, max_boxes_count=50)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
groupStructure = "Market Structure"
swingLen = input.int(5, "Swing Length", minval=2, group=groupStructure)
showBOS = input.bool(true, "Show BOS", group=groupStructure)
showCHoCH = input.bool(true, "Show CHoCH", group=groupStructure)
groupLiquidity = "Liquidity Sweep"
showSweeps = input.bool(true, "Show Liquidity Sweeps", group=groupLiquidity)
sweepWindow = input.int(15, "Sweep Validity Bars", minval=1, group=groupLiquidity)
groupZones = "Order Block & FVG"
showOB = input.bool(true, "Show Order Blocks", group=groupZones)
obLookback = input.int(12, "OB Search Bars", minval=2, group=groupZones)
obExtend = input.int(30, "OB Extension", minval=5, group=groupZones)
showFVG = input.bool(true, "Show FVG", group=groupZones)
fvgExtend = input.int(20, "FVG Extension", minval=5, group=groupZones)
requireFVG = input.bool(false, "Require Recent FVG For Signal", group=groupZones)
fvgWindow = input.int(5, "FVG Validity Bars", minval=1, group=groupZones)
groupSignals = "BUY / SELL Confirmation"
atrLen = input.int(14, "ATR Length", minval=1, group=groupSignals)
minBodyATR = input.float(0.8, "Displacement Body (ATR)", minval=0.1, step=0.1, group=groupSignals)
minBodyRatio = input.float(0.55, "Minimum Candle Body Ratio", minval=0.1, maxval=1, step=0.05, group=groupSignals)
useEMA = input.bool(false, "Use EMA Trend Filter", group=groupSignals)
emaLen = input.int(200, "EMA Length", minval=1, group=groupSignals)
cooldown = input.int(10, "Signal Cooldown Bars", minval=0, group=groupSignals)
groupTargets = "Automatic Targets"
tp1RR = input.float(1.0, "TP1 ATR Multiplier", minval=0.1, step=0.1, group=groupTargets)
tp2RR = input.float(2.0, "TP2 ATR Multiplier", minval=0.1, step=0.1, group=groupTargets)
tp3RR = input.float(3.0, "TP3 ATR Multiplier", minval=0.1, step=0.1, group=groupTargets)
rightBars = input.int(15, "Right-Side Label Distance", minval=3, maxval=100, group=groupTargets)
groupDisplay = "Display"
showTargets = input.bool(true, "Show Entry & Targets", group=groupDisplay)
showDashboard = input.bool(true, "Show Dashboard", group=groupDisplay)
showEMA = input.bool(false, "Show EMA", group=groupDisplay)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atr = ta.atr(atrLen)
ema = ta.ema(close, emaLen)
candleBody = math.abs(close - open)
candleRange = math.max(high - low, syminfo.mintick)
bodyRatio = candleBody / candleRange
bullDisplacement = close > open and candleBody >= atr * minBodyATR and bodyRatio >= minBodyRatio
bearDisplacement = close < open and candleBody >= atr * minBodyATR and bodyRatio >= minBodyRatio
plot(showEMA ? ema : na, "EMA", color=color.orange, linewidth=2)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SWING STRUCTURE / BOS / CHoCH
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pivotHigh = ta.pivothigh(high, swingLen, swingLen)
pivotLow = ta.pivotlow(low, swingLen, swingLen)
var float lastSwingHigh = na
var float lastSwingLow = na
var bool highBroken = false
var bool lowBroken = false
var int marketTrend = 0
if not na(pivotHigh)
lastSwingHigh := pivotHigh
highBroken := false
if not na(pivotLow)
lastSwingLow := pivotLow
lowBroken := false
crossUp = ta.crossover(close, lastSwingHigh)
crossDown = ta.crossunder(close, lastSwingLow)
bullBOS = not na(lastSwingHigh) and crossUp and not highBroken
bearBOS = not na(lastSwingLow) and crossDown and not lowBroken
bullCHoCH = bullBOS and marketTrend == -1
bearCHoCH = bearBOS and marketTrend == 1
if bullBOS
highBroken := true
marketTrend := 1
if bearBOS
lowBroken := true
marketTrend := -1
if showBOS and bullBOS and not bullCHoCH
label.new(bar_index, high, "BOS", style=label.style_label_down, color=color.new(color.green, 10), textcolor=color.white, size=size.tiny)
if showBOS and bearBOS and not bearCHoCH
label.new(bar_index, low, "BOS", style=label.style_label_up, color=color.new(color.red, 10), textcolor=color.white, size=size.tiny)
if showCHoCH and bullCHoCH
label.new(bar_index, high, "CHoCH", style=label.style_label_down, color=color.new(color.aqua, 5), textcolor=color.black, size=size.small)
if showCHoCH and bearCHoCH
label.new(bar_index, low, "CHoCH", style=label.style_label_up, color=color.new(color.orange, 5), textcolor=color.black, size=size.small)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIQUIDITY SWEEPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullSweep = not na(lastSwingLow) and low < lastSwingLow and close > lastSwingLow
bearSweep = not na(lastSwingHigh) and high > lastSwingHigh and close < lastSwingHigh
var int bullSweepBar = na
var int bearSweepBar = na
var float bullSweepLow = na
var float bearSweepHigh = na
if bullSweep
bullSweepBar := bar_index
bullSweepLow := low
if bearSweep
bearSweepBar := bar_index
bearSweepHigh := high
bullSweepActive = not na(bullSweepBar) and bar_index - bullSweepBar <= sweepWindow
bearSweepActive = not na(bearSweepBar) and bar_index - bearSweepBar <= sweepWindow
if showSweeps and bullSweep
label.new(bar_index, low, "Sell-Side Sweep", style=label.style_label_up, color=color.new(color.teal, 5), textcolor=color.white, size=size.tiny)
if showSweeps and bearSweep
label.new(bar_index, high, "Buy-Side Sweep", style=label.style_label_down, color=color.new(color.maroon, 5), textcolor=color.white, size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// FAIR VALUE GAPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullFVG = bar_index >= 2 and low > high[2]
bearFVG = bar_index >= 2 and high < low[2]
var box bullFVGBox = na
var box bearFVGBox = na
if showFVG and bullFVG
if not na(bullFVGBox)
box.delete(bullFVGBox)
bullFVGBox := box.new(left=bar_index - 2, top=low, right=bar_index + fvgExtend, bottom=high[2], bgcolor=color.new(color.green, 88), border_color=color.new(color.green, 40), text="Bullish FVG", text_color=color.green, text_size=size.tiny)
if showFVG and bearFVG
if not na(bearFVGBox)
box.delete(bearFVGBox)
bearFVGBox := box.new(left=bar_index - 2, top=low[2], right=bar_index + fvgExtend, bottom=high, bgcolor=color.new(color.red, 88), border_color=color.new(color.red, 40), text="Bearish FVG", text_color=color.red, text_size=size.tiny)
bullFvgRecent = ta.barssince(bullFVG) <= fvgWindow
bearFvgRecent = ta.barssince(bearFVG) <= fvgWindow
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ORDER BLOCKS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box bullOBBox = na
var box bearOBBox = na
if showOB and bullBOS
bool foundBullOB = false
for i = 1 to obLookback
if not foundBullOB and close[i] < open[i]
if not na(bullOBBox)
box.delete(bullOBBox)
bullOBBox := box.new(left=bar_index - i, top=high[i], right=bar_index + obExtend, bottom=low[i], bgcolor=color.new(color.teal, 88), border_color=color.new(color.teal, 35), text="Bullish OB", text_color=color.teal, text_size=size.tiny)
foundBullOB := true
if showOB and bearBOS
bool foundBearOB = false
for i = 1 to obLookback
if not foundBearOB and close[i] > open[i]
if not na(bearOBBox)
box.delete(bearOBBox)
bearOBBox := box.new(left=bar_index - i, top=high[i], right=bar_index + obExtend, bottom=low[i], bgcolor=color.new(color.red, 89), border_color=color.new(color.red, 35), text="Bearish OB", text_color=color.red, text_size=size.tiny)
foundBearOB := true
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BUY / SELL SIGNALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
emaBullOK = not useEMA or close > ema
emaBearOK = not useEMA or close < ema
bullFvgOK = not requireFVG or bullFvgRecent
bearFvgOK = not requireFVG or bearFvgRecent
var int lastSignalBar = na
cooldownOK = na(lastSignalBar) or bar_index - lastSignalBar > cooldown
buySignal = barstate.isconfirmed and bullSweepActive and bullBOS and bullDisplacement and emaBullOK and bullFvgOK and cooldownOK
sellSignal = barstate.isconfirmed and bearSweepActive and bearBOS and bearDisplacement and emaBearOK and bearFvgOK and cooldownOK
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ENTRY + AUTO TARGETS — NO STOP LOSS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
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 string lastSignalText = "Waiting"
var float lastEntry = na
var float lastTP1 = na
var float lastTP2 = na
var float lastTP3 = na
if buySignal or sellSignal
lastSignalBar := bar_index
float entryPrice = close
float direction = buySignal ? 1.0 : -1.0
float target1 = entryPrice + direction * atr * tp1RR
float target2 = entryPrice + direction * atr * tp2RR
float target3 = entryPrice + direction * atr * tp3RR
lastEntry := entryPrice
lastTP1 := target1
lastTP2 := target2
lastTP3 := target3
lastSignalText := buySignal ? "BUY" : "SELL"
if showTargets
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)
color tradeColor = buySignal ? color.aqua : color.red
entryLine := line.new(bar_index, entryPrice, bar_index + rightBars, entryPrice, color=tradeColor, width=2)
tp1Line := line.new(bar_index, target1, bar_index + rightBars, target1, color=color.new(color.green, 5), width=1, style=line.style_dashed)
tp2Line := line.new(bar_index, target2, bar_index + rightBars, target2, color=color.new(color.green, 5), width=1, style=line.style_dashed)
tp3Line := line.new(bar_index, target3, bar_index + rightBars, target3, color=color.new(color.green, 5), width=1, style=line.style_dashed)
entryLabel := label.new(bar_index + rightBars, entryPrice, (buySignal ? "BUY ENTRY " : "SELL ENTRY ") + str.tostring(entryPrice, format.mintick), style=label.style_label_left, color=tradeColor, textcolor=color.black, size=size.small)
tp1Label := label.new(bar_index + rightBars, target1, "TP1 " + str.tostring(target1, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.small)
tp2Label := label.new(bar_index + rightBars, target2, "TP2 " + str.tostring(target2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.small)
tp3Label := label.new(bar_index + rightBars, target3, "TP3 " + str.tostring(target3, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.small)
plotshape(buySignal, title="BUY Signal", style=shape.labelup, location=location.belowbar, color=color.aqua, 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, 4, border_width=1)
if barstate.islast and showDashboard
string trendText = marketTrend == 1 ? "Bullish" : marketTrend == -1 ? "Bearish" : "Neutral"
string sweepText = bullSweepActive ? "Sell-Side Swept" : bearSweepActive ? "Buy-Side Swept" : "Waiting"
color trendColor = marketTrend == 1 ? color.green : marketTrend == -1 ? color.red : color.gray
table.cell(dashboard, 0, 0, "THOMAS SMC PRO", bgcolor=color.black, text_color=color.white)
table.cell(dashboard, 1, 0, "STATUS", bgcolor=color.black, text_color=color.white)
table.cell(dashboard, 0, 1, "Market Structure", text_color=color.white)
table.cell(dashboard, 1, 1, trendText, bgcolor=trendColor, text_color=color.white)
table.cell(dashboard, 0, 2, "Liquidity", text_color=color.white)
table.cell(dashboard, 1, 2, sweepText, text_color=color.yellow)
table.cell(dashboard, 0, 3, "Last Signal", text_color=color.white)
table.cell(dashboard, 1, 3, lastSignalText, text_color=lastSignalText == "BUY" ? color.aqua : lastSignalText == "SELL" ? color.red : color.gray)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, title="Thomas BUY", message="Thomas SMC PRO: BUY signal")
alertcondition(sellSignal, title="Thomas SELL", message="Thomas SMC PRO: SELL signal")
alertcondition(bullSweep, title="Bullish Liquidity Sweep", message="Bullish liquidity sweep detected")
alertcondition(bearSweep, title="Bearish Liquidity Sweep", message="Bearish liquidity sweep detected")
alertcondition(bullBOS, title="Bullish BOS", message="Bullish BOS detected")
alertcondition(bearBOS, title="Bearish BOS", message="Bearish BOS detected")
alertcondition(bullCHoCH, title="Bullish CHoCH", message="Bullish CHoCH detected")
alertcondition(bearCHoCH, title="Bearish CHoCH", message="Bearish CHoCH detected")