indicator · on price · open source
Break of Structure (BOS) indicator
Break of Structure (BOS) is a free open-source indicator by @deepwick. Break of Structure (BOS) marks the bar where price takes out the previous swing high… Deepwick Script runs a subset of Pine Script.
Running…
Loading chart…
What Break of Structure (BOS) does
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
confirmClosefilter requires the candle to close beyond the level. - Use BOS, not random breakouts, to align with smart-money positioning.
- A BOS in the direction of the prevailing trend is a continuation signal; against the trend it is the precursor to a CHoCH.
- Default swing = 5 (works well on 1m–1h); raise to 10+ on daily charts for structural breaks.
- Pair with a higher-timeframe trend filter (HTF swing) for cleanest signals.
- A BOS that closes strongly (full body through the level) is far more reliable than one that only touches the level with its wick.
- Toggle the triangle markers off via
showArrowsif you want a cleaner chart.
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
indicator("Break of Structure (BOS)", overlay=true)
swing = input.int(5, "Swing Length", minval=2, maxval=50)
confirmClose = input.bool(true, "Confirm on Close")
upColor = input.string("color.green", "Bullish BOS Color")
dnColor = input.string("color.red", "Bearish BOS Color")
showArrows = input.bool(true, "Show Triangle Markers")
alertUp = input.bool(true, "Alert on Bullish BOS")
alertDn = input.bool(true, "Alert on Bearish BOS")
alertStrong = input.bool(false, "Alert on Strong BOS only")
alertStreak = input.bool(false, "Alert on BOS Streak (2+)")
markerSize = input.string("small", "Triangle Size")
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(showArrows and bosUp, "Bullish BOS", style=shape.triangleup, location=location.belowbar, color=upColor, text="BOS")
plotshape(showArrows and bosDn, "Bearish BOS", style=shape.triangledown, location=location.abovebar, color=dnColor, text="BOS")
alertcondition(bosUp, "Bullish BOS", "Bullish Break of Structure")
alertcondition(bosDn, "Bearish BOS", "Bearish Break of Structure")
alertcondition(bosUp and close > lastPh + (high - low), "Strong bullish BOS", "Strong bullish break — close beyond level by more than bar range")
alertcondition(bosDn and close < lastPl - (high - low), "Strong bearish BOS", "Strong bearish break — close beyond level by more than bar range")
alertcondition(bosUp and bosUp[1], "Bullish BOS streak", "Two consecutive bullish BOS prints")
alertcondition(bosDn and bosDn[1], "Bearish BOS streak", "Two consecutive bearish BOS prints")
No comments yet.
Sign in to comment.