//@version=5 strategy("Modern Bearish Order Block with FVG", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // Inputs useFilter = input.bool(true, "Use EMA Trend Filter") emaPeriod = input.int(200, "EMA Period") tpMultiplier = input.float(2.0, "Risk-to-Reward Multiplier") // EMA Calculations emaVal = ta.ema(close, emaPeriod) isBearishTrend = not useFilter or (close < emaVal) // Bearish Order Block & FVG Detection (3-candle sequence) // Candle 2 (OB): Bullish Candle // Candle 1 (Engulfing): Bearish candle that engulfs the OB Candle's low // Candle 0: Bearish candle confirming the FVG isOB = (close[2] > open[2]) isEngulfing = (close[1] < open[1]) and (close[1] < low[2]) hasFVG = (low[2] > high[0]) var float obHigh = na var float obLow = na var float obSL = na var float obTP = na var bool pendingSetup = false // Set setup conditions when a valid pattern is identified if isBearishTrend and isOB and isEngulfing and hasFVG obHigh := high[2] obLow := low[2] obSL := obHigh + (obHigh - obLow) obTP := obLow - (tpMultiplier * (obHigh - obLow)) pendingSetup := true // Invalidate setup if price moves past our Stop Loss before hitting the Entry Level (High of OB) if pendingSetup and high > obSL pendingSetup := false // Entry Order logic if pendingSetup strategy.entry("OB_Sell_Limit", strategy.short, limit=obHigh, comment="Bearish OB Entry") // Exit Order management if strategy.position_size < 0 strategy.exit("OB_Exit", "OB_Sell_Limit", stop=obSL, limit=obTP, comment="OB Close") // Clear state when position is closed if strategy.position_size == 0 pendingSetup := false // Visualizations plot(pendingSetup ? obHigh : na, color=color.new(color.red, 0), linewidth=2, title="OB Entry (High)") plot(pendingSetup ? obSL : na, color=color.new(color.maroon, 0), linewidth=2, style=plot.style_line, title="OB Stop Loss") plot(pendingSetup ? obTP : na, color=color.new(color.green, 0), linewidth=2, style=plot.style_line, title="OB Take Profit")