indicator · on price · open source

Break of Structure (BOS)

Deepwick · @deepwickv1Updated 2 Oct 2026▲ 0 users
Running…
Loading chart…

About

Break of Structure (BOS) marks the bar where price takes out the previous swing high (bullish) or swing low (bearish) in the direction of the prevailing trend.

  • Bullish BOS = new high beyond the last swing high; bearish BOS = new low beyond the last swing low.
  • Triangles plot on break; an optional confirmClose filter requires the candle to close beyond the level.
  • Use BOS, not random breakouts, to align with smart-money positioning.

Source code

//@version=5
indicator("Break of Structure (BOS)", overlay=true)
swing = input.int(5, "Swing Length", minval=2, maxval=50)
confirmClose = input.bool(true, "Confirm on Close")
ph = ta.pivothigh(high, swing, swing)
pl = ta.pivotlow(low, swing, swing)
var float lastPh = na
var float lastPl = na
if not na(ph)
    lastPh := ph
if not na(pl)
    lastPl := pl
bosUp = confirmClose ? close > lastPh : high > lastPh
bosDn = confirmClose ? close < lastPl : low < lastPl
bosUp := bosUp and not bosUp[1]
bosDn := bosDn and not bosDn[1]
plotshape(bosUp, "Bullish BOS", style=shape.triangleup, location=location.belowbar, color=color.green, text="BOS")
plotshape(bosDn, "Bearish BOS", style=shape.triangledown, location=location.abovebar, color=color.red, text="BOS")
alertcondition(bosUp, "Bullish BOS", "Bullish Break of Structure")
alertcondition(bosDn, "Bearish BOS", "Bearish Break of Structure")

Comments

No comments yet.

Sign in to comment.