EMMA SETUPS | Precision Volume Reversal

EmmaSetups · study · 238 行 · 点赞 46 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0
// © EMMA SETUPS
 
//@version=6
indicator("EMMA SETUPS | Precision Volume Reversal", overlay=true, max_labels_count=200)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 1. SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
groupVolume = "Volume Settings"
volLength = input.int(20, "Volume Average Length", minval=1, group=groupVolume)
volMultiplier = input.float(1.5, "Volume Spike Multiplier", minval=1.0, step=0.1, group=groupVolume)
requireVolume = input.bool(true, "Require Volume Confirmation", group=groupVolume)
 
groupCandle = "Reversal Candle Settings"
useEngulfing = input.bool(true, "Engulfing Patterns", group=groupCandle)
usePinbar = input.bool(true, "Pin Bar Patterns", group=groupCandle)
wickRatio = input.float(2.0, "Minimum Wick / Body Ratio", minval=1.0, step=0.25, group=groupCandle)
useMomentum = input.bool(true, "Momentum Reversal Candles", group=groupCandle)
minBodyRatio = input.float(0.60, "Momentum Body / Range", minval=0.1, maxval=0.95, step=0.05, group=groupCandle)
 
groupTrend = "Trend Filter"
useEMA = input.bool(true, "Enable EMA Filter", group=groupTrend)
fastLength = input.int(50, "Fast EMA", minval=1, group=groupTrend)
slowLength = input.int(200, "Slow EMA", minval=1, group=groupTrend)
showEMA = input.bool(false, "Show EMA Lines", group=groupTrend)
 
groupRisk = "Risk Management"
showRisk = input.bool(true, "Show Entry / SL / Targets", group=groupRisk)
atrLength = input.int(14, "ATR Length", minval=1, group=groupRisk)
atrMultiplier = input.float(1.5, "Stop Loss ATR Multiplier", minval=0.1, step=0.1, group=groupRisk)
rr1 = input.float(1.0, "TP1 Risk / Reward", minval=0.1, step=0.1, group=groupRisk)
rr2 = input.float(2.0, "TP2 Risk / Reward", minval=0.1, step=0.1, group=groupRisk)
rr3 = input.float(3.0, "TP3 Risk / Reward", minval=0.1, step=0.1, group=groupRisk)
 
groupDisplay = "Display Settings"
showDashboard = input.bool(true, "Show Dashboard", group=groupDisplay)
showSignals = input.bool(true, "Show BUY / SELL Labels", group=groupDisplay)
showVolumeHighlight = input.bool(false, "Highlight Volume Spikes", group=groupDisplay)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 2. VOLUME ANALYSIS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
volAverage = ta.sma(volume, volLength)
relativeVolume = not na(volAverage) and volAverage > 0 ? volume / volAverage : na
volumeSpike = not na(relativeVolume) and relativeVolume >= volMultiplier
volumeOK = not requireVolume or volumeSpike
 
volumeStatus = volumeSpike ? "HIGH VOLUME" : "NORMAL"
volumeRatioText = na(relativeVolume) ? "N/A" : str.tostring(relativeVolume, "#.##") + "x"
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 3. CANDLE ANALYSIS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
candleRange = math.max(high - low, syminfo.mintick)
body = math.abs(close - open)
upperWick = high - math.max(open, close)
lowerWick = math.min(open, close) - low
 
bodyRatio = body / candleRange
bullCandle = close > open
bearCandle = close < open
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 4. ENGULFING DETECTION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullEngulf = useEngulfing and bullCandle and close[1] < open[1] and open <= close[1] and close >= open[1]
bearEngulf = useEngulfing and bearCandle and close[1] > open[1] and open >= close[1] and close <= open[1]
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 5. PIN BAR DETECTION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullPin = usePinbar and lowerWick >= body * wickRatio and upperWick <= body and bullCandle
bearPin = usePinbar and upperWick >= body * wickRatio and lowerWick <= body and bearCandle
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 6. MOMENTUM REVERSAL CANDLES
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullMomentum = useMomentum and bullCandle and bodyRatio >= minBodyRatio
bearMomentum = useMomentum and bearCandle and bodyRatio >= minBodyRatio
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 7. EMA TREND FILTER
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
emaFast = ta.ema(close, fastLength)
emaSlow = ta.ema(close, slowLength)
 
bullTrend = emaFast > emaSlow
bearTrend = emaFast < emaSlow
 
trendBuyOK = not useEMA or bullTrend
trendSellOK = not useEMA or bearTrend
 
plot(showEMA ? emaFast : na, "EMA 50", color=color.orange, linewidth=2)
plot(showEMA ? emaSlow : na, "EMA 200", color=color.blue, linewidth=2)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 8. REVERSAL SIGNAL LOGIC
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullReversal = bullEngulf or bullPin or bullMomentum
bearReversal = bearEngulf or bearPin or bearMomentum
 
buySignal = bullReversal and volumeOK and trendBuyOK and not bearReversal and barstate.isconfirmed
sellSignal = bearReversal and volumeOK and trendSellOK and not bullReversal and barstate.isconfirmed
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 9. PATTERN NAME
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
string patternName = "No Pattern"
 
if bullEngulf
    patternName := "Bullish Engulfing"
else if bearEngulf
    patternName := "Bearish Engulfing"
else if bullPin
    patternName := "Bullish Pin Bar"
else if bearPin
    patternName := "Bearish Pin Bar"
else if bullMomentum
    patternName := "Bull Momentum"
else if bearMomentum
    patternName := "Bear Momentum"
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 10. ATR RISK LEVELS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
atr = ta.atr(atrLength)
 
var float entryPrice = na
var float stopLoss = na
var float target1 = na
var float target2 = na
var float target3 = na
var string lastDirection = "WAIT"
 
if buySignal
    entryPrice := close
    stopLoss := close - atr * atrMultiplier
    target1 := close + (close - stopLoss) * rr1
    target2 := close + (close - stopLoss) * rr2
    target3 := close + (close - stopLoss) * rr3
    lastDirection := "BUY"
 
if sellSignal
    entryPrice := close
    stopLoss := close + atr * atrMultiplier
    target1 := close - (stopLoss - close) * rr1
    target2 := close - (stopLoss - close) * rr2
    target3 := close - (stopLoss - close) * rr3
    lastDirection := "SELL"
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 11. CHART SIGNALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
plotshape(showSignals and buySignal, title="BUY Reversal", style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", textcolor=color.white, size=size.small)
 
plotshape(showSignals and sellSignal, title="SELL Reversal", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.small)
 
barcolor(showVolumeHighlight and volumeSpike ? color.yellow : na)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 12. ATR LEVEL PLOTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
plot(showRisk ? entryPrice : na, "Entry Price", color=color.blue, linewidth=2, style=plot.style_stepline)
plot(showRisk ? stopLoss : na, "Stop Loss", color=color.red, linewidth=2, style=plot.style_stepline)
plot(showRisk ? target1 : na, "TP1", color=color.lime, linewidth=1, style=plot.style_stepline)
plot(showRisk ? target2 : na, "TP2", color=color.green, linewidth=1, style=plot.style_stepline)
plot(showRisk ? target3 : na, "TP3", color=color.teal, linewidth=1, style=plot.style_stepline)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 13. DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var table dash = table.new(position.top_right, 2, 10, border_width=1)
 
trendText = bullTrend ? "BULLISH" : bearTrend ? "BEARISH" : "NEUTRAL"
signalText = buySignal ? "BUY" : sellSignal ? "SELL" : "WAIT"
signalColor = buySignal ? color.green : sellSignal ? color.red : color.gray
 
if barstate.islast and showDashboard
    table.cell(dash, 0, 0, "EMMA SETUPS", bgcolor=color.black, text_color=color.white)
    table.cell(dash, 1, 0, "PRECISION REVERSAL", bgcolor=color.black, text_color=color.white)
 
    table.cell(dash, 0, 1, "Symbol", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 1, syminfo.ticker, text_color=color.white)
 
    table.cell(dash, 0, 2, "Timeframe", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 2, timeframe.period, text_color=color.white)
 
    table.cell(dash, 0, 3, "Trend", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 3, useEMA ? trendText : "FILTER OFF", text_color=color.white)
 
    table.cell(dash, 0, 4, "Relative Volume", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 4, volumeRatioText, text_color=color.white)
 
    table.cell(dash, 0, 5, "Volume Status", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 5, volumeStatus, text_color=volumeSpike ? color.lime : color.white)
 
    table.cell(dash, 0, 6, "Pattern", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 6, patternName, text_color=color.white)
 
    table.cell(dash, 0, 7, "Signal", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 7, signalText, bgcolor=signalColor, text_color=color.white)
 
    table.cell(dash, 0, 8, "Entry / SL", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 8, na(entryPrice) ? "N/A" : str.tostring(entryPrice, format.mintick) + " / " + str.tostring(stopLoss, format.mintick), text_color=color.white)
 
    table.cell(dash, 0, 9, "TP1 / TP2 / TP3", bgcolor=color.new(color.gray, 70), text_color=color.white)
    table.cell(dash, 1, 9, na(target1) ? "N/A" : str.tostring(target1, format.mintick) + " / " + str.tostring(target2, format.mintick) + " / " + str.tostring(target3, format.mintick), text_color=color.white)
 
if barstate.islast and not showDashboard
    table.clear(dash, 0, 0, 1, 9)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 14. ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
alertcondition(buySignal, title="Precision BUY Reversal", message="EMMA SETUPS: Bullish volume reversal on {{ticker}} {{interval}}")
alertcondition(sellSignal, title="Precision SELL Reversal", message="EMMA SETUPS: Bearish volume reversal on {{ticker}} {{interval}}")
 
alertcondition(volumeSpike, title="Volume Spike", message="EMMA SETUPS: Volume spike detected on {{ticker}} {{interval}}")
 
alertcondition(bullEngulf, title="Bullish Engulfing", message="Bullish Engulfing on {{ticker}}")
alertcondition(bearEngulf, title="Bearish Engulfing", message="Bearish Engulfing on {{ticker}}")
alertcondition(bullPin, title="Bullish Pin Bar", message="Bullish Pin Bar on {{ticker}}")
alertcondition(bearPin, title="Bearish Pin Bar", message="Bearish Pin Bar on {{ticker}}")

← 返回列表