Indicators··7 min read

Swing Structure & Break of Structure (BOS) / Change of Character (CHoCH) Marker

0 references, link-verified · inline [n] markersEditor of record: Shane CantyStandards review editorial standard · audit log

Institutional traders use swing structure analysis to identify key price levels and reversal zones. This indicator marks swing highs and lows, then labels when price breaks a previous swing level (BOS) or when the pattern of swings inverts (CHoCH). It helps traders spot potential shifts in market direction without repaint, using only confirmed, lookback-verified structure.

//@version=6
indicator("Swing Structure & BOS/CHoCH", overlay=true)

// Inputs
lookback = input(5, "Swing Confirmation Bars", minval=2)
showSwings = input(true, "Show Swings")
showBOS = input(true, "Show BOS")
showCHoCH = input(true, "Show CHoCH")
lineExtend = input(100, "Extended Line Length (bars)", minval=0)

// Confirmed swing high/low from lookback bars ago (prevents repaint)
swingConfirmBars = lookback * 2 + 1
isSwingHigh = high[lookback] == ta.highest(high, swingConfirmBars)
isSwingLow = low[lookback] == ta.lowest(low, swingConfirmBars)

swingH = isSwingHigh ? high[lookback] : na
swingL = isSwingLow ? low[lookback] : na

// Track swing history
var array<float> highs = array.new<float>()
var array<float> lows = array.new<float>()
var array<int> highBars = array.new<int>()
var array<int> lowBars = array.new<int>()

// Append new swings, keep last 10
if isSwingHigh
    array.push(highs, swingH)
    array.push(highBars, bar_index[lookback])
    if array.size(highs) > 10
        array.shift(highs)
        array.shift(highBars)

if isSwingLow
    array.push(lows, swingL)
    array.push(lowBars, bar_index[lookback])
    if array.size(lows) > 10
        array.shift(lows)
        array.shift(lowBars)

// Get most recent swings
recentHigh = array.size(highs) > 0 ? array.get(highs, array.size(highs) - 1) : na
recentLow = array.size(lows) > 0 ? array.get(lows, array.size(lows) - 1) : na
priorHigh = array.size(highs) > 1 ? array.get(highs, array.size(highs) - 2) : na
priorLow = array.size(lows) > 1 ? array.get(lows, array.size(lows) - 2) : na

// Break of Structure: close crosses above/below a confirmed swing
bosHigh = not na(recentHigh) and close > recentHigh and close[1] <= recentHigh
bosLow = not na(recentLow) and close < recentLow and close[1] >= recentLow

// Change of Character: pattern inverts (e.g., higher highs become lower highs)
choch = false
if array.size(highs) >= 2 and array.size(lows) >= 2
    if (recentHigh < priorHigh and recentLow > priorLow)
        choch := true
    if (recentHigh > priorHigh and recentLow < priorLow)
        choch := true

// Plotting
if showSwings
    if isSwingHigh
        plotshape(swingH, "Swing High", shape.diamond, location.abovebar, color.new(color.lime, 0), size=size.small)
    if isSwingLow
        plotshape(swingL, "Swing Low", shape.diamond, location.belowbar, color.new(color.red, 0), size=size.small)

if showBOS
    if bosHigh
        line.new(bar_index - 1, recentHigh, bar_index + lineExtend, recentHigh, extend=extend.right, color=color.new(color.orange, 20), width=2, style=line.style_dashed)
        plotshape(recentHigh, "BOS ↑", shape.flag, location.abovebar, color.orange, size=size.small)
    if bosLow
        line.new(bar_index - 1, recentLow, bar_index + lineExtend, recentLow, extend=extend.right, color=color.new(color.orange, 20), width=2, style=line.style_dashed)
        plotshape(recentLow, "BOS ↓", shape.flag, location.belowbar, color.orange, size=size.small)

if showCHoCH and choch
    plotshape(na, "CHoCH", shape.cross, location.top, color.new(color.purple, 0), size=size.large)
    alert("Change of Character Detected")

How the code works

The indicator looks back a fixed window (default 5 bars on each side) to confirm swing highs and lows only after they are formed. This prevents repainting: a bar is marked as a swing high only if it is the highest in its 5-bar window before and after, a confirmation that has already occurred.

Each confirmed swing is appended to a rolling array (keeping the last 10 for memory). When the current bar's close crosses above the most recent swing high, a BOS is triggered: an orange dashed line extends to the right at that level with a flag marker. The same logic applies for breaks below swing lows.

Change of Character is detected when the pattern of recent swings inverts. If the last swing high is lower than the prior swing high AND the last swing low is higher than the prior swing low, the structure has rotated from an uptrend pattern to a downtrend pattern, or vice versa. This is marked with a purple cross at the top of the chart.

All conditions (BOS and CHoCH) depend on close crossing the level and not being at it the prior bar, ensuring the signal fires only once per event.

Reading it on a chart

Swing highs appear as green diamonds above their bars; swing lows as red diamonds below. These mark local extremes that traders often hold as key support and resistance.

When price closes beyond a swing level on a single bar, an orange dashed line appears at that level and extends forward. This is the Break of Structure: the level has been breached and will likely no longer act as support or resistance. Traders often treat BOS as a directional commitment; a BOS above a swing high may signal the start of a bullish impulse, while a BOS below a swing low may signal a bearish impulse.

A purple cross at the chart top signals a Change of Character. This occurs when the most recent swing high is lower than the prior swing high while the most recent swing low is higher than the prior swing low, or when the inverse happens. CHoCH often precedes a reversal or consolidation; the "character" of the market has shifted from making a series of higher highs and higher lows (uptrend) to making a series of lower highs and lower lows (downtrend), or sideways.

The Extended Line Length input controls how far the dashed BOS lines project forward; longer lines make key levels more visible.

Limitations

The indicator's accuracy depends entirely on the lookback period. A 5-bar lookback may miss finer structure but reduces false positives; a 2-bar lookback is sensitive to every small local extremum, producing noise. No universal setting suits all timeframes or assets.

Swing highs and lows are mechanical: a price is a swing simply because it is the highest or lowest in its window. This ignores volume, volatility regime, or whether the swing was formed on a wick or body. A wick spike that touches an extreme bar still counts as a swing, and price may not respect it in the next cycle.

BOS and CHoCH are purely structural signals; they do not measure momentum, time, or context. A BOS can occur on low volume or in a ranging market where the break is immediately reversed. CHoCH may signal confusion rather than a committed reversal.

The indicator does not label swing patterns (doubletops, H&S, impulses) or distinguish between impulsive and corrective swings. It also does not track higher timeframe structure, so a BOS on a 1-minute chart may be noise if the 4-hour structure remains intact.

Confirmation bias is a risk: traders may anchor to CHoCH labels and misinterpret them as reversal signals when the market is still in a larger uptrend or downtrend.

Key definitions

Swing High: A price bar whose close (or high) is higher than the high of every bar within a fixed lookback window on both sides.

Swing Low: A price bar whose close (or low) is lower than the low of every bar within a fixed lookback window on both sides.

Break of Structure (BOS): The event when price closes beyond a previously formed swing high or swing low, indicating that level has been violated and is no longer a local extremum.

Change of Character (CHoCH): A shift in the pattern of swings such that the recent swing high is lower than the prior swing high while the recent swing low is higher than the prior swing low, or vice versa; signals a reversal in the swing structure.

Lookback Period: The number of bars before and after a potential swing used to confirm that bar as a local extremum; prevents repainting by ensuring the extremum is already in the past.

Support and Resistance: A swing low acts as support (a level buyers defend); a swing high acts as resistance (a level sellers defend). A BOS suggests one or both roles have been broken.

Repaint: When a signal recalculates and changes its result as new bars form; avoided here by using a fixed lookback to confirm swings only after they are already in history.

References


Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.

Last reviewed by the PropLedger research pipeline: 2026-11-08. Educational research on historical data, not financial advice.

Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard. Found an error? Email support@prop-ledger.org and the paper is corrected or withdrawn.