Pivot-based definitions of Break of Structure and Change of Character that turn 'structure' from a retrospective story into a testable condition.
Break of Structure (BOS) and Change of Character (CHoCH) are terms from the 'smart money concepts' vocabulary for describing swing behavior. The difference between them is directional context: a BOS is a break of a swing point in the same direction as the prevailing structure — price in a sequence of higher highs and higher lows breaking above the latest swing high is a bullish BOS, read as trend continuation. A CHoCH is the first break of a swing point against the prevailing direction — that same uptrend breaking below its latest swing low — read as a possible shift in character. The problem is that most definitions are applied by eye, after the fact: two people can label the same chart differently because 'swing' and 'prevailing structure' were never pinned down. The terms only become useful when they are made deterministic: fix a pivot rule for what counts as a swing, track direction with an explicit state, and BOS/CHoCH become computable, testable events. Either way they are descriptions of what price has already done, not predictions. This is educational material, not financial advice, and all trading carries risk of loss.
A deterministic version starts with pivots: a swing high is a bar whose high exceeds the highs of the N bars on each side, and a swing low is the mirror image. Crucially, such a pivot is only confirmed N bars after it forms — that lag is unavoidable and honest implementations accept it rather than hiding it. The algorithm keeps the most recent confirmed swing high and swing low, plus a direction state: +1 after the last upside break, -1 after the last downside break. When the close crosses above the stored swing high, the event is a BOS if the state is already +1 (continuation) and a CHoCH if it is not (first counter-directional break); the state then flips to +1. Downside breaks mirror this. Every label is now reproducible: given the same chart, the same pivot length, and the same break rule (close-based versus wick-based), everyone gets the same BOS and CHoCH marks. Changing the pivot length changes every label — which is the point: the parameters are explicit and their sensitivity can be studied, instead of being absorbed invisibly into a discretionary reading.
Pivot length of 5 bars each side is a common starting point; 3 gives fast, noisy minor structure and 8-10 gives slower major structure. Close-based break detection is stricter than wick-based. Labels should be evaluated on confirmed bars only. There is no correct setting — only stated ones whose behavior you have examined on your market and timeframe.
//@version=6
indicator("Pivot-Based BOS & CHoCH", overlay = true)
len = input.int(5, "Pivot Length (bars each side)", minval = 1)
ph = ta.pivothigh(high, len, len)
pl = ta.pivotlow(low, len, len)
var float lastSwingHigh = na
var float lastSwingLow = na
if not na(ph)
lastSwingHigh := ph
if not na(pl)
lastSwingLow := pl
// Direction state: +1 after an upside break, -1 after a downside break
var int dir = 0
upCross = ta.crossover(close, lastSwingHigh)
dnCross = ta.crossunder(close, lastSwingLow)
brokeUp = not na(lastSwingHigh) and upCross
brokeDn = not na(lastSwingLow) and dnCross
bosUp = brokeUp and dir == 1 and barstate.isconfirmed
chochUp = brokeUp and dir != 1 and barstate.isconfirmed
bosDn = brokeDn and dir == -1 and barstate.isconfirmed
chochDn = brokeDn and dir != -1 and barstate.isconfirmed
if brokeUp
dir := 1
if brokeDn
dir := -1
plotshape(bosUp, "BOS up", style = shape.labelup, location = location.belowbar, color = color.teal, text = "BOS")
plotshape(chochUp, "CHoCH up", style = shape.labelup, location = location.belowbar, color = color.blue, text = "CHoCH")
plotshape(bosDn, "BOS down", style = shape.labeldown, location = location.abovebar, color = color.maroon, text = "BOS")
plotshape(chochDn, "CHoCH down", style = shape.labeldown, location = location.abovebar, color = color.gray, text = "CHoCH")Pro tip: Write your structure rules down before looking at the chart — pivot length, wick or close breaks, confirmed bars only — then let the code label everything, including the ugly ranges. If a structure concept only 'works' when you get to choose which swings count after seeing the outcome, that is hindsight, not analysis. Deterministic labels make the concept testable; they do not make it predictive. Educational content only, not financial advice, and all trading carries risk of loss.
Educational only — not financial advice, not a recommendation to trade. No indicator is predictive; trading involves substantial risk of loss.