// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © AI_PIPS //@version=6 indicator("AIPIPS Order Block Radar", overlay=true, max_lines_count=500, max_boxes_count=200) structureLookback = input.int(25, "Structure lookback", minval=5) scanDepth = input.int(12, "Candle scan depth", minval=1, maxval=50) minBodyPct = input.float(0.25, "Min body % of range", step=0.05) bodyPct(idx) => math.abs(close[idx] - open[idx]) / (high[idx] - low[idx] + 1e-6) bullishBreak = close > ta.highest(high[1], structureLookback) bearishBreak = close < ta.lowest(low[1], structureLookback) var float bullObHigh = na var float bullObLow = na var float bearObHigh = na var float bearObLow = na if bullishBreak bool found = false for i = 1 to scanDepth cond = close[i] < open[i] and bodyPct(i) >= minBodyPct if not found and cond bullObHigh := high[i] bullObLow := low[i] found := true if bearishBreak bool found = false for i = 1 to scanDepth cond = close[i] > open[i] and bodyPct(i) >= minBodyPct if not found and cond bearObHigh := high[i] bearObLow := low[i] found := true plotBullHigh = plot(bullObHigh, title="Bullish OB High", color=color.new(color.green, 0), linewidth=2, style=plot.style_linebr) plotBullLow = plot(bullObLow, title="Bullish OB Low", color=color.new(color.green, 50), linewidth=2, style=plot.style_linebr) plotBearHigh = plot(bearObHigh, title="Bearish OB High", color=color.new(color.red, 50), linewidth=2, style=plot.style_linebr) plotBearLow = plot(bearObLow, title="Bearish OB Low", color=color.new(color.red, 0), linewidth=2, style=plot.style_linebr) fill(plotBullHigh, plotBullLow, color=color.new(color.green, 80)) fill(plotBearHigh, plotBearLow, color=color.new(color.red, 80)) plotchar(bullishBreak, title="Bullish BOS", char="BOS↑", location=location.belowbar, color=color.green) plotchar(bearishBreak, title="Bearish BOS", char="BOS↓", location=location.abovebar, color=color.red)