OPEN-SOURCE SCRIPT

Breakout Signal - Smart Money Enhanced

53
//version=6
indicator("Breakout Signal - Smart Money Enhanced", overlay=true)

// === Input Settings ===
fibLength = input.int(50, minval=10, title="Fibonacci Lookback")
showRSI = input.bool(true, title="Enable RSI Confirmation")
showMACD = input.bool(true, title="Enable MACD Confirmation")
showVolumeShelf = input.bool(true, title="Enable Volume Shelf Modeling")
binSize = input.float(0.5, title="Volume Shelf Bin Size ($)")
volLookback = input.int(100, title="Volume Shelf Lookback")
showSignalStrength = input.bool(true, title="Show Signal Strength")
showATRStops = input.bool(true, title="Enable ATR-Based Stops")
atrLength = input.int(14, title="ATR Length")
atrMult = input.float(1.5, title="ATR Multiplier for Stops")

// === Smart Money Filters ===
volMultiplier = input.float(1.5, title="Volume Surge Threshold (x Avg)")
consolidationBars = input.int(20, title="ATR Contraction Lookback")
consolidationThresh = input.float(0.8, title="ATR Contraction % Threshold")
adxLength = input.int(14, title="ADX Length")
adxThreshold = input.int(20, title="ADX Minimum Value")
requireRetest = input.bool(false, title="Require Retest Before Signal")
liquidityWickRatio = input.float(2.0, title="Wick-to-Body Ratio for Liquidity Grab")

// === Fibonacci Levels ===
highLevel = ta.highest(high, fibLength)
lowLevel = ta.lowest(low, fibLength)
fibRange = highLevel - lowLevel
fib0618 = lowLevel + fibRange * 0.618
fib0382 = lowLevel + fibRange * 0.382

plot(fib0618, title="Fib 0.618", color=color.green, linewidth=1)
plot(fib0382, title="Fib 0.382", color=color.red, linewidth=1)

// === RSI & MACD ===
rsi = ta.rsi(close, 14)
macdLine = ta.ema(close, 12) - ta.ema(close, 26)
signal_Line = ta.ema(macdLine, 9)

rsiBull = rsi > 50 and rsi > rsi[1] and rsi[1] > rsi[2]
rsiBear = rsi < 50 and rsi < rsi[1] and rsi[1] < rsi[2]

macdHist = macdLine - signal_Line
macdBull = macdLine > signal_Line and macdHist > macdHist[1] and macdHist[1] > macdHist[2]
macdBear = macdLine < signal_Line and macdHist < macdHist[1] and macdHist[1] < macdHist[2]


// === Volume Shelf Modeling ===
var float[] volumeBins = array.new_float()
var float[] priceBins = array.new_float()
if bar_index == 0
for i = 0 to 99
array.push(volumeBins, 0.0)
array.push(priceBins, na)

if showVolumeShelf
for i = 0 to volLookback
idx = bar_index - i
priceBin = math.floor(close[idx] / binSize) * binSize
binIndex = -1
for j = 0 to array.size(priceBins) - 1
if priceBin == array.get(priceBins, j)
binIndex := j
break
if binIndex == -1
for j = 0 to array.size(priceBins) - 1
if na(array.get(priceBins, j))
array.set(priceBins, j, priceBin)
array.set(volumeBins, j, volume[idx])
break
else
array.set(volumeBins, binIndex, array.get(volumeBins, binIndex) + volume[idx])

// Plotting top volume shelf
maxVol = 0.0
var float shelfPrice = na
for i = 0 to array.size(volumeBins) - 1
if array.get(volumeBins, i) > maxVol
maxVol := array.get(volumeBins, i)
shelfPrice := array.get(priceBins, i)

plot(showVolumeShelf and not na(shelfPrice) ? shelfPrice : na, title="Volume Shelf Level", color=color.orange, linewidth=1, style=plot.style_line)

// === ATR & ADX ===
atr = ta.atr(atrLength)
atrContraction = ta.atr(consolidationBars) < atr * consolidationThresh

upMove = high - high[1]
downMove = low[1] - low
plusDM = na(upMove) ? na : (upMove > downMove and upMove > 0 ? upMove : 0)
minusDM = na(downMove) ? na : (downMove > upMove and downMove > 0 ? downMove : 0)
trur = ta.rma(ta.tr(true), adxLength)
plusDI = 100 * ta.rma(plusDM, adxLength) / trur
minusDI = 100 * ta.rma(minusDM, adxLength) / trur
adx = 100 * ta.rma(math.abs(plusDI - minusDI) / (plusDI + minusDI), adxLength)

volSurge = volume > ta.sma(volume, 20) * volMultiplier

// === Retest Logic ===
var float breakoutLevel = na
var int barsSinceBreakout = na
var int barsSinceBreakdown = na

brokeAbove = ta.crossover(close, fib0618)
brokeBelow = ta.crossunder(close, fib0382)

barsSinceBreakout := brokeAbove ? 0 : nz(barsSinceBreakout[1]) + 1
barsSinceBreakdown := brokeBelow ? 0 : nz(barsSinceBreakdown[1]) + 1

if brokeAbove
breakoutLevel := fib0618
if brokeBelow
breakoutLevel := fib0382

hasRetested = close < breakoutLevel and barsSinceBreakout < 10
hasRetestedDown = close > breakoutLevel and barsSinceBreakdown < 10

// === Liquidity Grab Detection ===
wickUp = high - math.max(close, open)
body = math.abs(close - open)
liquidityGrab = wickUp > (body * liquidityWickRatio) and close < high and high > fib0618

wickDown = math.min(close, open) - low
liquidityDump = wickDown > (body * liquidityWickRatio) and close > low and low < fib0382

// === Signal Conditions ===
buySignal = close > fib0618 and (not showRSI or rsiBull) and (not showMACD or macdBull) and volSurge and atrContraction and adx > adxThreshold and (not requireRetest or hasRetested) and liquidityGrab
sellSignal = close < fib0382 and (not showRSI or rsiBear) and (not showMACD or macdBear) and volSurge and atrContraction and adx > adxThreshold and (not requireRetest or hasRetestedDown) and liquidityDump

// === Signal Strength ===
buyStrength = rsi > 60 and (macdLine - signal_Line) > 0.5 and close > fib0618 * 1.005
sellStrength = rsi < 40 and (macdLine - signal_Line) < -0.5 and close < fib0382 * 0.995

// === Plot ATR Stops ===
buyStop = close - atr * atrMult
sellStop = close + atr * atrMult
plot(showATRStops and buySignal ? buyStop : na, title="Buy ATR Stop", color=color.green, style=plot.style_line)
plot(showATRStops and sellSignal ? sellStop : na, title="Sell ATR Stop", color=color.red, style=plot.style_line)

// === Plot Signals ===
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=buyStrength and showSignalStrength ? color.lime : color.green, style=shape.triangleup, size=size.small)
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=sellStrength and showSignalStrength ? color.maroon : color.red, style=shape.triangledown, size=size.small)

// === Alerts ===
alertcondition(buySignal, title="Buy Breakout", message="Smart Money breakout above 0.618 confirmed")
alertcondition(sellSignal, title="Sell Breakdown", message="Smart Money breakdown below 0.382 confirmed")

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。