Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Break of Structure (BOS) and Change of Character (CHoCH) Labels - indicator for MetaTrader 5

Views:
20
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Break of Structure (BOS) and Change of Character (CHoCH) Labels

The idea behind it

Many price-action traders describe a trend through its swings. In an up-trend price makes higher highs and higher lows; in a down-trend it makes lower highs and lower lows. Two events are watched closely:

  • BOS (Break of Structure) - price breaks the last swing in the direction of the current trend, for example a new high in an up-trend. It confirms that the trend continues.
  • CHoCH (Change of Character) - price breaks the last swing against the current trend, for example the last swing low in an up-trend. It is the first sign that the trend may reverse.

The indicator measures this objectively:

  1. A swing high is a bar whose High is higher than the High of InpSwingBars bars on each side. A swing low is defined in the same way with the Low. A swing is confirmed only when those following bars are closed.
  2. The last confirmed swing high and swing low are the structure levels.
  3. When a closed bar breaks the last swing high (or low), the trend direction is updated. If the break is in the direction of the current trend, it is labeled BOS; if it is against the trend, it is labeled CHoCH.
  4. A swing can be broken only once; the next break needs a new swing.

The first break after the start only defines the initial trend and receives no label, because there is no previous trend to compare with.

All calculations use closed bars only, so labels do not repaint. The indicator keeps its market-structure state between calls; at start it scans a limited number of bars, and after that every new closed bar is processed once. The full history is never rescanned.

How to interpret it

  • Horizontal line - drawn at the price of the broken swing, from the swing bar to the bar that broke it.
  • BOS label (white dashed line by default) - the trend continues. The label is above the line for an upward break and below it for a downward break.
  • CHoCH label (silver dotted line by default) - the trend changes direction. Above the line means the trend changed to bullish; below the line means it changed to bearish.
  • A series of BOS labels in the same direction shows a healthy trend. A CHoCH after such a series is an early warning and is often used together with other tools to look for a pull-back entry or a reversal.

External variables (inputs)

Input Default Purpose
Structure
InpSwingBars 3 Number of bars on each side of a swing (1 to 20). Larger values give fewer, more significant swings
InpBreakMode BREAK_CLOSE How a swing is broken: BREAK_CLOSE (a bar must close beyond it) or BREAK_WICK (a High or Low beyond it is enough)
InpLookbackBars 500 Number of bars scanned when the indicator starts (30 to 5000)
InpMaxLabels 40 Maximum number of breaks kept on the chart; the oldest is removed first (1 to 300)
Display
InpShowBos true Show BOS labels
InpShowChoch true Show CHoCH labels
InpBosColor clrWhite Color of BOS lines and labels
InpChochColor clrSilver Color of CHoCH lines and labels
InpBosStyle STYLE_DASH Line style of BOS
InpChochStyle STYLE_DOT Line style of CHoCH
InpLineWidth 1 Line width (1 to 5). Dash and dot styles are drawn only with width 1
InpFontSize 9 Label font size (6 to 20)
Alerts
InpAlertNew false Show an alert when a BOS or CHoCH is confirmed on a closed bar

Recommended use

  • Works on any symbol and timeframe. M15 to H4 charts are the most common choice. A small InpSwingBars marks internal, short-term structure; a large one marks the major structure.
  • Swings are confirmed InpSwingBars bars after they form, so a break can be labeled only against a swing that was already confirmed. This avoids repainting but means that very fast reversals may be labeled later than they look on the chart.
  • Even when BOS or CHoCH labels are switched off, the indicator still tracks the trend internally, so the remaining labels stay correct.
  • In BREAK_WICK mode, a bar that breaks both the swing high and the swing low is counted only in the direction of its candle.
  • Market structure is subjective by nature: other traders may choose swings differently, so use these labels as a visual aid rather than a trading signal, and confirm with trend, levels and risk management.
  • On the first start only the last InpLookbackBars bars are scanned, and the trend is unknown at the beginning of that range, so the first break is not labeled.
  • All objects use the prefix Bos_ and are removed when the indicator is deleted from the chart. Do not attach two copies to the same chart because they would share object names.
  • It is a chart indicator only and does not trade, so it works the same on netting and hedging accounts.


Fig. 1. BosChochLabels on an M15 chart with default settings: BOS (dashed) and CHoCH (dotted) labels (black and white image per Code Base guidelines).

Fair Value Gap (FVG) Detector with Auto-Removal When Filled Fair Value Gap (FVG) Detector with Auto-Removal When Filled

Detects bullish and bearish Fair Value Gaps (three-candle price imbalances), draws them as boxes extending to the right and automatically removes each box once the price fills the gap.

Order Block Marker with Mitigation Tracking Order Block Marker with Mitigation Tracking

Marks bullish and bearish order blocks (the last opposite candle before a strong impulse) and tracks their state: fresh, mitigated when price returns, and removed when broken.

Premium and Discount Zones Based on the Current Swing Range Premium and Discount Zones Based on the Current Swing Range

Splits the current swing range (last swing high to last swing low) into a Premium zone above 50% and a Discount zone below 50%, with an equilibrium line and a live label that shows where the price is inside the range.

MACD Signals MACD Signals

Indicator edition for new platform.