Structure Flow and Trailing Stop MT4
- Indicators
-
Narayanan Mohanan Mohanan Krishnan
I build measurement tools for MetaTrader. They describe what the market has done, and state the limits of each measurement rather than hiding them. - Version: 1.1
- Updated: 16 August 2026
- Activations: 5
Structure Flow and Trailing Stop MT4 — an adaptive flow line with five trailing stop methods, market structure and liquidity bands for MetaTrader 4
Five trailing stop methods, one adaptive flow line, and a condition panel that reports how many measurements agree. This indicator draws two lines on the price chart: an adaptive flow line that follows the market's direction, and a trailing stop that moves only in that direction and never back. A small panel reports the state behind them.
The trailing stop can be calculated five different ways. These are not variations on one idea — each anchors to something different, and on the same chart they frequently disagree.
Structure Flow and Trailing Stop is also available for MetaTrader 5. This MT4 build is a direct port of it, verified bar by bar — the comparison is described further down.
The flow line
An adaptive average. It smooths heavily when price is rotating and lightly when price is travelling, so it stays close during a move without chasing every swing in a range. Three inputs control it: the window it measures over, and the fastest and slowest smoothing it may use.
A noise filter holds the line still when price has not moved far enough from it to be worth following. That threshold is expressed in ATR, so it scales with the instrument rather than assuming a pip value.
The trailing stop and its five methods
The stop advances only in the trend's direction. It never moves against the trend and it never retreats, so during consolidation it holds its level rather than creeping closer to price. When price crosses it, the trend flips and the stop moves to the other side.
- Swing pivot — anchored to the last swing in the flow line, or to the ATR trail when that is tighter. Structural: it sits where the market last turned.
- ATR trail — a fixed ATR distance from the flow line, ratcheted bar by bar. The smoothest of the five, since it inherits the flow line's own smoothing.
- SuperTrend — an ATR band around each bar's median price, flipping when the close crosses it. Angular rather than smooth: it steps with the bars instead of curving with an average.
- Chandelier — anchored to the flow line's highest or lowest point across the lookback. Holds through pullbacks that tighter methods give up on.
- Donchian channel — the highest high and lowest low over the lookback, with no ATR component at all. The widest of the five and the slowest to flip.
Because they anchor to different things, they answer differently. On USOIL daily on 14 August 2026, five instances on one chart read: swing pivot bullish for 167 bars, Donchian for 28, ATR trail for 23, Chandelier for 21 — and SuperTrend bearish for 11. All five reported the same regime and the same structure. They agreed on everything except direction, and the levels they placed spanned more than twelve dollars a barrel.
Which suits you is a question about how you trade, not about which is right.
Several instances can run on one chart, each with its own method and its own panel — which is how that screenshot was made.
The condition panel
Four conditions are evaluated on each bar: the direction of the flow, its position relative to a volatility band, the market's swing structure, and the size of the current impulse. The panel reports how many agree and in which direction, alongside the flow's trend duration, the volatility regime, and a compression reading.
That is a summary of where the market is, not an instruction about what to do. Four conditions agreeing describes the present; it does not forecast what follows.
The panel can sit in any corner or vertically centred, and switch to a compact two-row form when several instances share a chart.
Reading it from an Expert Advisor
All eight buffers are exposed and documented. Four of them are not drawn at all — they exist so an EA can read the indicator's conclusions as numbers rather than inferring them from the drawing.
double flowBull = iCustom(NULL, 0, "NaaMo\\StructureFlowTrailingStop", 0, 1); double flowBear = iCustom(NULL, 0, "NaaMo\\StructureFlowTrailingStop", 1, 1); double stopBull = iCustom(NULL, 0, "NaaMo\\StructureFlowTrailingStop", 2, 1); double stopBear = iCustom(NULL, 0, "NaaMo\\StructureFlowTrailingStop", 3, 1); double regime = iCustom(NULL, 0, "NaaMo\\StructureFlowTrailingStop", 7, 1);
The buffer map on MetaTrader 4, which differs from the MetaTrader 5 version. Read this before writing any EA code.
- 0 — flow line, bullish half
- 1 — flow line, bearish half
- 2 — trailing stop, bullish half
- 3 — trailing stop, bearish half
- 4 — condition quality, 0 to 100
- 5 — condition bitmask: 1 flow, 2 volatility, 4 structure, 8 impulse, so 15 means all four agree
- 6 — trend direction, +1 or −1
- 7 — regime: 1 trending, 2 ranging, 3 compressing, 4 expanding, 5 exhausting
Why buffers 0 to 3 are split into halves. MetaTrader 4 has no coloured-line drawing type, so each of the two lines is drawn as a bull half and a bear half, with EMPTY_VALUE wherever the other half is active. To read the flow line as a single series, take whichever of buffer 0 and buffer 1 is not EMPTY_VALUE on that bar. The same applies to the stop across buffers 2 and 3.
On MetaTrader 5 those same indices mean something else — buffer 1 and buffer 3 are colour indices there, and the two lines are single series at buffers 0 and 2. An EA written for one platform needs this one section changed for the other; everything from buffer 4 onward is identical.
Buffer 7 is the one worth knowing about. A system that should stand down in a rotating market can read it directly instead of deriving a regime of its own.
Read shift 1 — the last fully closed bar — for values that will not change.
Inputs
- Flow line — the adaptive window (default 14), the fastest and slowest smoothing (2 and 30), and the noise threshold in ATR (0.3)
- Trailing stop — the method, the ATR period (14) and multiplier (2.5), the channel lookback (20), and the pivot settings
- Liquidity bands — the innermost band distance in ATR (6.5), and the volume profile resolution and lookback
- Market structure — how many bars either side define a swing (10 and 10), and how many breaks confirm a shift
- Condition gates — the impulse threshold, how long a regime must hold to count, and how far back to evaluate (500 bars)
- Display — the two colours, and the panel's corner, vertical position, offsets, font size and compact mode
Calculation behaviour
Closed-bar values are final. The forming bar is recalculated on every tick from a copy of the internal state, so the stop reacts to live price while the state that history depends on advances only once, when the bar closes. A trailing stop that updated only at the close would sit still during exactly the moves that matter.
Nothing is drawn before the calculation has the history it needs, and no value is computed from a partial window and then plotted as though it were complete.
One behaviour worth stating plainly. The condition quality reading depends on how much history the terminal has loaded, because the conditions are evaluated over a fixed lookback counted back from the newest bar. Two charts of the same instrument with different history depths can therefore show slightly different quality scores on the same bar. The trend direction, the regime and both lines are unaffected.
About the screenshots. Every image is captured in MetaTrader 4, on this build, at the same resolution. The first shows five instances on one chart, one per stop method, so the disagreement described above can be read directly rather than taken on trust. The seventh shows every input and the Data Window together.
The last two are the buffer split, demonstrated. They are the same instrument in the Strategy Tester, once with the trend up and once with it down. On the first, Flow Bull and Stop Bull hold values and the bear buffers are empty; on the second it is exactly reversed. If you intend to read this indicator from an EA, those two images are worth more than the buffer table — they show the EMPTY_VALUE behaviour you will be coding against.
The MetaTrader 5 version was the original and this is a direct port, verified against it: on matched history across three instruments, the flow line, the trailing stop and the trend classification agree on every comparable bar, and the condition quality differs by a median of 0.12 on a score displayed as a whole number. What differs between the two platforms is the terminal itself — chart rendering, the layout of the settings dialog, and the buffer split described above — not what the indicator calculates.
Notes
- Draws on the price chart. Two visible lines, no separate window.
- Several instances can be attached to one chart, each with a different method and its own panel. Two instances of the same method should be given different panel positions.
- The stop is a level, not an order. The indicator draws where a trailing stop would sit. It does not know your position, does not place or modify orders, and does not manage trades.
- Volume readings use tick volume, which every broker provides.
- No external dependencies. Every value is calculated inside the indicator. It does not call any other indicator, so there are no handles to fail, nothing to install alongside it, and no dependency on the state of your standard indicator folder.
What this is and is not
This is a tool for technical analysis and for filtering market conditions. It is not a trading system, it produces no buy or sell signals, it gives no investment advice, and it does not open or manage positions.
There are deliberately no entry arrows. A stop level and a count of agreeing conditions describe where the market is; turning that into a decision is the reader's job, not the indicator's.
It is descriptive rather than predictive, and no claim is made about its performance.
The free demo runs in the Strategy Tester. Put it on the instruments and timeframes you actually trade, try each of the five stop methods, and judge it against your own charts.
| More tools from this developer I build MT4 indicators and Expert Advisors with an emphasis on clean, documented, no-repaint code — closed-bar logic, validated buffers, and no dependencies on other indicators. The five-state regime classification here is the same one used in the Oscillator Regime Suite, which applies it to volume-derived series in a separate window rather than to price on the chart. Questions about the calculation, the buffers, or using this in your own EA? Send me a private message — I am happy to answer. |
Built and maintained by Narayanan Mohanan, MT4/MQL4 developer.
