OPEN-SOURCE SCRIPT

SMC Entry & Exit Strategy (Multi-Timeframe)

140
//version=5
indicator("SMC Entry & Exit Strategy (Multi-Timeframe)", overlay=true)

// User-defined higher timeframe selection (Use "240" for 4H, "60" for 1H, etc.)
htf = input.timeframe("240", "Higher Timeframe (minutes)")

// Get higher timeframe values
htfOpen = request.security(syminfo.tickerid, htf, open)
htfHigh = request.security(syminfo.tickerid, htf, high)
htfLow = request.security(syminfo.tickerid, htf, low)
htfClose = request.security(syminfo.tickerid, htf, close)

// Identify Higher Timeframe Market Structure (BOS & CHoCH)
var float htfPrevHigh = na
var float htfPrevLow = na

htfPrevHigh := (htfHigh[1] > htfHigh[2]) ? htfHigh[1] : htfPrevHigh
htfPrevLow := (htfLow[1] < htfLow[2]) ? htfLow[1] : htfPrevLow

htfBullishBOS = (htfHigh > htfPrevHigh)
htfBearishBOS = (htfLow < htfPrevLow)

htfBullishCHoCH = (htfBearishBOS and (htfHigh > htfPrevHigh))
htfBearishCHoCH = (htfBullishBOS and (htfLow < htfPrevLow))

// Higher Timeframe Order Blocks
htfBullishOB = (htfClose[2] < htfOpen[2]) and (htfClose > htfHigh[2])
htfBearishOB = (htfClose[2] > htfOpen[2]) and (htfClose < htfLow[2])

// Get lower timeframe structure
var float prevHigh = na
var float prevLow = na

prevHigh := (high[1] > high[2]) ? high[1] : prevHigh
prevLow := (low[1] < low[2]) ? low[1] : prevLow

bullishBOS = (high > prevHigh)
bearishBOS = (low < prevLow)

bullishCHoCH = (bearishBOS and (high > prevHigh))
bearishCHoCH = (bullishBOS and (low < prevLow))

// Order Blocks with Volume Confirmation
avgVolume = ta.sma(volume, 20) // 20-period average volume

bullishOB = (close[2] < open[2]) and (close > high[2]) and (volume > avgVolume)
bearishOB = (close[2] > open[2]) and (close < low[2]) and (volume > avgVolume)

// Confirm entries with HTF Order Blocks
htfOBConfluence = ((htfBullishOB and (close > htfLow)) or (htfBearishOB and (close < htfHigh)))

// Entry Confirmation with HTF Confluence
bullishEntry = (bullishOB and (low <= high[2]) and htfOBConfluence)
bearishEntry = (bearishOB and (high >= low[2]) and htfOBConfluence)

// Exit Targets
bullishExit = (bullishEntry and (high >= prevHigh))
bearishExit = (bearishEntry and (low <= prevLow))

// Plot HTF BOS & CHoCH
plotshape(htfBullishBOS, location=location.belowbar, color=color.green, style=shape.labelup, title="HTF Bullish BOS")
plotshape(htfBearishBOS, location=location.abovebar, color=color.red, style=shape.labeldown, title="HTF Bearish BOS")
plotshape(htfBullishCHoCH, location=location.belowbar, color=color.blue, style=shape.labelup, title="HTF Bullish CHoCH")
plotshape(htfBearishCHoCH, location=location.abovebar, color=color.orange, style=shape.labeldown, title="HTF Bearish CHoCH")

// Highlight Order Blocks
bgcolor(htfBullishOB ? color.green : na, transp=85)
bgcolor(htfBearishOB ? color.red : na, transp=85)
bgcolor(bullishOB ? color.green : na, transp=80)
bgcolor(bearishOB ? color.red : na, transp=80)

// Entry & Exit Alerts
alertcondition(bullishEntry, title="Bullish Entry", message="HTF Order Block Retest - Potential Long Entry")
alertcondition(bearishEntry, title="Bearish Entry", message="HTF Order Block Retest - Potential Short Entry")
alertcondition(bullishExit, title="Bullish Exit", message="Target Hit - Consider Exiting Long")
alertcondition(bearishExit, title="Bearish Exit", message="Target Hit - Consider Exiting Short")

// Plot Entry & Exit Signals
plotshape(bullishEntry, location=location.belowbar, color=color.green, style=shape.triangleup, title="Buy Signal")
plotshape(bearishEntry, location=location.abovebar, color=color.red, style=shape.triangledown, title="Sell Signal")
plotshape(bullishExit, location=location.abovebar, color=color.blue, style=shape.square, title="Exit Long")
plotshape(bearishExit, location=location.belowbar, color=color.purple, style=shape.square, title="Exit Short")

Pernyataan Penyangkalan

Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.