OPEN-SOURCE SCRIPT

SMT Divergence + IFVG Strategy with Buy/Sell Signals

//version=6
indicator("SMT Divergence + IFVG Strategy with Buy/Sell Signals", overlay=true)

// Input parameters
higherTimeframe = input.timeframe("60", "Higher Timeframe") // Corrected timeframe to "60" for hourly
defaultStopLossPct = input.float(15.0, "Stop Loss %", step=0.1) // Updated to 15% stop loss
defaultTakeProfitPct = input.float(30.0, "Take Profit %", step=0.1) // Added 30% take profit percentage

// Retrieve higher timeframe trend
htfClose = request.security(syminfo.tickerid, higherTimeframe, close)
higherTrend = ta.ema(htfClose, 50) > ta.ema(htfClose, 200) // Higher timeframe bias: bullish if EMA50 > EMA200

// Custom Divergence Detection
rsiPeriod = input.int(14, "RSI Period")
rsi = ta.rsi(close, rsiPeriod)
lookback = input.int(5, "Divergence Lookback")

// Detect bullish divergence: Price makes a lower low, RSI makes a higher low
priceLow = ta.lowest(close, lookback)
pricePrevLow = ta.lowest(close[lookback], lookback)
rsiLow = ta.lowest(rsi, lookback)
rsiPrevLow = ta.lowest(rsi[lookback], lookback)
bullishDivergence = (priceLow < pricePrevLow) and (rsiLow > rsiPrevLow)

// Detect bearish divergence: Price makes a higher high, RSI makes a lower high
priceHigh = ta.highest(close, lookback)
pricePrevHigh = ta.highest(close[lookback], lookback)
rsiHigh = ta.highest(rsi, lookback)
rsiPrevHigh = ta.highest(rsi[lookback], lookback)
bearishDivergence = (priceHigh > pricePrevHigh) and (rsiHigh < rsiPrevHigh)

smtDiv = bullishDivergence or bearishDivergence

// Inverse Fair Value Gap (IFVG)
gapThreshold = input.float(0.5, "IFVG Threshold (%)", step=0.1)
priceChange = math.abs(close - close[1])
previousHigh = ta.valuewhen(priceChange > gapThreshold * close[1], high, 1)
previousLow = ta.valuewhen(priceChange > gapThreshold * close[1], low, 1)
ifvgZone = not na(previousHigh) and not na(previousLow) and (close > previousHigh or close < previousLow)

// Entry Signal
entryConditionBuy = higherTrend and bullishDivergence and ifvgZone
entryConditionSell = not higherTrend and bearishDivergence and ifvgZone

// Plotting Buy and Sell Signals
if entryConditionBuy
label.new(bar_index, high, "BUY", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)
stopLossLevel = close * (1 - defaultStopLossPct / 100)
takeProfitLevel = close * (1 + defaultTakeProfitPct / 100)
line.new(bar_index, stopLossLevel, bar_index + 1, stopLossLevel, color=color.red, width=1, extend=extend.right)
line.new(bar_index, takeProfitLevel, bar_index + 1, takeProfitLevel, color=color.green, width=1, extend=extend.right)

if entryConditionSell
label.new(bar_index, low, "SELL", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)
stopLossLevel = close * (1 + defaultStopLossPct / 100)
takeProfitLevel = close * (1 - defaultTakeProfitPct / 100)
line.new(bar_index, stopLossLevel, bar_index + 1, stopLossLevel, color=color.red, width=1, extend=extend.right)
line.new(bar_index, takeProfitLevel, bar_index + 1, takeProfitLevel, color=color.green, width=1, extend=extend.right)

// Alerts
alertcondition(entryConditionBuy, title="Buy Signal", message="Buy signal detected. Target 30%, Stop Loss 15%.")
alertcondition(entryConditionSell, title="Sell Signal", message="Sell signal detected. Target 30%, Stop Loss 15%.")
Bands and ChannelsBill Williams IndicatorsCandlestick analysis

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?

면책사항