//@version=5 strategy("Raghee Horner Box Theory Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // Inputs useSessionFilter = input.bool(true, title="Use Session Filter (Avoid First 15 Mins)") stochK_len = input.int(14, title="Slow Stochastic %K Length") stochD_len = input.int(3, title="Slow Stochastic %D Smoothing") stoch_smooth = input.int(3, title="Slow Stochastic %K Smoothing") // Previous Session Close (Daily Close) prev_session_close = request.security(syminfo.tickerid, "D", close[1], barmerge.lookahead_on, barmerge.gaps_off) // Opening Range / Box Construction (Yesterday's High and Low as primary box) yHigh = request.security(syminfo.tickerid, "D", high[1], barmerge.lookahead_on, barmerge.gaps_off) yLow = request.security(syminfo.tickerid, "D", low[1], barmerge.lookahead_on, barmerge.gaps_off) boxMid = (yHigh + yLow) / 2 // Plotting Box Boundaries p_high = plot(yHigh, title="Box Top (Resistance)", color=color.red, linewidth=2) p_low = plot(yLow, title="Box Bottom (Support)", color=color.green, linewidth=2) p_mid = plot(boxMid, title="Box Midline (50%)", color=color.gray, linewidth=1, style=plot.style_dashed) // Slow Stochastic Calculation k = ta.sma(ta.stoch(close, high, low, stochK_len), stoch_smooth) d = ta.sma(k, stoch_D_len) // Time Filter: Avoid first 15 minutes of US Session (09:30 - 09:45 EST) isFirst15Mins = (hour == 9 and minute < 45) tradingAllowed = not useSessionFilter or not isFirst15Mins // Strategy Logic: Range-Bound / Chop execution at extremes // Buy near support (Box Bottom) when oversold or price touches support and above/near previous session close // Sell near resistance (Box Top) when overbought or price touches resistance touchSupport = low <= yLow + (yHigh - yLow) * 0.02 touchResistance = high >= yHigh - (yHigh - yLow) * 0.02 longCondition = tradingAllowed and touchSupport and (close > prev_session_close) and (k < 30 or k > d) shortCondition = tradingAllowed and touchResistance and (close < prev_session_close) and (k > 70 or k < d) // Execution if (longCondition) strategy.entry("Box Buy", strategy.long) strategy.exit("Take Profit/Stop Loss", "Box Buy", limit=boxMid, stop=yLow - (yHigh - yLow) * 0.05) if (shortCondition) strategy.entry("Box Short", strategy.short) strategy.exit("Take Profit/Stop Loss", "Box Short", limit=boxMid, stop=yHigh + (yHigh - yLow) * 0.05)