// 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 Breaker Structure Mapper", overlay=true, max_labels_count=500) swingLen = input.int(6, "Swing length", minval=1) confirmBars = input.int(2, "Confirmation bars", minval=1) htf = input.timeframe("240", "Higher timeframe") htfTrend = request.security(syminfo.tickerid, htf, ta.ema(close, 50)) ph = ta.pivothigh(high, swingLen, swingLen) pl = ta.pivotlow(low, swingLen, swingLen) prevPH = ta.valuewhen(not na(ph), ph, 1) prevPL = ta.valuewhen(not na(pl), pl, 1) bosUp = not na(prevPH) and ta.barssince(not na(ph)) <= confirmBars and close > prevPH bosDown = not na(prevPL) and ta.barssince(not na(pl)) <= confirmBars and close < prevPL plotshape(bosUp, title="Bullish BOS", text="BOS↑", style=shape.labelup, color=color.new(color.green, 0), location=location.belowbar) plotshape(bosDown, title="Bearish BOS", text="BOS↓", style=shape.labeldown, color=color.new(color.red, 0), location=location.abovebar) var line lastBullLine = na var line lastBearLine = na if bosUp line.delete(lastBullLine) lastBullLine := line.new(bar_index - confirmBars, nz(prevPH), bar_index, nz(prevPH), extend=extend.right, color=color.new(color.green, 50)) if bosDown line.delete(lastBearLine) lastBearLine := line.new(bar_index - confirmBars, nz(prevPL), bar_index, nz(prevPL), extend=extend.right, color=color.new(color.red, 50)) trendBias = close > htfTrend ? "HTF Bull" : close < htfTrend ? "HTF Bear" : "HTF Neutral" var string prevBias = "" if trendBias != prevBias label.new(bar_index, high, text=trendBias, color=color.new(color.gray, 85), style=label.style_label_down, textcolor=color.gray, size=size.tiny) prevBias := trendBias