本页源码来自 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("SMC PRO EMA 200 + Auto Targets [Thomas-Sterling]", overlay=true, max_labels_count=300, max_lines_count=200, max_boxes_count=50)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
swingLen = input.int(5, "Swing Sensitivity", minval=2, maxval=30)
eqAtrMult = input.float(0.15, "EQH/EQL Tolerance (ATR)", minval=0.01, step=0.05)
atrLen = input.int(14, "ATR Length", minval=1)
obSearch = input.int(15, "Order Block Search Bars", minval=2, maxval=50)
zoneBars = input.int(100, "Zone Extension", minval=10, maxval=300)
showStructure = input.bool(true, "Show BOS / CHoCH")
showStrength = input.bool(true, "Show Strong / Weak High-Low")
showEqual = input.bool(true, "Show EQH / EQL")
showOB = input.bool(true, "Show Order Blocks")
showFVG = input.bool(true, "Show Fair Value Gaps")
showEMA = input.bool(true, "Show EMA 200")
filterEMA = input.bool(false, "Filter Auto Targets With EMA 200")
showTargets = input.bool(true, "Show Auto Entry / SL / TP")
showDashboard = input.bool(true, "Show Dashboard")
rr1 = input.float(1.0, "TP1 Risk:Reward", minval=0.5, step=0.5)
rr2 = input.float(2.0, "TP2 Risk:Reward", minval=1.0, step=0.5)
rr3 = input.float(3.0, "TP3 Risk:Reward", minval=1.5, step=0.5)
rightBars = input.int(15, "Target Label Distance", minval=2, maxval=100)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// EMA 200 + SWINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ema200 = ta.ema(close, 200)
plot(showEMA ? ema200 : na, "EMA 200", color=color.orange, linewidth=2)
atr = ta.atr(atrLen)
ph = ta.pivothigh(high, swingLen, swingLen)
pl = ta.pivotlow(low, swingLen, swingLen)
var float lastHigh = na
var float lastLow = na
var int lastHighBar = na
var int lastLowBar = na
var bool highBroken = false
var bool lowBroken = false
var int trend = 0
var float previousHigh = na
var float previousLow = na
if not na(ph)
previousHigh := lastHigh
lastHigh := ph
lastHighBar := bar_index - swingLen
highBroken := false
if showStrength
label.new(lastHighBar, lastHigh, "Weak High", style=label.style_label_down, color=color.new(color.red, 100), textcolor=color.red, size=size.tiny)
if not na(pl)
previousLow := lastLow
lastLow := pl
lastLowBar := bar_index - swingLen
lowBroken := false
if showStrength
label.new(lastLowBar, lastLow, "Weak Low", style=label.style_label_up, color=color.new(color.blue, 100), textcolor=color.blue, size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BOS / CHoCH
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullBreak = barstate.isconfirmed and not na(lastHigh) and not highBroken and close > lastHigh
bearBreak = barstate.isconfirmed and not na(lastLow) and not lowBroken and close < lastLow
bullCHoCH = bullBreak and trend == -1
bearCHoCH = bearBreak and trend == 1
bullBOS = bullBreak and not bullCHoCH
bearBOS = bearBreak and not bearCHoCH
if bullBreak
if showStructure
line.new(lastHighBar, lastHigh, bar_index, lastHigh, color=color.teal, width=1)
label.new(bar_index, lastHigh, bullCHoCH ? "CHoCH" : "BOS", style=label.style_label_down, color=color.new(color.white, 100), textcolor=color.teal, size=size.tiny)
highBroken := true
trend := 1
if bearBreak
if showStructure
line.new(lastLowBar, lastLow, bar_index, lastLow, color=color.red, width=1)
label.new(bar_index, lastLow, bearCHoCH ? "CHoCH" : "BOS", style=label.style_label_up, color=color.new(color.white, 100), textcolor=color.red, size=size.tiny)
lowBroken := true
trend := -1
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// EQH / EQL
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if showEqual and not na(ph) and not na(previousHigh) and math.abs(ph - previousHigh) <= atr[swingLen] * eqAtrMult
line.new(bar_index - swingLen * 2, previousHigh, bar_index - swingLen, ph, color=color.orange, style=line.style_dashed)
label.new(bar_index - swingLen, ph, "EQH", style=label.style_label_down, color=color.new(color.white, 100), textcolor=color.orange, size=size.tiny)
if showEqual and not na(pl) and not na(previousLow) and math.abs(pl - previousLow) <= atr[swingLen] * eqAtrMult
line.new(bar_index - swingLen * 2, previousLow, bar_index - swingLen, pl, color=color.aqua, style=line.style_dashed)
label.new(bar_index - swingLen, pl, "EQL", style=label.style_label_up, color=color.new(color.white, 100), textcolor=color.aqua, size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ORDER BLOCKS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box bullOB = na
var box bearOB = na
if showOB and bullBreak
int bullOffset = na
for i = 1 to obSearch
if na(bullOffset) and close[i] < open[i]
bullOffset := i
if not na(bullOffset)
if not na(bullOB)
box.delete(bullOB)
bullOB := box.new(bar_index - bullOffset, high[bullOffset], bar_index + zoneBars, low[bullOffset], bgcolor=color.new(color.blue, 86), border_color=color.new(color.blue, 40), text="Bullish OB", text_color=color.blue, text_size=size.tiny)
if showOB and bearBreak
int bearOffset = na
for i = 1 to obSearch
if na(bearOffset) and close[i] > open[i]
bearOffset := i
if not na(bearOffset)
if not na(bearOB)
box.delete(bearOB)
bearOB := box.new(bar_index - bearOffset, high[bearOffset], bar_index + zoneBars, low[bearOffset], bgcolor=color.new(color.red, 86), border_color=color.new(color.red, 40), text="Bearish OB", text_color=color.red, text_size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// FAIR VALUE GAPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullFVG = barstate.isconfirmed and bar_index >= 2 and low > high[2]
bearFVG = barstate.isconfirmed and bar_index >= 2 and high < low[2]
var box bullGapBox = na
var box bearGapBox = na
if showFVG and bullFVG
if not na(bullGapBox)
box.delete(bullGapBox)
bullGapBox := box.new(bar_index - 2, low, bar_index + zoneBars, high[2], bgcolor=color.new(color.aqua, 88), border_color=color.new(color.aqua, 45), text="Bullish FVG", text_color=color.teal, text_size=size.tiny)
if showFVG and bearFVG
if not na(bearGapBox)
box.delete(bearGapBox)
bearGapBox := box.new(bar_index - 2, low[2], bar_index + zoneBars, high, bgcolor=color.new(color.orange, 88), border_color=color.new(color.orange, 45), text="Bearish FVG", text_color=color.orange, text_size=size.tiny)
if barstate.islast
if not na(bullOB)
box.set_right(bullOB, bar_index + zoneBars)
if not na(bearOB)
box.set_right(bearOB, bar_index + zoneBars)
if not na(bullGapBox)
box.set_right(bullGapBox, bar_index + zoneBars)
if not na(bearGapBox)
box.set_right(bearGapBox, bar_index + zoneBars)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// STRONG HIGH / LOW
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var label strongLabel = na
if showStrength and (bullCHoCH or bearCHoCH)
label.delete(strongLabel)
if bullCHoCH and not na(lastLow)
strongLabel := label.new(lastLowBar, lastLow, "Strong Low", style=label.style_label_up, color=color.new(color.white, 100), textcolor=color.green, size=size.tiny)
if bearCHoCH and not na(lastHigh)
strongLabel := label.new(lastHighBar, lastHigh, "Strong High", style=label.style_label_down, color=color.new(color.white, 100), textcolor=color.red, size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// AUTO TARGETS ON BOS / CHoCH
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var float entry = na
var float sl = na
var float tp1 = na
var float tp2 = na
var float tp3 = na
var string lastSignal = "WAITING"
var line entryLine = na
var line slLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
var label entryLabel = na
var label slLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na
buyAllowed = bullBreak and (not filterEMA or close > ema200)
sellAllowed = bearBreak and (not filterEMA or close < ema200)
validBuy = buyAllowed and not na(lastLow) and close - lastLow > syminfo.mintick
validSell = sellAllowed and not na(lastHigh) and lastHigh - close > syminfo.mintick
if validBuy or validSell
entry := close
if validBuy
sl := lastLow
float buyRisk = entry - sl
tp1 := entry + buyRisk * rr1
tp2 := entry + buyRisk * rr2
tp3 := entry + buyRisk * rr3
lastSignal := "BUY"
if validSell
sl := lastHigh
float sellRisk = sl - entry
tp1 := entry - sellRisk * rr1
tp2 := entry - sellRisk * rr2
tp3 := entry - sellRisk * rr3
lastSignal := "SELL"
line.delete(entryLine)
line.delete(slLine)
line.delete(tp1Line)
line.delete(tp2Line)
line.delete(tp3Line)
label.delete(entryLabel)
label.delete(slLabel)
label.delete(tp1Label)
label.delete(tp2Label)
label.delete(tp3Label)
if showTargets
entryLine := line.new(bar_index, entry, bar_index + rightBars, entry, color=color.blue, width=2)
slLine := line.new(bar_index, sl, bar_index + rightBars, sl, color=color.red, width=2)
tp1Line := line.new(bar_index, tp1, bar_index + rightBars, tp1, color=color.lime, width=2)
tp2Line := line.new(bar_index, tp2, bar_index + rightBars, tp2, color=color.green, width=2)
tp3Line := line.new(bar_index, tp3, bar_index + rightBars, tp3, color=color.aqua, width=2)
entryLabel := label.new(bar_index + rightBars, entry, "ENTRY " + str.tostring(entry, format.mintick), style=label.style_label_left, color=color.blue, textcolor=color.white, size=size.small)
slLabel := label.new(bar_index + rightBars, sl, "SL " + str.tostring(sl, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white, size=size.small)
tp1Label := label.new(bar_index + rightBars, tp1, "TP1 " + str.tostring(tp1, format.mintick), style=label.style_label_left, color=color.lime, textcolor=color.black, size=size.small)
tp2Label := label.new(bar_index + rightBars, tp2, "TP2 " + str.tostring(tp2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.small)
tp3Label := label.new(bar_index + rightBars, tp3, "TP3 " + str.tostring(tp3, format.mintick), style=label.style_label_left, color=color.aqua, textcolor=color.black, size=size.small)
plotshape(validBuy, title="Auto BUY", text="BUY", style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.small)
plotshape(validSell, title="Auto SELL", text="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.small)
if barstate.islast and showTargets and not na(entryLine)
line.set_x2(entryLine, bar_index + rightBars)
line.set_x2(slLine, bar_index + rightBars)
line.set_x2(tp1Line, bar_index + rightBars)
line.set_x2(tp2Line, bar_index + rightBars)
line.set_x2(tp3Line, bar_index + rightBars)
label.set_x(entryLabel, bar_index + rightBars)
label.set_x(slLabel, bar_index + rightBars)
label.set_x(tp1Label, bar_index + rightBars)
label.set_x(tp2Label, bar_index + rightBars)
label.set_x(tp3Label, bar_index + rightBars)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table dash = table.new(position.top_right, 2, 5, border_width=1)
if barstate.islast and showDashboard
table.cell(dash, 0, 0, "SMC PRO", bgcolor=color.rgb(25, 35, 55), text_color=color.white)
table.cell(dash, 1, 0, "EMA 200", bgcolor=color.rgb(25, 35, 55), text_color=color.orange)
table.cell(dash, 0, 1, "Trend", text_color=chart.fg_color)
table.cell(dash, 1, 1, close > ema200 ? "ABOVE EMA" : close < ema200 ? "BELOW EMA" : "AT EMA", text_color=close > ema200 ? color.lime : close < ema200 ? color.red : chart.fg_color)
table.cell(dash, 0, 2, "Structure", text_color=chart.fg_color)
table.cell(dash, 1, 2, trend == 1 ? "BULLISH" : trend == -1 ? "BEARISH" : "NEUTRAL", text_color=trend == 1 ? color.lime : trend == -1 ? color.red : chart.fg_color)
table.cell(dash, 0, 3, "Last Signal", text_color=chart.fg_color)
table.cell(dash, 1, 3, lastSignal, text_color=lastSignal == "BUY" ? color.lime : lastSignal == "SELL" ? color.red : chart.fg_color)
table.cell(dash, 0, 4, "Targets", text_color=chart.fg_color)
table.cell(dash, 1, 4, "TP1 / TP2 / TP3", text_color=color.aqua)
if barstate.islast and not showDashboard
table.clear(dash, 0, 0, 1, 4)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(bullBOS, title="Bullish BOS", message="Bullish BOS | {{ticker}} | {{interval}} | {{close}}")
alertcondition(bearBOS, title="Bearish BOS", message="Bearish BOS | {{ticker}} | {{interval}} | {{close}}")
alertcondition(bullCHoCH, title="Bullish CHoCH", message="Bullish CHoCH | {{ticker}} | {{interval}} | {{close}}")
alertcondition(bearCHoCH, title="Bearish CHoCH", message="Bearish CHoCH | {{ticker}} | {{interval}} | {{close}}")
alertcondition(validBuy, title="SMC Auto BUY", message="SMC BUY | {{ticker}} | {{interval}} | {{close}}")
alertcondition(validSell, title="SMC Auto SELL", message="SMC SELL | {{ticker}} | {{interval}} | {{close}}")
alertcondition(bullFVG, title="Bullish FVG", message="Bullish FVG | {{ticker}} | {{interval}}")
alertcondition(bearFVG, title="Bearish FVG", message="Bearish FVG | {{ticker}} | {{interval}}")