本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Smart Money Concept Suite Pro | Emma Trading", overlay=true, max_labels_count=200, max_lines_count=100, max_boxes_count=100)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 1. INPUT SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
grpStructure = "Market Structure"
swingLen = input.int(5, "Swing Length", minval=2, group=grpStructure)
showBOS = input.bool(true, "Show BOS", group=grpStructure)
showCHoCH = input.bool(true, "Show CHoCH", group=grpStructure)
grpOB = "Order Blocks"
showOB = input.bool(true, "Show Order Blocks", group=grpOB)
obLookback = input.int(15, "OB Search Lookback", minval=2, maxval=50, group=grpOB)
grpFVG = "Fair Value Gaps"
showFVG = input.bool(true, "Show FVG", group=grpFVG)
grpLiq = "Liquidity"
showLiquidity = input.bool(true, "Show Liquidity Levels", group=grpLiq)
grpTrade = "Entry / SL / TP"
showSignals = input.bool(true, "Show BUY / SELL Signals", group=grpTrade)
showTradeLevels = input.bool(true, "Show Entry / SL / TP Lines", group=grpTrade)
atrLen = input.int(14, "ATR Length", minval=1, group=grpTrade)
slMultiplier = input.float(1.5, "ATR Stop Loss Multiplier", minval=0.1, step=0.1, group=grpTrade)
rr1 = input.float(1.0, "TP1 Risk Reward", minval=0.1, step=0.1, group=grpTrade)
rr2 = input.float(2.0, "TP2 Risk Reward", minval=0.1, step=0.1, group=grpTrade)
rr3 = input.float(3.0, "TP3 Risk Reward", minval=0.1, step=0.1, group=grpTrade)
grpDash = "Professional Dashboard"
showDashboard = input.bool(true, "Show Dashboard", group=grpDash)
dashboardPosition = input.string("Top Right", "Dashboard Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group=grpDash)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 2. MARKET STRUCTURE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atr = ta.atr(atrLen)
pivotHigh = ta.pivothigh(high, swingLen, swingLen)
pivotLow = ta.pivotlow(low, swingLen, swingLen)
var float lastHigh = na
var float lastLow = na
var int trend = 0
var string lastStructure = "Waiting"
var string lastSignal = "NONE"
if not na(pivotHigh)
lastHigh := pivotHigh
if not na(pivotLow)
lastLow := pivotLow
bullBreak = barstate.isconfirmed and not na(lastHigh) and ta.crossover(close, lastHigh)
bearBreak = barstate.isconfirmed and not na(lastLow) and ta.crossunder(close, lastLow)
bullCHoCH = bullBreak and trend == -1
bearCHoCH = bearBreak and trend == 1
bullBOS = bullBreak and not bullCHoCH
bearBOS = bearBreak and not bearCHoCH
if bullBreak
lastStructure := bullCHoCH ? "BULLISH CHoCH" : "BULLISH BOS"
trend := 1
lastHigh := na
if bearBreak
lastStructure := bearCHoCH ? "BEARISH CHoCH" : "BEARISH BOS"
trend := -1
lastLow := na
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 3. BOS / CHoCH LABELS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if showBOS and bullBOS
label.new(bar_index, high, "BOS", style=label.style_label_down, color=color.green, textcolor=color.white, size=size.tiny)
if showBOS and bearBOS
label.new(bar_index, low, "BOS", style=label.style_label_up, color=color.red, textcolor=color.white, size=size.tiny)
if showCHoCH and bullCHoCH
label.new(bar_index, high, "CHoCH", style=label.style_label_down, color=color.blue, textcolor=color.white, size=size.small)
if showCHoCH and bearCHoCH
label.new(bar_index, low, "CHoCH", style=label.style_label_up, color=color.orange, textcolor=color.white, size=size.small)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 4. ORDER BLOCKS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box bullOB = na
var box bearOB = na
if showOB and bullBreak
int foundBull = na
for i = 1 to obLookback
if close[i] < open[i] and na(foundBull)
foundBull := i
if not na(foundBull)
if not na(bullOB)
box.delete(bullOB)
bullOB := box.new(bar_index - foundBull, high[foundBull], bar_index + 20, low[foundBull], bgcolor=color.new(color.green, 88), border_color=color.green, text="BULLISH OB", text_color=color.green)
if showOB and bearBreak
int foundBear = na
for i = 1 to obLookback
if close[i] > open[i] and na(foundBear)
foundBear := i
if not na(foundBear)
if not na(bearOB)
box.delete(bearOB)
bearOB := box.new(bar_index - foundBear, high[foundBear], bar_index + 20, low[foundBear], bgcolor=color.new(color.red, 88), border_color=color.red, text="BEARISH OB", text_color=color.red)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 5. FAIR VALUE GAPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box bullFVG = na
var box bearFVG = na
bullGap = low > high[2]
bearGap = high < low[2]
if showFVG and bullGap
if not na(bullFVG)
box.delete(bullFVG)
bullFVG := box.new(bar_index - 2, low, bar_index + 15, high[2], bgcolor=color.new(color.aqua, 88), border_color=color.aqua, text="BULLISH FVG", text_color=color.aqua)
if showFVG and bearGap
if not na(bearFVG)
box.delete(bearFVG)
bearFVG := box.new(bar_index - 2, low[2], bar_index + 15, high, bgcolor=color.new(color.orange, 88), border_color=color.orange, text="BEARISH FVG", text_color=color.orange)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 6. LIQUIDITY LEVELS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var line buyLiquidity = na
var line sellLiquidity = na
if showLiquidity and not na(pivotHigh)
if not na(buyLiquidity)
line.delete(buyLiquidity)
buyLiquidity := line.new(bar_index - swingLen, pivotHigh, bar_index + 20, pivotHigh, color=color.red, style=line.style_dashed)
if showLiquidity and not na(pivotLow)
if not na(sellLiquidity)
line.delete(sellLiquidity)
sellLiquidity := line.new(bar_index - swingLen, pivotLow, bar_index + 20, pivotLow, color=color.lime, style=line.style_dashed)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 7. ENTRY / STOP LOSS / TARGETS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var float entryPrice = na
var float stopPrice = na
var float target1 = na
var float target2 = na
var float target3 = na
var int tradeDirection = 0
var int entryBar = na
var bool tradeActive = false
var bool tp1Done = false
var bool tp2Done = false
buySignal = bullBreak
sellSignal = bearBreak
// Trade event flags reset on each bar
bool slEvent = false
bool tp1Event = false
bool tp2Event = false
bool tp3Event = false
if buySignal
entryPrice := close
tradeDirection := 1
float risk = atr * slMultiplier
stopPrice := entryPrice - risk
target1 := entryPrice + risk * rr1
target2 := entryPrice + risk * rr2
target3 := entryPrice + risk * rr3
entryBar := bar_index
tradeActive := true
tp1Done := false
tp2Done := false
lastSignal := "BUY"
if sellSignal
entryPrice := close
tradeDirection := -1
float risk = atr * slMultiplier
stopPrice := entryPrice + risk
target1 := entryPrice - risk * rr1
target2 := entryPrice - risk * rr2
target3 := entryPrice - risk * rr3
entryBar := bar_index
tradeActive := true
tp1Done := false
tp2Done := false
lastSignal := "SELL"
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 8. TARGET HIT / STOP LOSS MANAGEMENT
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if tradeActive and bar_index > entryBar
bool stopHit = tradeDirection == 1 ? low <= stopPrice : high >= stopPrice
bool thirdTargetHit = tradeDirection == 1 ? high >= target3 : low <= target3
// Conservative handling: SL takes priority if SL and target occur on same candle.
if stopHit
slEvent := true
tradeActive := false
else
bool firstTargetHit = tradeDirection == 1 ? high >= target1 : low <= target1
bool secondTargetHit = tradeDirection == 1 ? high >= target2 : low <= target2
if firstTargetHit and not tp1Done
tp1Done := true
tp1Event := true
if secondTargetHit and not tp2Done
tp2Done := true
tp2Event := true
if thirdTargetHit
tp3Event := true
tradeActive := false
tradeStatus = tradeActive ? "ACTIVE" : slEvent ? "STOP LOSS HIT" : tp3Event ? "TP3 HIT" : "WAITING"
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 9. ENTRY / SL / TP CHART DISPLAY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plot(showTradeLevels and tradeActive ? entryPrice : na, "ENTRY PRICE", color=color.blue, linewidth=2, style=plot.style_linebr)
plot(showTradeLevels and tradeActive ? stopPrice : na, "STOP LOSS", color=color.red, linewidth=2, style=plot.style_linebr)
plot(showTradeLevels and tradeActive ? target1 : na, "TP1", color=color.lime, linewidth=1, style=plot.style_linebr)
plot(showTradeLevels and tradeActive ? target2 : na, "TP2", color=color.green, linewidth=1, style=plot.style_linebr)
plot(showTradeLevels and tradeActive ? target3 : na, "TP3", color=color.teal, linewidth=2, style=plot.style_linebr)
plotshape(showSignals and buySignal, title="BUY SIGNAL", text="BUY", style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.small)
plotshape(showSignals and sellSignal, title="SELL SIGNAL", text="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.small)
// Price labels on signal candles
if showTradeLevels and buySignal
label.new(bar_index, entryPrice, "BUY ENTRY\n" + str.tostring(entryPrice, format.mintick), style=label.style_label_left, color=color.blue, textcolor=color.white)
label.new(bar_index, stopPrice, "SL\n" + str.tostring(stopPrice, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white)
label.new(bar_index, target1, "TP1\n" + str.tostring(target1, format.mintick), style=label.style_label_left, color=color.lime, textcolor=color.black)
label.new(bar_index, target2, "TP2\n" + str.tostring(target2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
label.new(bar_index, target3, "TP3\n" + str.tostring(target3, format.mintick), style=label.style_label_left, color=color.teal, textcolor=color.white)
if showTradeLevels and sellSignal
label.new(bar_index, entryPrice, "SELL ENTRY\n" + str.tostring(entryPrice, format.mintick), style=label.style_label_left, color=color.blue, textcolor=color.white)
label.new(bar_index, stopPrice, "SL\n" + str.tostring(stopPrice, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white)
label.new(bar_index, target1, "TP1\n" + str.tostring(target1, format.mintick), style=label.style_label_left, color=color.lime, textcolor=color.black)
label.new(bar_index, target2, "TP2\n" + str.tostring(target2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
label.new(bar_index, target3, "TP3\n" + str.tostring(target3, format.mintick), style=label.style_label_left, color=color.teal, textcolor=color.white)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 10. PROFESSIONAL DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_price(float value) =>
na(value) ? "—" : str.tostring(value, format.mintick)
f_position(string pos) =>
pos == "Top Left" ? position.top_left :
pos == "Bottom Right" ? position.bottom_right :
pos == "Bottom Left" ? position.bottom_left :
position.top_right
var table dash = table.new(f_position(dashboardPosition), 2, 14, border_width=1, frame_color=color.gray, border_color=color.new(color.gray, 60))
if barstate.islast
if showDashboard
color header = color.rgb(20, 30, 48)
color row = color.rgb(37, 47, 64)
color trendColor = trend == 1 ? color.green : trend == -1 ? color.red : color.gray
color signalColor = lastSignal == "BUY" ? color.green : lastSignal == "SELL" ? color.red : color.gray
table.cell(dash, 0, 0, "EMMA TRADING", bgcolor=header, text_color=color.white)
table.cell(dash, 1, 0, "SMC SUITE PRO", bgcolor=header, text_color=color.aqua)
table.cell(dash, 0, 1, "TRADING PAIR", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 1, syminfo.ticker, bgcolor=row, text_color=color.white)
table.cell(dash, 0, 2, "TIMEFRAME", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 2, timeframe.period, bgcolor=row, text_color=color.white)
table.cell(dash, 0, 3, "MARKET TREND", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 3, trend == 1 ? "BULLISH" : trend == -1 ? "BEARISH" : "NEUTRAL", bgcolor=trendColor, text_color=color.white)
table.cell(dash, 0, 4, "STRUCTURE", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 4, lastStructure, bgcolor=row, text_color=color.white)
table.cell(dash, 0, 5, "DIRECTION", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 5, lastSignal, bgcolor=signalColor, text_color=color.white)
table.cell(dash, 0, 6, "TRADE STATUS", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 6, tradeStatus, bgcolor=tradeActive ? color.green : color.gray, text_color=color.white)
table.cell(dash, 0, 7, "ENTRY PRICE", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 7, f_price(entryPrice), bgcolor=row, text_color=color.blue)
table.cell(dash, 0, 8, "STOP LOSS", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 8, f_price(stopPrice), bgcolor=row, text_color=color.red)
table.cell(dash, 0, 9, "TAKE PROFIT 1", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 9, f_price(target1) + (tp1Done ? " HIT" : ""), bgcolor=row, text_color=color.lime)
table.cell(dash, 0, 10, "TAKE PROFIT 2", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 10, f_price(target2) + (tp2Done ? " HIT" : ""), bgcolor=row, text_color=color.lime)
table.cell(dash, 0, 11, "TAKE PROFIT 3", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 11, f_price(target3) + (tp3Event ? " HIT" : ""), bgcolor=row, text_color=color.lime)
table.cell(dash, 0, 12, "RISK / REWARD", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 12, "1:" + str.tostring(rr3), bgcolor=row, text_color=color.aqua)
table.cell(dash, 0, 13, "ATR", bgcolor=row, text_color=color.white)
table.cell(dash, 1, 13, f_price(atr), bgcolor=row, text_color=color.white)
else
table.clear(dash, 0, 0, 1, 13)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 11. ALERT CONDITIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, "BUY ENTRY", "SMC BUY Entry | {{ticker}} | {{interval}} | {{close}}")
alertcondition(sellSignal, "SELL ENTRY", "SMC SELL Entry | {{ticker}} | {{interval}} | {{close}}")
alertcondition(slEvent, "STOP LOSS HIT", "SMC Stop Loss Hit | {{ticker}}")
alertcondition(tp1Event, "TP1 HIT", "SMC Take Profit 1 Hit | {{ticker}}")
alertcondition(tp2Event, "TP2 HIT", "SMC Take Profit 2 Hit | {{ticker}}")
alertcondition(tp3Event, "TP3 HIT", "SMC Take Profit 3 Hit | {{ticker}}")
alertcondition(bullCHoCH, "BULLISH CHoCH", "Bullish CHoCH | {{ticker}}")
alertcondition(bearCHoCH, "BEARISH CHoCH", "Bearish CHoCH | {{ticker}}")
alertcondition(bullBOS, "BULLISH BOS", "Bullish BOS | {{ticker}}")
alertcondition(bearBOS, "BEARISH BOS", "Bearish BOS | {{ticker}}")