Break of Structure (BOS) in Pine Script
A close through the last confirmed swing high or low: in the trend's direction it is a break of structure that continues the sequence, against it a change of character that starts to reverse it.
Definition
A break of structure (BOS) is the moment price trades through the most recent confirmed swing in the direction of the prevailing trend: a close above the last swing high in an uptrend, or below the last swing low in a downtrend. It belongs to the swing structure family and is the trigger event of the market-structure read. The smart-money vocabulary pairs it with the change of character (CHoCH), which is the same close through a swing but against the trend: the first break of a higher low in an uptrend, or of a lower high in a downtrend.
The event matters because a swing is where one side of the market last won. A swing high in an uptrend is where sellers stopped the previous leg; a close through it shows buyers absorbed that supply and the sequence of higher highs continues. A close through the last higher low shows the buyers who defended it have been overrun. That is why a BOS confirms and a CHoCH warns. The same mechanical test, a close beyond a confirmed swing, carries opposite meaning depending on which swing it breaks and which way the trend was running.
The labels come from the smart-money and ICT schools of the 2010s, but the underlying rule is Dow's: a trend continues until the pattern of peaks and troughs fails. The standard settings are the swing definition itself, typically 5 bars either side of a turn, and the break rule, where most traders demand a close beyond the swing rather than a wick. Some schools count only the body close, some accept any trade through the level, and the choice decides how many false breaks the method will show.
On the chart, expect breaks to arrive in clusters in a trend and to look identical whether they continue or reverse. The implementation draws the last confirmed swing high and low as stepped lines. It marks Long on a close above the high line and Short on a close below the low line, and leaves the classification to the reader. The same Long mark is a BOS after a run of higher highs and a CHoCH after a run of lower highs. Expect the lines to step only when a new swing confirms, several bars after the turn.
Reading the chart
A break is only readable against the sequence it breaks, so the trend read comes before the break.
- Establish the prevailing sequence first. Read the last few confirmed swings: HH and HL mean the trend is up, LH and LL mean it is down. Without this step every break looks the same.
- Find the protected swing. In an uptrend it is the last higher low, the level the trend has to hold; in a downtrend it is the last lower high. The last swing in the trend direction is the continuation level.
- Wait for a close beyond a swing, not a wick. A bar that trades through the level and closes back inside is a sweep, and sweeps of the protected swing are common before the trend resumes.
- Classify the break. A close through the continuation level is a BOS and confirms the trend; a close through the protected swing is a CHoCH and is the first evidence of a reversal.
- After a CHoCH, wait for the new sequence to prove itself. The reversal is only established once price makes a swing in the new direction and then breaks it: the first BOS of the new trend.
- Note the confirmation delay. The swing line only steps to a new swing a set number of bars after the turn, so a break that happens during the wait is measured against the older level.
The maths
The test is a close compared with the last confirmed swing of the relevant kind, with the trend read deciding what the break means.
The break uses the close, so a wick through the swing does not count. That filters most sweeps but confirms a bar later than a wick rule would.
Only the most recent swing of each kind is held. Once a new swing confirms, the line steps to it and an older level no longer produces a break, even if it was the more important one.
Because swings confirm late, a strong move can pass through a fresh swing before the line has stepped to it; the break is then measured against the previous level and no second mark is drawn.
The implementation marks every close through a swing line as Long or Short without a trend read. Classifying a mark as BOS or CHoCH is done from the label sequence that precedes it.
Inputs that matter
| Input | Typical | What changing it does |
|---|---|---|
| Bars left of a pivot | 5 | Larger values make swings scarcer and more important, so breaks are rarer and more meaningful; smaller values produce frequent minor breaks. |
| Bars right of a pivot | 5 | Sets how long a swing takes to confirm and therefore how quickly the break level updates after a new turn. |
| Break rule | close through the level | A close rule ignores sweeps and signals later; a wick rule signals on the first trade through the level and includes every failed probe. |
| Show structure breaks | on | Draws the Long and Short marks on the break bars. The alert switch, off by default, fires the same events once per bar close. |
In practice
- As a continuation trigger: in an uptrend, a BOS above the last higher high confirms the sequence, and the pullback that follows toward the new higher low is the entry, with the stop below it.
- As the first reversal warning: a CHoCH through the protected swing switches the read from trend to caution. Position rules stop adding in the old direction and look for the new sequence to form.
- As a stop-loss logic: a long is wrong when the structure that justified it breaks, so the stop sits under the last higher low. When that swing is broken by a close, the trade is exited by definition.
- As confirmation for a level: a break above a swing high that coincides with a prior period high or a volume-weighted line carries more weight than a break of the swing alone.
- As a scan across timeframes: a CHoCH on the hourly chart inside a daily uptrend is often the end of a pullback, and the next hourly BOS in the daily direction is the resumption entry.
- As an alert stream: switch the alerts on and let the script report every close through the last swing, then classify each alert against the label sequence before acting on it.
Where it goes wrong
- Trading every break as a reversal. A break in the trend direction continues the trend; only the break of the protected swing is a change of character.
- Counting a wick as a break. Price often probes through a swing and closes back inside, especially at obvious lows; wait for the close, or for a retest, before treating the level as broken.
- Calling a reversal on the first CHoCH. It is evidence, not proof; the reversal is confirmed when the new sequence makes its own swing and breaks it.
- Forgetting the swing lag. The line steps a set number of bars after each turn, so during the wait the script measures breaks against the previous swing, and a fast move can outrun it.
Compared with
Market Structure. Market structure is the sequence of tagged swings; a break of structure is a single close through one of those swings. The sequence decides whether a given break confirms the trend or starts to reverse it.
Breakout. A breakout is a move out of a defined range or channel, measured against the range's edges. A break of structure is measured against one confirmed swing and carries a trend meaning that a range breakout does not have on its own.
Donchian Channels. A Donchian break is a close beyond the highest high of a fixed number of bars, so the level moves with the lookback. A structure break uses the confirmed swing, which stays fixed until the next swing forms, however many bars pass.
Swing Highs & Lows. The swing is the level; the break is the event. How a swing is defined, and how many bars it takes to confirm, sets where the break line sits and how far behind price it can lag.
Build it in Quant
Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.
Questions
What is the difference between BOS and CHoCH?
Both are a close through the last confirmed swing. A BOS breaks the swing in the direction of the prevailing trend, a higher high in an uptrend, and confirms it. A CHoCH breaks the swing the trend was protecting, the last higher low in an uptrend, and is the first sign of a reversal. The mechanics are identical; the meaning comes from which swing broke.
Should a break be judged on the close or the wick?
Most traders use the close, because wicks through obvious swing levels are common and often reverse. The implementation uses the close and only on confirmed bars, so it never marks a break that a later tick would undo. The cost is a later signal; a wick rule reacts sooner but includes every sweep.
Does one CHoCH mean the trend has reversed?
No. It means the level the trend depended on has given way. The new trend is established when price makes a swing in the new direction and then breaks it, the first BOS of the new sequence. Until then, the CHoCH can turn out to be a deep pullback that the old trend absorbs.
Why did the script not mark a break I can see on the chart?
Usually because of the confirmation delay. The swing line steps to a new turn only after the right-side bars have printed. If price broke the fresh swing before it confirmed, the script measured the move against the older level and may already have marked that, or not crossed it at all.
Which timeframe should I read breaks on?
A with-trend rule reads the trend on the timeframe above and takes breaks on the trading timeframe in that direction. An hourly CHoCH inside a daily uptrend usually marks the end of a pullback, and the next hourly BOS upward is the continuation entry. Breaks read on one timeframe alone flip too often to carry weight.
How do I turn a break of structure into a strategy?
Start from the implementation, which marks Long on a close above the last swing high and Short on a close below the last swing low, and ask for it as a strategy. Place the stop beyond the swing on the other side, since that is where the structure is wrong. Add the trend read as a filter so the strategy only takes breaks in the direction of the sequence.