Market structure

Breaks of structure and changes of character from confirmed swing highs and lows.

Market structure from confirmed swing pivots (swing params as swing). The last unbroken swing high (low) is broken when the close (or the wick, break_on) passes it by max(floor_pct % × close, break_k × ATR); each pivot breaks once per direction. A break in the bias direction is a BOS, against it a CHoCH; the first break with no bias only sets the bias. Both levels broken on one candle: the candle's colour picks the one that counts. protected_level = the level whose break would flip the bias.

Market structure is a structure detector: it marks price structure on the chart and counts against the plan's detector limit.

Settings

SettingDefaultRangeWhat it does
atr_period141 to 500ATR length (Wilder) for every buffer.
swing_k20.1 to 20Swing reversal in ATRs: a pivot is confirmed when a close moves this far back.
swing_min_pct0.10 to 10Smallest swing reversal, % of the close.
break_oncloseclose, wickWhat must pass a swing level to break it.
break_k00 to 5A swing level is broken only this many ATRs beyond it.
floor_pct00 to 10Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple).

What it gives

OutputWhat it is
Bullish break of structureTrue on a bullish break of structure.
Bearish break of structureTrue on a bearish break of structure.
Bullish change of characterTrue on a bullish change of character.
Bearish change of characterTrue on a bearish change of character.
Bullish biasTrue while the structure bias is bullish.
Bearish biasTrue while the structure bias is bearish.
Protected levelThe swing level whose break flips the bias (a low in a bullish bias).

What it reads

It reads the whole candle (open, high, low, close and volume).

Warm-up

With its default settings, Market structure needs 241 closed candles before its first value. A backtest loads them before its start date, so the first trade can already use it.

Test it

Copy this sentence into the Algonney chat to backtest it:

Backtest a strategy on BTC that uses Market structure with its default settings