//@version=6 indicator("Simplified two-session swings", overlay = true) start = input.time(timestamp("01 Jan 2025 00:00 +0000"), "First eligible close time") initialUp = input.bool(true, "Initial direction up") if not timeframe.isdaily runtime.error("Use daily bars") var bool up = initialUp var int streak = 0 var float extreme = na var float turn = na turn := na inside = high <= high[1] and low >= low[1] outside = high > high[1] and low < low[1] if barstate.isconfirmed and time_close >= start if na(extreme) extreme := up ? high : low else opposing = up ? low < low[1] : high > high[1] if inside streak := 0 else streak := opposing ? streak + 1 : 0 if streak >= 2 turn := extreme up := not up extreme := up ? high : low streak := 0 else extreme := up ? math.max(extreme, high) : math.min(extreme, low) plot(turn, "Confirmed prior extreme", color.black, linewidth = 3, style = plot.style_circles) bgcolor(outside and barstate.isconfirmed ? color.new(color.gray, 90) : na)