Trading Dev AcademyFree quant education

Free lesson · Technical analysis

Market structure, BOS and CHOCH as a state machine

Open interactive lessonPractice calculationsExplore labs

Start with the idea

Market structure summarizes a sequence of swings. A state machine makes its transitions explicit instead of relabeling the chart after the outcome.

Symbols, units & horizon
  • i: index of the proposed pivot
  • k: number of right-side bars required for confirmation
  • t_known: first index where confirmation is available
  • C_t: completed current close
  • H*,L*: last applicable confirmed high and protected low in a pre-existing up-state
  • 1{ }: binary condition flag

When and why to use this

Use structure transitions as causal state features or event-study labels, joined to separately specified entries, exits and sizing.

  • Define confirmed highs and lows first. A pivot with k bars required on its right becomes known k bars after the extremum.
  • A simple up-state requires confirmed higher highs and higher lows; a down-state uses lower highs and lower lows. Otherwise label neutral/uncertain.
  • BOS = break of structure, commonly in the established direction. CHOCH = change of character, commonly a break opposing that direction. These labels are not universally standardized.
  • For this lesson, an up-state close above the last confirmed high is bullish BOS. A close below the protected confirmed low is bearish CHOCH. Mirror the definitions in a down-state.
  • Use completed-close breaks with an optional prior-volatility buffer. A wick-through variant is a separate detector.
  • Specify which low is “protected,” what happens after CHOCH and how re-entry into a trend is confirmed. A warning flag need not immediately reverse the state.
  • Preserve event timestamps, breached level IDs and every state transition. Labels plotted at historical extrema must not imply earlier knowledge.
tknown=i+k,BOStup=𝟏{Ct>H∗},CHOCHtdown=𝟏{Ct<L∗}
Specified chart rule · derivation and arithmetic

Market structure, BOS and CHOCH as a state machine

  1. A pivot at index 10 with k=2 is first known at index 12.
  2. In an up-state with H*=110 and L*=104, close=111 triggers bullish BOS.
  3. Close=103 instead triggers the specified bearish CHOCH flag. Neither flag defines the entire subsequent trade by itself.
Work it by hand

Close=108 triggers neither event. If the supposed protected low was only confirmed tomorrow, it cannot be used today.

Use the rule

  • Fix the definition, units and information timestamp.
  • Compute the example and inspect the graph.
  • Compare with a simple baseline on untouched periods after costs.

Before moving on

Write the exact rule, its availability time, an invalidation condition and a fair out-of-sample test.

From chart labels to a research table

  • Store one row per completed decision time: instrument, venue, bar end, confirmed pivot IDs, prior state, level distance, trigger and feature version.
  • Add returns only after the stated outcome horizon matures. Track all candidates, failed signals and expired zones.
  • Start with a rule-only or simple statistical baseline. Then compare numerical features, shapelets and learned representations under the same split, horizon and costs.
  • FVG, BOS, CHOCH, Gann and harmonic terminology varies. This targeted research review did not establish a universally profitable implementation of these named conventions. Treat them as testable hypotheses.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

def structure_flags(close,confirmed_high,protected_low,state="up"):
    if confirmed_high<=protected_low or state not in ("up","down"): raise ValueError("Ordered levels and explicit state required")
    if state=="up": return {"bos":close>confirmed_high,"choch":close<protected_low}
    return {"bos":close<protected_low,"choch":close>confirmed_high}

print(structure_flags(111,110,104))

Continue learning

Technical Analysis: Geometry, Structure & Evidence — all lessons
  1. Support, resistance and reversal: start with a price zone
  2. Breakout detection, false breaks and retests
  3. Fibonacci retracements: anchors before ratios
  4. Harmonic patterns: ratio constraints and competing candidates
  5. Elliott Wave: count hypotheses, rules and invalidation
  6. Fair value gaps (FVG): three-bar geometry and fill measurement
  7. Heikin-Ashi: smoothed candles are synthetic prices
  8. Renko: price-driven bricks and the missing time axis
  9. Dynamic support, trend lines and Gann angles
  10. Momentum indicators, oscillators and divergence
  11. Volume, supply/demand zones and what OHLCV cannot reveal
  12. Market structure, BOS and CHOCH as a state machine
  13. Moon phases: encode a calendar hypothesis and try to falsify it

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations