Market structure
Confirmed swings labelled HH, HL, LH and LL, with breaks of structure (BOS) and changes of character (CHoCH), for internal and swing structure.
Inputs
| Name | Type | Default | Range |
|---|---|---|---|
| swing_len | int | 5 | 2 to 100 |
| internal_len | int | 2 | 1 to 99 |
| internal | bool | true | |
| swing | bool | true | |
| confluence_filter | bool | false | |
| break_on | choice | close |
Outputs
| Name | Type | Required | Description |
|---|---|---|---|
| bos | event | Optional | color_down theme.down, color_up theme.up, shape circle, style marker, where above_bar |
| choch | event | Optional | color_down theme.down, color_up theme.up, shape triangle_up, style marker, where above_bar |
| internal_bos | event | Optional | color_down theme.down/0.60, color_up theme.up/0.60, shape circle, style marker, where above_bar |
| internal_choch | event | Optional | color_down theme.down/0.60, color_up theme.up/0.60, shape triangle_up, style marker, where above_bar |
| hh | value | Optional | color theme.up, shape triangle_down, shift -5, style marker, where above_bar |
| lh | value | Optional | color theme.down, shape triangle_down, shift -5, style marker, where above_bar |
| hl | value | Optional | color theme.up, shape triangle_up, shift -5, style marker, where below_bar |
| ll | value | Optional | color theme.down, shape triangle_up, shift -5, style marker, where below_bar |
| swing_high | value | Optional | color theme.down, dash dot, style step, width 1 |
| swing_low | value | Optional | color theme.up, dash dot, style step, width 1 |
| internal_high | value | Optional | color theme.accent, style line, width 1 |
| internal_low | value | Optional | color theme.accent, style line, width 1 |
| trend | value | Optional | color theme.accent, style line, width 1 |
| internal_trend | value | Optional | color theme.accent, style line, width 1 |
- Warm-up
- 2 * internal_len bars (4 at the defaults)
- Repaints
- Yes
- Parity
- None
Formula
A swing high is a bar whose high is above the high of every bar within swing_len bars on each side; a swing low mirrors it. Equal highs make no swing. A swing is known swing_len bars after it, and every value is written on that later bar; the chart draws the label back on the swing bar.
HH and LH mark a swing high above or below the previous one; HL and LL mark a swing low above or below the previous one.
A break happens on the first bar that closes above the latest swing high (break_on close) or trades above it (break_on wick). It is a change of character (CHoCH) when the trend was down, and a break of structure (BOS) otherwise; the trend then turns up and that level cannot break again. Breaks below the latest swing low mirror it. Values +1 are upward breaks and -1 downward.
Internal structure applies the same rule with internal_len. internal and swing turn each one on or off. With confluence_filter on, an internal break is marked only when its bar closes in the break's direction and the level it breaks is not the swing level. A missing bar starts the structure again.