//@version=5 strategy("Master 5:30 PM Sweep Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10) // Inputs session_time = input.session("1200-1400", title="Reference Session Time (UTC/Broker Time)") rr_ratio = input.float(2.0, title="Risk to Reward Ratio") buffer_ticks = input.int(5, title="Stop Loss Buffer (Ticks)") // Determine if we are inside the session in_session = not na(time(timeframe.period, session_time)) var float session_high = na var float session_low = na var float sweep_high = na var float sweep_low = na var string state = "idle" // "idle", "swept_high", "swept_low", "done" var int last_trade_day = -1 current_day = dayofweek // Reset session levels if in_session if not in_session[1] or current_day != current_day[1] session_high := high session_low := low state := "idle" else session_high := math.max(nz(session_high, high), high) session_low := math.min(nz(session_low, low), low) // Trade execution window (after reference session ends) after_session = not in_session and not na(session_high) and not na(session_low) // Avoid trading on weekends is_weekend = (dayofweek == sunday or dayofweek == saturday) if after_session and not is_weekend and state != "done" if state == "idle" if close > session_high state := "swept_high" sweep_high := high else if close < session_low state := "swept_low" sweep_low := low else if state == "swept_high" sweep_high := math.max(sweep_high, high) if close < session_high // Sweep high completed, close back inside -> Enter Short sl = sweep_high + (buffer_ticks * syminfo.mintick) risk = sl - close tp = close - (risk * rr_ratio) strategy.entry("Short Sweep", strategy.short) strategy.exit("Exit Short", "Short Sweep", stop=sl, limit=tp) state := "done" else if state == "swept_low" sweep_low := math.min(sweep_low, low) if close > session_low // Sweep low completed, close back inside -> Enter Long sl = sweep_low - (buffer_ticks * syminfo.mintick) risk = close - sl tp = close + (risk * rr_ratio) strategy.entry("Long Sweep", strategy.long) strategy.exit("Exit Long", "Long Sweep", stop=sl, limit=tp) state := "done" // Visualizing levels plot(after_session ? session_high : na, color=color.green, style=plot.style_line, title="Session High") plot(after_session ? session_low : na, color=color.red, style=plot.style_line, title="Session Low")