本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("EMMA SETUPS | Institutional Flow Pro", overlay=true, max_boxes_count=200, max_lines_count=200, max_labels_count=200)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 01. INPUT SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
grpSMC = "01. Smart Money Structure"
swingLen = input.int(5, "Swing Length", minval=2, maxval=30, group=grpSMC)
showStructure = input.bool(true, "Show BOS / CHoCH", group=grpSMC)
showLiquidity = input.bool(true, "Show Liquidity Levels", group=grpSMC)
showSweeps = input.bool(true, "Show Liquidity Sweeps", group=grpSMC)
sweepLookback = input.int(20, "Sweep Validity Bars", minval=1, maxval=100, group=grpSMC)
grpOB = "02. Order Blocks"
showOB = input.bool(true, "Show Order Blocks", group=grpOB)
obLookback = input.int(10, "OB Search Bars", minval=2, maxval=30, group=grpOB)
obExtend = input.int(40, "OB Extension", minval=5, maxval=200, group=grpOB)
grpFVG = "03. Fair Value Gaps"
showFVG = input.bool(true, "Show FVG", group=grpFVG)
fvgExtend = input.int(20, "FVG Extension", minval=5, maxval=100, group=grpFVG)
grpTrend = "04. Trend & Momentum"
useEMA = input.bool(true, "Enable EMA Filter", group=grpTrend)
emaFastLen = input.int(50, "Fast EMA", group=grpTrend)
emaSlowLen = input.int(200, "Slow EMA", group=grpTrend)
showEMA = input.bool(false, "Display EMA Lines", group=grpTrend)
rsiLen = input.int(14, "RSI Length", group=grpTrend)
rsiBull = input.int(50, "Bullish RSI Level", group=grpTrend)
rsiBear = input.int(50, "Bearish RSI Level", group=grpTrend)
grpVolume = "05. Volume Analysis"
useVolume = input.bool(true, "Enable Volume Filter", group=grpVolume)
volLen = input.int(20, "Volume Average", group=grpVolume)
volMult = input.float(1.2, "Strong Volume Multiplier", minval=0.1, step=0.1, group=grpVolume)
grpDisplay = "06. Display"
showDashboard = input.bool(true, "Show Dashboard", group=grpDisplay)
showSignals = input.bool(true, "Show BUY / SELL", group=grpDisplay)
showPremium = input.bool(true, "Show Premium / Discount", group=grpDisplay)
rangeLen = input.int(50, "Premium / Discount Range", minval=10, maxval=200, group=grpDisplay)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 02. EMA, RSI & VOLUME
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
rsi = ta.rsi(close, rsiLen)
avgVolume = ta.sma(volume, volLen)
volumeRatio = not na(avgVolume) and avgVolume > 0 ? volume / avgVolume : na
volumeAvailable = not na(volume) and not na(avgVolume) and avgVolume > 0
strongVolume = volumeAvailable and volumeRatio >= volMult
bullTrend = emaFast > emaSlow
bearTrend = emaFast < emaSlow
trendBullOK = not useEMA or bullTrend
trendBearOK = not useEMA or bearTrend
volumeOK = not useVolume or strongVolume
plot(showEMA ? emaFast : na, "EMA 50", color=color.aqua)
plot(showEMA ? emaSlow : na, "EMA 200", color=color.orange)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 03. SWING STRUCTURE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pivotHigh = ta.pivothigh(high, swingLen, swingLen)
pivotLow = ta.pivotlow(low, swingLen, swingLen)
var float lastSwingHigh = na
var float lastSwingLow = na
var int lastHighBar = na
var int lastLowBar = na
var line buyLiquidityLine = na
var line sellLiquidityLine = na
var bool buyLevelSwept = false
var bool sellLevelSwept = false
if not na(pivotHigh)
lastSwingHigh := pivotHigh
lastHighBar := bar_index - swingLen
buyLevelSwept := false
if not na(buyLiquidityLine)
line.delete(buyLiquidityLine)
if showLiquidity
buyLiquidityLine := line.new(lastHighBar, lastSwingHigh, bar_index, lastSwingHigh, extend=extend.right, color=color.new(color.red, 20), style=line.style_dashed, width=1)
if not na(pivotLow)
lastSwingLow := pivotLow
lastLowBar := bar_index - swingLen
sellLevelSwept := false
if not na(sellLiquidityLine)
line.delete(sellLiquidityLine)
if showLiquidity
sellLiquidityLine := line.new(lastLowBar, lastSwingLow, bar_index, lastSwingLow, extend=extend.right, color=color.new(color.lime, 20), style=line.style_dashed, width=1)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 04. LIQUIDITY SWEEPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
buySideSweep = not na(lastSwingHigh) and not buyLevelSwept and high > lastSwingHigh and close < lastSwingHigh
sellSideSweep = not na(lastSwingLow) and not sellLevelSwept and low < lastSwingLow and close > lastSwingLow
var int lastBSLSweepBar = na
var int lastSSLSweepBar = na
if buySideSweep
buyLevelSwept := true
lastBSLSweepBar := bar_index
if not na(buyLiquidityLine)
line.set_extend(buyLiquidityLine, extend.none)
line.set_x2(buyLiquidityLine, bar_index)
if showSweeps
label.new(bar_index, high, "BSL SWEEP", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.tiny)
if sellSideSweep
sellLevelSwept := true
lastSSLSweepBar := bar_index
if not na(sellLiquidityLine)
line.set_extend(sellLiquidityLine, extend.none)
line.set_x2(sellLiquidityLine, bar_index)
if showSweeps
label.new(bar_index, low, "SSL SWEEP", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.tiny)
recentBSL = not na(lastBSLSweepBar) and bar_index - lastBSLSweepBar <= sweepLookback
recentSSL = not na(lastSSLSweepBar) and bar_index - lastSSLSweepBar <= sweepLookback
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 05. BOS & CHoCH
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var int structureTrend = 0
var string structureText = "WAITING"
bullBreak = not na(lastSwingHigh) and ta.crossover(close, lastSwingHigh)
bearBreak = not na(lastSwingLow) and ta.crossunder(close, lastSwingLow)
bullCHoCH = bullBreak and structureTrend == -1
bearCHoCH = bearBreak and structureTrend == 1
bullBOS = bullBreak and structureTrend != -1
bearBOS = bearBreak and structureTrend != 1
if bullBreak
structureTrend := 1
structureText := bullCHoCH ? "BULLISH CHoCH" : "BULLISH BOS"
if bearBreak
structureTrend := -1
structureText := bearCHoCH ? "BEARISH CHoCH" : "BEARISH BOS"
if showStructure and bullBreak
label.new(bar_index, low, bullCHoCH ? "CHoCH UP" : "BOS UP", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.tiny)
if showStructure and bearBreak
label.new(bar_index, high, bearCHoCH ? "CHoCH DOWN" : "BOS DOWN", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 06. ORDER BLOCK DETECTION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box bullishOB = na
var box bearishOB = na
var float bullOBTop = na
var float bullOBBottom = na
var float bearOBTop = na
var float bearOBBottom = na
if bullBreak and showOB
int bullOffset = na
for i = 1 to obLookback
if close[i] < open[i] and na(bullOffset)
bullOffset := i
if not na(bullOffset)
bullOBTop := high[bullOffset]
bullOBBottom := low[bullOffset]
if not na(bullishOB)
box.delete(bullishOB)
bullishOB := box.new(bar_index - bullOffset, bullOBTop, bar_index + obExtend, bullOBBottom, border_color=color.lime, bgcolor=color.new(color.green, 86), text="BULLISH OB", text_color=color.lime, text_size=size.tiny)
if bearBreak and showOB
int bearOffset = na
for i = 1 to obLookback
if close[i] > open[i] and na(bearOffset)
bearOffset := i
if not na(bearOffset)
bearOBTop := high[bearOffset]
bearOBBottom := low[bearOffset]
if not na(bearishOB)
box.delete(bearishOB)
bearishOB := box.new(bar_index - bearOffset, bearOBTop, bar_index + obExtend, bearOBBottom, border_color=color.red, bgcolor=color.new(color.red, 86), text="BEARISH OB", text_color=color.red, text_size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 07. 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
var float bullFVGTop = na
var float bullFVGBottom = na
var float bearFVGTop = na
var float bearFVGBottom = na
if showFVG and bullFVG
bullFVGTop := low
bullFVGBottom := high[2]
if not na(bullFVGBox)
box.delete(bullFVGBox)
bullFVGBox := box.new(bar_index - 2, bullFVGTop, bar_index + fvgExtend, bullFVGBottom, border_color=color.aqua, bgcolor=color.new(color.aqua, 88), text="BULL FVG", text_color=color.aqua, text_size=size.tiny)
if showFVG and bearFVG
bearFVGTop := low[2]
bearFVGBottom := high
if not na(bearFVGBox)
box.delete(bearFVGBox)
bearFVGBox := box.new(bar_index - 2, bearFVGTop, bar_index + fvgExtend, bearFVGBottom, border_color=color.orange, bgcolor=color.new(color.orange, 88), text="BEAR FVG", text_color=color.orange, text_size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 08. PREMIUM & DISCOUNT
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
rangeHigh = ta.highest(high, rangeLen)
rangeLow = ta.lowest(low, rangeLen)
equilibrium = (rangeHigh + rangeLow) / 2
isPremium = close > equilibrium
isDiscount = close < equilibrium
plot(showPremium ? equilibrium : na, "Equilibrium", color=color.new(color.yellow, 15), linewidth=1, style=plot.style_line)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 09. INSTITUTIONAL BUY / SELL SIGNALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullCandle = close > open and close > close[1]
bearCandle = close < open and close < close[1]
buySignal = barstate.isconfirmed and recentSSL and bullBreak and bullCandle and rsi > rsiBull and trendBullOK and volumeOK
sellSignal = barstate.isconfirmed and recentBSL and bearBreak and bearCandle and rsi < rsiBear and trendBearOK and volumeOK
plotshape(showSignals and buySignal, title="EMMA BUY", text="BUY", style=shape.labelup, location=location.belowbar, color=color.lime, textcolor=color.black, size=size.small)
plotshape(showSignals and sellSignal, title="EMMA SELL", text="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.small)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 10. DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table dash = table.new(position.top_right, 2, 15, bgcolor=color.new(color.black, 8), frame_color=color.gray, frame_width=1, border_width=1)
if barstate.islast and showDashboard
string direction = bullTrend ? "BULLISH" : bearTrend ? "BEARISH" : "SIDEWAYS"
string signal = buySignal ? "BUY" : sellSignal ? "SELL" : "WAIT"
string sweepStatus = buySideSweep ? "BSL SWEPT" : sellSideSweep ? "SSL SWEPT" : recentBSL ? "RECENT BSL" : recentSSL ? "RECENT SSL" : "NO SWEEP"
string obStatus = not na(bullishOB) ? "BULLISH OB" : not na(bearishOB) ? "BEARISH OB" : "WAITING"
string fvgStatus = bullFVG ? "BULLISH FVG" : bearFVG ? "BEARISH FVG" : not na(bullFVGBox) ? "BULL FVG ACTIVE" : not na(bearFVGBox) ? "BEAR FVG ACTIVE" : "NONE"
string pdStatus = isPremium ? "PREMIUM" : isDiscount ? "DISCOUNT" : "EQUILIBRIUM"
string volStatus = not volumeAvailable ? "N/A" : strongVolume ? "HIGH" : "NORMAL"
string rsiStatus = rsi > rsiBull ? "BULLISH" : rsi < rsiBear ? "BEARISH" : "NEUTRAL"
table.cell(dash, 0, 0, "EMMA SETUPS", bgcolor=color.blue, text_color=color.white)
table.cell(dash, 1, 0, "INSTITUTIONAL PRO", bgcolor=color.blue, text_color=color.white)
table.cell(dash, 0, 1, "PAIR")
table.cell(dash, 1, 1, syminfo.ticker, text_color=color.white)
table.cell(dash, 0, 2, "TIMEFRAME")
table.cell(dash, 1, 2, timeframe.period, text_color=color.white)
table.cell(dash, 0, 3, "DIRECTION")
table.cell(dash, 1, 3, direction, text_color=bullTrend ? color.lime : bearTrend ? color.red : color.gray)
table.cell(dash, 0, 4, "SIGNAL")
table.cell(dash, 1, 4, signal, text_color=buySignal ? color.lime : sellSignal ? color.red : color.gray)
table.cell(dash, 0, 5, "BUY-SIDE LIQUIDITY")
table.cell(dash, 1, 5, na(lastSwingHigh) ? "N/A" : str.tostring(lastSwingHigh, format.mintick), text_color=color.red)
table.cell(dash, 0, 6, "SELL-SIDE LIQUIDITY")
table.cell(dash, 1, 6, na(lastSwingLow) ? "N/A" : str.tostring(lastSwingLow, format.mintick), text_color=color.lime)
table.cell(dash, 0, 7, "SWEEP STATUS")
table.cell(dash, 1, 7, sweepStatus, text_color=buySideSweep ? color.red : sellSideSweep ? color.lime : color.white)
table.cell(dash, 0, 8, "STRUCTURE")
table.cell(dash, 1, 8, structureText, text_color=structureTrend == 1 ? color.lime : structureTrend == -1 ? color.red : color.gray)
table.cell(dash, 0, 9, "ORDER BLOCK")
table.cell(dash, 1, 9, obStatus, text_color=not na(bullishOB) ? color.lime : not na(bearishOB) ? color.red : color.gray)
table.cell(dash, 0, 10, "FAIR VALUE GAP")
table.cell(dash, 1, 10, fvgStatus, text_color=bullFVG ? color.aqua : bearFVG ? color.orange : color.white)
table.cell(dash, 0, 11, "PRICE ZONE")
table.cell(dash, 1, 11, pdStatus, text_color=isPremium ? color.red : color.lime)
table.cell(dash, 0, 12, "RSI")
table.cell(dash, 1, 12, str.tostring(rsi, "#.0") + " / " + rsiStatus, text_color=rsi > rsiBull ? color.lime : rsi < rsiBear ? color.red : color.gray)
table.cell(dash, 0, 13, "VOLUME")
table.cell(dash, 1, 13, volStatus + (volumeAvailable ? " (" + str.tostring(volumeRatio, "#.##") + "x)" : ""), text_color=strongVolume ? color.lime : color.white)
table.cell(dash, 0, 14, "EMA TREND")
table.cell(dash, 1, 14, bullTrend ? "50 ABOVE 200" : bearTrend ? "50 BELOW 200" : "EQUAL", text_color=bullTrend ? color.lime : bearTrend ? color.red : color.gray)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 11. ALERT SYSTEM
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, "EMMA Institutional BUY", "EMMA SETUPS: Institutional Flow BUY confirmation")
alertcondition(sellSignal, "EMMA Institutional SELL", "EMMA SETUPS: Institutional Flow SELL confirmation")
alertcondition(buySideSweep, "Buy-Side Liquidity Sweep", "EMMA SETUPS: Buy-Side Liquidity Swept")
alertcondition(sellSideSweep, "Sell-Side Liquidity Sweep", "EMMA SETUPS: Sell-Side Liquidity Swept")
alertcondition(bullBreak, "Bullish BOS / CHoCH", "EMMA SETUPS: Bullish Market Structure Break")
alertcondition(bearBreak, "Bearish BOS / CHoCH", "EMMA SETUPS: Bearish Market Structure Break")
alertcondition(bullFVG, "Bullish FVG", "EMMA SETUPS: Bullish Fair Value Gap Detected")
alertcondition(bearFVG, "Bearish FVG", "EMMA SETUPS: Bearish Fair Value Gap Detected")