// 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 Range Build-Up Analyzer", overlay=true, max_boxes_count=200) window = input.int(30, "Range window", minval=5) atrLen = input.int(14, "ATR length", minval=1) compressionPct = input.float(1.2, "Max range %", step=0.1) atr = ta.atr(atrLen) windowHigh = ta.highest(high, window) windowLow = ta.lowest(low, window) rangePct = (windowHigh - windowLow) / nz(close == 0 ? na : close) * 100 inRange = rangePct <= compressionPct and atr < ta.sma(atr, atrLen) and ta.barssince(close > windowHigh) > 1 and ta.barssince(close < windowLow) > 1 var box rangeBox = na if inRange if na(rangeBox) rangeBox := box.new(bar_index - window, windowHigh, bar_index, windowLow, bgcolor=color.new(color.yellow, 90), extend=extend.right) else box.set_right(rangeBox, bar_index) box.set_top(rangeBox, windowHigh) box.set_bottom(rangeBox, windowLow) else box.delete(rangeBox) rangeBox := na plot(windowHigh, title="Range high", color=color.new(color.orange, 30), style=plot.style_linebr) plot(windowLow, title="Range low", color=color.new(color.orange, 30), style=plot.style_linebr) plotchar(inRange, title="Range state", char="R", location=location.top, size=size.tiny, color=color.orange)