Structure Flow and Trailing Stop MT4

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.

See all published products →

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.

More from author
Anchored Volume Delta with Adaptive Bands
Narayanan Mohanan Mohanan Krishnan
This indicator plots Cumulative Volume Delta (CVD) — the running total of each bar's volume, signed by the direction the bar closed — inside adaptive standard-deviation bands. It answers a question price alone does not: is the move being carried by participation, or is it drifting? The cumulative total restarts at an anchor you choose — daily, weekly or monthly — so the reading is always relative to the current session, week or month rather than to the beginning of chart history. That single con
FREE
MTF Currency Strength Panel MT4
Narayanan Mohanan Mohanan Krishnan
MTF Currency Strength Panel for MetaTrader 4 A multi timeframe currency strength meter covering all 28 major forex pairs on one chart. This currency strength panel shows where the eight major currencies stand right now, and how each of the 28 major pairs has been moving across nine timeframes at once — M1 to MN1. Both readings sit on one chart, updated on a timer. Ranking pairs on their own is misleading. When a single currency moves, every pair containing it moves with it, so the top of a pair
FREE
Trend Survival States
Narayanan Mohanan Mohanan Krishnan
Trend Survival States for MetaTrader 5 — a free market regime indicator measuring bull and bear pressure with adaptive volatility bands and a five-state trend classification Bull and bear pressure, an adaptive-band spread, and a five-state market classification, free for MT5. It measures the buying and selling pressure behind the current move and classifies that into a market state: strong bull, weak bull, neutral, weak bear, strong bear. This is a complete regime indicator, not a time-limited t
FREE
Force Index with Adaptive Volatility Bands
Narayanan Mohanan Mohanan Krishnan
This indicator plots the Force Index — each bar's price change multiplied by its volume — inside adaptive standard-deviation bands. Where price alone tells you that a market moved, the Force Index tells you how much effort went into moving it. A large price change on thin volume and a small change on heavy volume are very different events, even when the candles look similar. The Force Index separates them by combining both into a single reading, and the bands place that reading in the context of
FREE
Multi Timeframe Currency Strength Panel
Narayanan Mohanan Mohanan Krishnan
MTF Currency Strength Panel for MetaTrader 5 A multi timeframe currency strength meter covering all 28 major forex pairs on one chart. This currency strength panel shows where the eight major currencies stand right now, and how each of the 28 major pairs has been moving across nine timeframes at once — M1 to MN1. Both readings sit on one chart, updated on a timer. Ranking pairs on their own is misleading. When a single currency moves, every pair containing it moves with it, so the top of a pair
FREE
This indicator plots Cumulative Volume Delta (CVD) — the running total of each bar's volume, signed by the direction the bar closed — inside adaptive standard-deviation bands. It answers a question price alone does not: is the move being carried by participation, or is it drifting? The cumulative total restarts at an anchor you choose — daily, weekly or monthly — so the reading is always relative to the current session, week or month rather than to the beginning of chart history. That single con
FREE
This indicator plots the Force Index — each bar's price change multiplied by its volume — inside adaptive standard-deviation bands. Where price alone tells you that a market moved, the Force Index tells you how much effort went into moving it. A large price change on thin volume and a small change on heavy volume are very different events, even when the candles look similar. The Force Index separates them by combining both into a single reading, and the bands place that reading in the context of
FREE
OBVCD Pro MT4
Narayanan Mohanan Mohanan Krishnan
OBVCD Pro is a momentum oscillator that applies convergence/divergence analysis to On-Balance Volume (OBV) instead of price, combining adaptive volatility bands with a 5-state regime classifier that can be read visually on the chart or consumed directly by an Expert Advisor. Most classical oscillators analyse price alone. OBVCD Pro calculates convergence and divergence from cumulative volume flow, so it measures the participation behind a market move rather than only the movement itself. The res
Currency Strength Oscillator MT4
Narayanan Mohanan Mohanan Krishnan
Currency Strength Oscillator for MetaTrader 4 A relative currency strength indicator that plots the history of the eight majors. This currency strength oscillator plots the relative strength of the eight major currencies as a history, decomposed from the 28 major pairs. While a standard currency strength meter tells you where things stand right now, this shows how they got there — which currency has been strengthening, which has rolled over, and where the ranking changed hands. All eight series
Oscillator Regime Suite MT4
Narayanan Mohanan Mohanan Krishnan
This indicator applies the convergence/divergence construction — fast moving average minus slow, with a signal line — to a volume-derived series rather than to price. Three sources are selectable: Cumulative Volume Delta, Force Index, and On Balance Volume. Adaptive volatility bands are drawn over the result, and every completed bar is classified into one of five regime states. That state is exposed as a numeric buffer, so an Expert Advisor can read it directly. Why the source matters A standard
OBVCD Pro
Narayanan Mohanan Mohanan Krishnan
OBVCD Pro is a momentum oscillator that applies convergence/divergence analysis to On-Balance Volume (OBV) instead of price, combining adaptive volatility bands with a 5-state regime classifier that can be read visually on the chart or consumed directly by an Expert Advisor. Most classical oscillators analyse price alone. OBVCD Pro calculates convergence and divergence from cumulative volume flow, so it measures the participation behind a market move rather than only the movement itself. The res
Currency Strength Oscillator MT5
Narayanan Mohanan Mohanan Krishnan
This indicator plots the relative strength of the eight major currencies as a history, decomposed from the 28 major pairs. A panel tells you where things stand now. This shows how they got there — which currency has been strengthening, which has rolled over, and where the ranking changed hands. All eight series are exposed as documented indicator buffers, so an Expert Advisor can read currency strength directly. How the decomposition works Each of the eight currencies appears in seven of the twe
Oscillator Regime Suite
Narayanan Mohanan Mohanan Krishnan
This indicator applies the convergence/divergence construction — fast moving average minus slow, with a signal line — to a volume-derived series rather than to price. Three sources are selectable: Cumulative Volume Delta, Force Index, and On Balance Volume. Adaptive volatility bands are drawn over the result, and every completed bar is classified into one of five regime states. That state is exposed as a numeric buffer, so an Expert Advisor can read it directly. Why the source matters A standard
Structure Flow and Trailing Stop
Narayanan Mohanan Mohanan Krishnan
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. The flow line An adaptive average. It smooths heavily when price is rotating and lightly when
Trend Survival Rate
Narayanan Mohanan Mohanan Krishnan
Trend Survival Rate for MetaTrader 5 — a market regime indicator that measures how often the current trend state has survived to the next bar, and scores its own forecast Trend survival rate, market state classification and a live Brier forecast score, in one MT5 indicator window. It measures the buying and selling pressure behind the current move, classifies that into a market state, and reports how often that state has survived to the next bar — then grades its own forecast against what actual
Filter:
No reviews
Reply to review