DDDDXRPUSDT SPOTBITGET:XRPUSDTaektechnician91//@version=5 strategy("Order Block INTRADAY PRO", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // ===== Inputs ===== periods = input.int(5, "OB Strength") threshold = input.float(0.2, "Min % Move", step=0.1) rrRunner = input.float(3.0, "Runner RR") atrMult = input.float(1.2, "ATR SL Multiplier") // ===== HTF Trend (4H EMA Filter) ===== htfClose = request.security(syminfo.tickerid, "240", close) htfEMA = request.security(syminfo.tickerid, "240", ta.ema(close, 50)) bullTrend = htfClose > htfEMA bearTrend = htfClose < htfEMA // ===== OB Detection ===== ob_period = periods + 1 absmove = math.abs(close - close) / close * 100 relmove = absmove >= threshold // Bullish OB bullishOB = close < open upcandles = 0 for i = 1 to periods upcandles += close > open ? 1 : 0 OB_bull = bullishOB and upcandles == periods and relmove OB_bull_high = OB_bull ? open : na OB_bull_low = OB_bull ? low : na OB_bull_avg = (OB_bull_high + OB_bull_low)/2 // Bearish OB bearishOB = close > open downcandles = 0 for i = 1 to periods downcandles += close < open ? 1 : 0 OB_bear = bearishOB and downcandles == periods and relmove OB_bear_high = OB_bear ? high : na OB_bear_low = OB_bear ? open : na OB_bear_avg = (OB_bear_high + OB_bear_low)/2 // ===== Store Latest OB ===== var float lastBullLow = na var float lastBullAvg = na var bool bullTraded = false var float lastBearHigh = na var float lastBearAvg = na var bool bearTraded = false if OB_bull lastBullLow := OB_bull_low lastBullAvg := OB_bull_avg bullTraded := false if OB_bear lastBearHigh := OB_bear_high lastBearAvg := OB_bear_avg bearTraded := false // ===== ATR Dynamic Stop ===== atr = ta.atr(14) // ===== Long Entry ===== touchBull = not na(lastBullAvg) and low open and close < open and close > open longCondition = touchBull and bullTrend and bullEngulf and not bullTraded if longCondition and strategy.position_size == 0 stopLoss = close - atr * atrMult risk = close - stopLoss strategy.entry("LONG", strategy.long) // Partial TP 50% at 1R strategy.exit("TP1 LONG", from_entry="LONG", qty_percent=50, limit=close + risk) // Runner 50% at RR strategy.exit("TP2 LONG", from_entry="LONG", qty_percent=50, limit=close + risk * rrRunner, stop=stopLoss) bullTraded := true // ===== Short Entry ===== touchBear = not na(lastBearAvg) and high >= lastBearAvg bearEngulf = close < open and close > open and close < open shortCondition = touchBear and bearTrend and bearEngulf and not bearTraded if shortCondition and strategy.position_size == 0 stopLoss = close + atr * atrMult risk = stopLoss - close strategy.entry("SHORT", strategy.short) strategy.exit("TP1 SHORT", from_entry="SHORT", qty_percent=50, limit=close - risk) strategy.exit("TP2 SHORT", from_entry="SHORT", qty_percent=50, limit=close - risk * rrRunner, stop=stopLoss) bearTraded := true