Algos Price Action Market Structure
- Indicatori
-
Noam Ben Shaul
Computer Science student (University of Haifa, GPA 88) who builds MetaTrader 5 tools in MQL5 and Python.
Recent work:
- A ~1,000-line market-structure indicator (swing points, BOS/CHoCH detection, automatic HTML statistics report), ported from my own Pine Script. - Versione: 1.0
- Attivazioni: 5
Algos Price Action maps market structure the way price-action traders read it by hand: a swing high or low only counts after price has actually pulled back from it, and only then can it be broken.
How it works
- Tracks the running swing high and swing low on closed bars.
- A swing is confirmed only after price retraces by the pull back distance for at least the minimum number of bars. Smaller noise is ignored.
- When price breaks a confirmed swing, the break is classified as BOS (Break of Structure - continuation in the direction of the current structure) or CHoCH (Change of Character - the first break against the current structure).
- A short line is drawn at every confirmed high and low (high, low, high, low...), with an optional BOS / CHoCH label. Nothing else is drawn, so the chart stays clean.
The logic behind the code
- Closed candles only. The candle that is still forming is never used. A level that is crossed during a candle that then closes back inside is not a break, so there is no flicker and no signal that disappears a minute later.
- A break needs a close, not a wick. A swing high is broken only when a candle closes above it, and a swing low only when a candle closes below it. If a candle only spikes through the level with its wick and closes back, it is not counted and the level stays where it is.
- A swing must earn its pull back. Before a high can be broken, price must have pulled back from it by at least the pull back distance (measured on the candles after the high). If the pull back was smaller, a new higher high is not a break: the swing high simply moves up to the new high. Lows work the same way in the other direction.
- Time as well as distance. The pull back must also last at least "Pull back min length" candles. If price pulled back far enough but came straight back sooner than that, the whole move is treated as noise: the last pair of lines it drew is removed and the swing is extended instead.
- BOS or CHoCH depends on the current structure. The indicator remembers whether structure is bullish or bearish. A break in the same direction is a BOS; the first break against it is a CHoCH, and the structure flips.
- The pull back point becomes the new level. After a bullish break, the lowest point of the pull back becomes the new swing low that has to hold (the opposite after a bearish break). This is how the structure follows price step by step.
- Lines alternate high, low, high, low. A line is drawn at a high only after price has moved away from it by the pull back distance. If a higher high forms before a low is confirmed, the line moves up to the new high instead of stacking two highs.
- How the pull back is set. In Auto mode it is the average candle range of the last 200 closed candles multiplied by a factor for the timeframe, calculated when the indicator loads. In Manual mode it is your fixed number of pips (1 pip = 10 points on 5- and 3-digit quotes).
- Labels and alerts are final. A BOS / CHoCH label and its alert are created once, on the candle that closed beyond the level, and are not moved or redrawn afterwards.
IMPORTANT - match the pull back to your timeframe
The pull back decides which swings are real, so it must fit the timeframe you trade.
- If it is too small for the timeframe (for example 10 pips on H1), almost every small wiggle becomes a "swing" and the chart fills with lines and labels that mean nothing.
- If it is too large (for example 100 pips on M5), real swings are skipped.
- As a starting point on EURUSD and similar pairs: about 10 pips on M5 and about 100 pips on H1. Volatile symbols such as gold need proportionally more.
- The default Auto mode does this for you: it sets the pull back from the timeframe and the symbol's own average bar range, and shows the value in use on the chart ("Pull back: X pips"). Switch to Manual to enter your own value in pips.
On the chart
- Lines at confirmed highs and lows (color, width, length and style are adjustable; optionally connect each line to the next break).
- BOS / CHoCH text labels.
- Panel (top-right) with the number of BOS and CHoCH events on the loaded history and the pull back in use.
- Optional pop-up alert on every new BOS or CHoCH.
For EA developers: data buffers 0-3 (not drawn) hold the CHoCH count, BOS count, current structure high and current structure low, so the indicator can be read with iCustom.
Settings
- Pull back mode (Auto / Manual), Auto sensitivity, Manual pull back (pips), Pull back min length (bars)
- Line color, width, length, style, connect line with next break
- Show labels, show panel, panel color, alerts
- Object prefix (lets you run two instances with different settings on one chart)
Works on any symbol and timeframe. Calculations use closed bars only, to avoid flicker while a bar is still forming. This is an analysis tool: it does not open trades and does not promise any result.
