//@version=5 strategy("Simplest Range & Swing Reversal Strategy 2026", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // Strategy Inputs rr_ratio = input.float(2.0, title="Risk to Reward Ratio", minval=1.0, step=0.1) swing_lookback = input.int(20, title="Swing High/Low Lookback Bars", minval=5) level_tolerance = input.float(0.3, title="Level Tolerance (%)", minval=0.0, step=0.1) / 100.0 // Previous Day Levels (Range High & Range Low) pdh = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on) pdl = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on) // Swing Levels swing_high = ta.highest(high, swing_lookback)[1] swing_low = ta.lowest(low, swing_lookback)[1] // Visual Plotting of Key Levels plot(pdh, title="Previous Day High (PDH)", color=color.red, linewidth=2, style=plot.style_line) plot(pdl, title="Previous Day Low (PDL)", color=color.green, linewidth=2, style=plot.style_line) plot(swing_high, title="Swing High", color=color.orange, linewidth=1, style=plot.style_line) plot(swing_low, title="Swing Low", color=color.teal, linewidth=1, style=plot.style_line) // Proximity Detection logic is_at_resistance(price) => (math.abs(price - pdh) / pdh <= level_tolerance or price >= pdh) or (math.abs(price - swing_high) / swing_high <= level_tolerance or price >= swing_high) is_at_support(price) => (math.abs(price - pdl) / pdl <= level_tolerance or price <= pdl) or (math.abs(price - swing_low) / swing_low <= level_tolerance or price <= swing_low) at_resistance_setup = is_at_resistance(high[1]) at_support_setup = is_at_support(low[1]) // Signal Conditions // Bullish Reversal: Previous bar touched/tested support and closed bullish, current bar breaks above setup bar's high bullish_setup = at_support_setup and close[1] > open[1] long_trigger = bullish_setup and close > high[1] and strategy.position_size == 0 // Bearish Reversal: Previous bar touched/tested resistance and closed bearish, current bar breaks below setup bar's low bearish_setup = at_resistance_setup and close[1] < open[1] short_trigger = bearish_setup and close < low[1] and strategy.position_size == 0 // Variables to store SL var float long_sl = na var float short_sl = na // Trade Execution Logic if long_trigger long_sl := math.min(low[1], low) entry_price = close risk = entry_price - long_sl if risk > 0 tp = entry_price + (risk * rr_ratio) strategy.entry("Long", strategy.long) strategy.exit("Exit Long", "Long", stop=long_sl, limit=tp) if short_trigger short_sl := math.max(high[1], high) entry_price = close risk = short_sl - entry_price if risk > 0 tp = entry_price - (risk * rr_ratio) strategy.entry("Short", strategy.short) strategy.exit("Exit Short", "Short", stop=short_sl, limit=tp)