OPEN-SOURCE SCRIPT

💼 Momentum SNR VIP

71
//version=5
indicator("Momentum", overlay=true)

// === SNR Detection ===
lookback = input.int(20, "Lookback for S/R", minval=5)
pivotHigh = ta.pivothigh(high, lookback, lookback)
pivotLow = ta.pivotlow(low, lookback, lookback)

// Plot SNR Zones
plotshape(pivotHigh, title="Resistance", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
plotshape(pivotLow, title="Support", location=location.belowbar, color=color.blue, style=shape.triangleup, size=size.small)

// === Price Action Detection ===
// Bullish Engulfing
bullishEngulfing = close[1] < open[1] and close > open and close > open[1] and open <= close[1]
// Bearish Engulfing
bearishEngulfing = close[1] > open[1] and close < open and close < open[1] and open >= close[1]

// Pin Bar Bullish
bullishPinBar = close > open and (low - math.min(open, close)) > 1.5 * (math.abs(close - open))
// Pin Bar Bearish
bearishPinBar = close < open and (math.max(open, close) - high) > 1.5 * (math.abs(close - open))

// === Combined Signal at SNR ===
supportZone = not na(pivotLow)
resistanceZone = not na(pivotHigh)

buySignal = (bullishEngulfing or bullishPinBar) and supportZone
sellSignal = (bearishEngulfing or bearishPinBar) and resistanceZone

// Plot Buy/Sell Arrows
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// === SL & TP Calculation ===
rr_ratio = input.float(2.0, "Risk Reward Ratio", minval=0.5, step=0.5)

buySL = low
buyTP = close + (close - low) * rr_ratio

sellSL = high
sellTP = close - (high - close) * rr_ratio

plot(buySignal ? buySL : na, title="Buy SL", color=color.red, style=plot.style_linebr, linewidth=1)
plot(buySignal ? buyTP : na, title="Buy TP", color=color.green, style=plot.style_linebr, linewidth=1)
plot(sellSignal ? sellSL : na, title="Sell SL", color=color.red, style=plot.style_linebr, linewidth=1)
plot(sellSignal ? sellTP : na, title="Sell TP", color=color.green, style=plot.style_linebr, linewidth=1)

// === Alerts ===
alertcondition(buySignal, title="Buy Alert", message="GOLD: Potential BUY @ SNR Zone + Price Action")
alertcondition(sellSignal, title="Sell Alert", message="GOLD: Potential SELL @ SNR Zone + Price Action")

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。