本页源码来自 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/
// © PeterSetups
//@version=6
indicator("Professional SMC Ultimate | Gold & Forex", overlay=true, max_labels_count=500, max_lines_count=300, max_boxes_count=100)
// ==========================================
// INPUTS
// ==========================================
groupSMC = "Smart Money Settings"
pivotLen = input.int(5, "Swing Pivot Length", minval=2, group=groupSMC)
sweepWindow = input.int(15, "Sweep Validity Bars", minval=1, group=groupSMC)
showStructure = input.bool(true, "Show BOS / CHoCH", group=groupSMC)
showSwings = input.bool(true, "Show HH / HL / LH / LL", group=groupSMC)
showZones = input.bool(true, "Show Order Blocks & FVG", group=groupSMC)
groupTrend = "Trend Filters"
useHTF = input.bool(true, "Use 4H + 1H Trend", group=groupTrend)
useRSI = input.bool(true, "Use RSI Confirmation", group=groupTrend)
useEMA = input.bool(true, "Use 15M EMA Filter", group=groupTrend)
rsiLen = input.int(14, "RSI Length", group=groupTrend)
groupRisk = "Risk Management"
atrLen = input.int(14, "ATR Length", group=groupRisk)
atrBuffer = input.float(0.2, "ATR Stop Buffer", step=0.1, group=groupRisk)
rr1 = input.float(2.0, "TP1 Risk/Reward", step=0.5, group=groupRisk)
rr2 = input.float(3.0, "TP2 Risk/Reward", step=0.5, group=groupRisk)
showLevels = input.bool(true, "Show Entry / SL / TP", group=groupRisk)
// ==========================================
// INDICATORS
// ==========================================
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
rsi = ta.rsi(close, rsiLen)
atr = ta.atr(atrLen)
plot(ema50, "EMA 50", color=color.orange, linewidth=2)
plot(ema200, "EMA 200", color=color.blue, linewidth=2)
// Confirmed higher timeframe trends
h4Bull = request.security(syminfo.tickerid, "240", ta.ema(close, 50) > ta.ema(close, 200), lookahead=barmerge.lookahead_off)
h1Bull = request.security(syminfo.tickerid, "60", ta.ema(close, 50) > ta.ema(close, 200), lookahead=barmerge.lookahead_off)
bullTrend = not useHTF or (h4Bull and h1Bull)
bearTrend = not useHTF or (not h4Bull and not h1Bull)
bullMomentum = not useRSI or rsi > 50
bearMomentum = not useRSI or rsi < 50
bullEMA = not useEMA or close > ema50
bearEMA = not useEMA or close < ema50
// ==========================================
// SWING STRUCTURE
// ==========================================
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
var float swingHigh = na
var float swingLow = na
var float previousHigh = na
var float previousLow = na
var int structureDir = 0
if not na(ph)
previousHigh := swingHigh
swingHigh := ph
if showSwings
string highText = na(previousHigh) ? "SH" : ph > previousHigh ? "HH" : "LH"
label.new(bar_index-pivotLen, ph, highText, style=label.style_label_down, color=color.new(color.red, 20), textcolor=color.white, size=size.tiny)
if not na(pl)
previousLow := swingLow
swingLow := pl
if showSwings
string lowText = na(previousLow) ? "SL" : pl > previousLow ? "HL" : "LL"
label.new(bar_index-pivotLen, pl, lowText, style=label.style_label_up, color=color.new(color.teal, 15), textcolor=color.white, size=size.tiny)
// ==========================================
// BOS AND CHoCH
// ==========================================
bullBreak = not na(swingHigh) and ta.crossover(close, swingHigh)
bearBreak = not na(swingLow) and ta.crossunder(close, swingLow)
bullCHoCH = bullBreak and structureDir == -1
bearCHoCH = bearBreak and structureDir == 1
bullBOS = bullBreak and structureDir != -1
bearBOS = bearBreak and structureDir != 1
if bullBreak
structureDir := 1
if bearBreak
structureDir := -1
if showStructure and bullBreak
label.new(bar_index, low, bullCHoCH ? "CHoCH ↑" : "BOS ↑", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)
if showStructure and bearBreak
label.new(bar_index, high, bearCHoCH ? "CHoCH ↓" : "BOS ↓", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)
// ==========================================
// LIQUIDITY SWEEPS
// ==========================================
bullSweep = not na(swingLow) and low < swingLow and close > swingLow
bearSweep = not na(swingHigh) and high > swingHigh and close < swingHigh
var int bullSweepBar = na
var int bearSweepBar = na
var float bullSweepLow = na
var float bearSweepHigh = na
if bullSweep
bullSweepBar := bar_index
bullSweepLow := low
label.new(bar_index, low, "SELL-SIDE\nLIQUIDITY", style=label.style_label_up, color=color.teal, textcolor=color.white, size=size.tiny)
if bearSweep
bearSweepBar := bar_index
bearSweepHigh := high
label.new(bar_index, high, "BUY-SIDE\nLIQUIDITY", style=label.style_label_down, color=color.maroon, textcolor=color.white, size=size.tiny)
bullPending = not na(bullSweepBar) and bar_index - bullSweepBar <= sweepWindow
bearPending = not na(bearSweepBar) and bar_index - bearSweepBar <= sweepWindow
if not na(bullSweepBar) and bar_index - bullSweepBar > sweepWindow
bullSweepBar := na
bullSweepLow := na
if not na(bearSweepBar) and bar_index - bearSweepBar > sweepWindow
bearSweepBar := na
bearSweepHigh := na
// ==========================================
// FAIR VALUE GAPS
// ==========================================
bullFVG = low > high[2]
bearFVG = high < low[2]
var box bullGapBox = na
var box bearGapBox = na
if showZones and bullFVG
if not na(bullGapBox)
box.delete(bullGapBox)
bullGapBox := box.new(bar_index-2, low, bar_index+20, high[2], border_color=color.teal, bgcolor=color.new(color.teal, 87))
if showZones and bearFVG
if not na(bearGapBox)
box.delete(bearGapBox)
bearGapBox := box.new(bar_index-2, low[2], bar_index+20, high, border_color=color.red, bgcolor=color.new(color.red, 87))
// ==========================================
// ORDER BLOCK APPROXIMATION
// Last opposite candle before structure break
// ==========================================
var box bullOB = na
var box bearOB = na
if showZones and bullBreak and close[1] < open[1]
if not na(bullOB)
box.delete(bullOB)
bullOB := box.new(bar_index-1, high[1], bar_index+30, low[1], border_color=color.green, bgcolor=color.new(color.green, 88))
if showZones and bearBreak and close[1] > open[1]
if not na(bearOB)
box.delete(bearOB)
bearOB := box.new(bar_index-1, high[1], bar_index+30, low[1], border_color=color.red, bgcolor=color.new(color.red, 88))
// ==========================================
// BUY AND SELL SIGNALS
// ==========================================
buySetup = bullPending and bullBreak and bullTrend and bullMomentum and bullEMA
sellSetup = bearPending and bearBreak and bearTrend and bearMomentum and bearEMA
buySignal = barstate.isconfirmed and buySetup
sellSignal = barstate.isconfirmed and sellSetup
// ==========================================
// ENTRY, STOP LOSS AND TARGETS
// ==========================================
var float entryPrice = na
var float stopPrice = na
var float target1 = na
var float target2 = na
var int tradeDirection = 0
if buySignal and not na(bullSweepLow)
entryPrice := close
stopPrice := bullSweepLow - atr * atrBuffer
float risk = entryPrice - stopPrice
if risk > syminfo.mintick
target1 := entryPrice + risk * rr1
target2 := entryPrice + risk * rr2
tradeDirection := 1
label.new(bar_index, low, "BUY\n" + str.tostring(entryPrice, format.mintick), style=label.style_label_up, color=color.lime, textcolor=color.black, size=size.normal)
bullSweepBar := na
bullSweepLow := na
if sellSignal and not na(bearSweepHigh)
entryPrice := close
stopPrice := bearSweepHigh + atr * atrBuffer
float risk = stopPrice - entryPrice
if risk > syminfo.mintick
target1 := entryPrice - risk * rr1
target2 := entryPrice - risk * rr2
tradeDirection := -1
label.new(bar_index, high, "SELL\n" + str.tostring(entryPrice, format.mintick), style=label.style_label_down, color=color.red, textcolor=color.white, size=size.normal)
bearSweepBar := na
bearSweepHigh := na
// ==========================================
// TRADE LEVELS
// ==========================================
plot(showLevels and tradeDirection != 0 ? entryPrice : na, "Entry", color=color.blue, linewidth=2, style=plot.style_linebr)
plot(showLevels and tradeDirection != 0 ? stopPrice : na, "Stop Loss", color=color.red, linewidth=2, style=plot.style_linebr)
plot(showLevels and tradeDirection != 0 ? target1 : na, "TP1", color=color.green, linewidth=2, style=plot.style_linebr)
plot(showLevels and tradeDirection != 0 ? target2 : na, "TP2", color=color.lime, linewidth=2, style=plot.style_linebr)
plotshape(buySignal, title="BUY Signal", style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.small, text="BUY")
plotshape(sellSignal, title="SELL Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text="SELL")
// ==========================================
// ALERTS
// ==========================================
alertcondition(buySignal, "SMC BUY", "Professional SMC BUY signal confirmed")
alertcondition(sellSignal, "SMC SELL", "Professional SMC SELL signal confirmed")
alertcondition(bullCHoCH, "Bullish CHoCH", "Bullish Change of Character")
alertcondition(bearCHoCH, "Bearish CHoCH", "Bearish Change of Character")
// ==========================================
// STRUCTURE DASHBOARD
// ==========================================
var table dash = table.new(position.top_right, 2, 6, border_width=1)
if barstate.islast
table.cell(dash, 0, 0, "SMC ULTIMATE", bgcolor=color.black, text_color=color.yellow)
table.cell(dash, 1, 0, "STATUS", bgcolor=color.black, text_color=color.yellow)
table.cell(dash, 0, 1, "4H Trend")
table.cell(dash, 1, 1, h4Bull ? "BULLISH" : "BEARISH", bgcolor=h4Bull ? color.green : color.red, text_color=color.white)
table.cell(dash, 0, 2, "1H Trend")
table.cell(dash, 1, 2, h1Bull ? "BULLISH" : "BEARISH", bgcolor=h1Bull ? color.green : color.red, text_color=color.white)
table.cell(dash, 0, 3, "15M Structure")
table.cell(dash, 1, 3, structureDir == 1 ? "BULLISH" : structureDir == -1 ? "BEARISH" : "NEUTRAL", bgcolor=structureDir == 1 ? color.green : structureDir == -1 ? color.red : color.gray, text_color=color.white)
table.cell(dash, 0, 4, "RSI 14")
table.cell(dash, 1, 4, str.tostring(rsi, "#.0"))
table.cell(dash, 0, 5, "ATR 14")
table.cell(dash, 1, 5, str.tostring(atr, format.mintick))