Twin Range Filter is a stepped line on MT4 and MT5 with Long and Short labels where the line changes direction. The line is not an average. It's a ratchet, and that difference is the whole point.

Gold H1: the line holding flat for hours at a time, then stepping, with the labels on the turns

A line that refuses to move

A moving average recalculates on every bar whether or not the bar meant anything. This one asks a different question each bar: has price moved further than my own range allows?

If close is above the line, the line becomes close minus range, but only if that's higher than where the line already sits. Otherwise it stays exactly where it was. Below the line, mirrored. Written out that's four lines of code, and it produces the flat shelves you can see above: the line parks at one price and stays there through everything that isn't big enough, then steps.

The consequence worth understanding is that the line cannot move against itself while it's trending. It steps up, or it holds. It can only start dropping once price has fallen through the full range width from underneath, which is why the turns are late but rarely confused about direction.

Where "twin" comes from

The range that the ratchet uses is built twice.

Each build is a double EMA of the absolute bar-to-bar close change: an EMA over Per, then a second EMA of that over 2*Per - 1, multiplied by Mult. The fast build runs 27 and 1.6, the slow one 55 and 2.0. The two results are then averaged, one weight each, into the single number the ratchet uses.

So "twin" is a mean, not a confirmation. Nothing has to agree with anything. What you get is a band width with both a quick and a slow component in it, so a burst of volatility widens it immediately but not fully, and it takes a long time to come back down.

Two things follow from how that range is measured, and both matter:

It reads closes only. The absolute change is close minus previous close. A bar with an enormous wick that closes back where it started contributes almost nothing to the range. The filter is blind to the spike.

It isn't ATR. People assume any volatility band is ATR-based. This one isn't, and on gaps the two behave differently: a weekend gap is one large close-to-close change here and one large true range there, but the double smoothing means this one absorbs it over the following dozens of bars rather than over a single ATR period.

The signals, and what the code actually says

Two counters track how many bars in a row the line has been stepping up or stepping down. Then the long condition reads, in the source, as two alternatives joined by an or: price above the filter and rising with the up-counter positive, or price above the filter and falling with the up-counter positive.

Look at those two halves. They differ only in rising versus falling, so between them they cover every case except an exactly unchanged close. The whole thing collapses to "close above the filter, up-counter positive". I'm telling you because if you read the source you'll see two conditions and reasonably assume one of them is filtering something. It isn't.

On top of that sits a one-value state machine. It remembers whether the last thing that happened was a long condition or a short condition, and a label is only drawn when the state flips. That's what stops you getting a Long label on every bar of a trend, and it's why labels come in strict alternation: Long, Short, Long, Short, all the way down the chart.

It also means the first signal after you attach the indicator is swallowed. The state starts neutral, and neither branch fires from neutral, so the first flip has nothing to flip from.

EURUSD H4: the same alternation, with the long flat stretch through July

Moving average ATR trailing stop This
Moves every bar Yes No No
Range measured from n/a True range, wicks included Close-to-close change only
Number of ranges One One Two, averaged
Can move against the trend Yes No No
Signal rule Cross Stop hit State flip, strict alternation
Flat means Nothing Holding Nothing has cleared the band

What you get

The coloured line, plus an upper and lower band at filter plus or minus the range, which are off by default. Turn ShowBands on and you can see exactly how much room price needs to make the next step. That view is worth ten minutes even if you leave it off afterwards.

Notifications go through the shared block: alert, email, push or Telegram, once per bar per message so a fast tick stream can't spam you.

For EA use both platforms expose everything, but the buffer numbers differ between them, because MT5 draws a colour-indexed line while MT4 has to fake the same look with two overlaid line buffers. On MT5 the filter is buffer 0 and the signal is buffer 13. On MT4 the filter is buffer 4 and the signal is buffer 14. Read the wrong index and you get a plausible-looking series that isn't what you asked for.

Where it's weak

Alerts fire on the forming bar by default. AlertConfirmed is false out of the box, which matches how the original behaved, and it means a signal can fire mid-bar and then not be there at the close. The label gets deleted when that happens, so the chart tidies up after itself and the alert on your phone doesn't. Set AlertConfirmed to true for the closed-bar version.

Strict alternation is not a trend filter. Every Long is followed by a Short. In a range that produces pairs of opposite labels a handful of bars apart, and you can see several of those on the gold chart in the last week of August. The indicator has no opinion about which of the two you should take, because it has no trend or higher-timeframe input at all.

The turn is late by design. Price has to travel a full range width past the line before the line can start moving the other way. That's the price of a line that never whipsaws against itself, and on a sharp reversal it's expensive.

Labels crowd on fast charts. They're chart objects anchored to the bar high and low in 8pt text. On H1 gold, with a few hundred bars in view, adjacent labels overlap and become hard to read. Around two thousand objects accumulate over the default history. Turn ShowSignals off if the chart feels heavy.

No wick information anywhere. As above, the range comes from closes. A stop-hunt spike through the band that closes back inside is invisible to this indicator, both in the range and in the signal.

The grey colour state is dead code. The line has a third colour for "flat", but the counters keep their previous value while the line holds, so once the first step has happened the line is always lime or red. You won't see grey.

Two periods, no weighting. Per1/Mult1 and Per2/Mult2 are averaged with equal weight and there's no input to change that. If you want the slow range to dominate, your only lever is its multiplier, and that also changes the band width.

Questions you'll have

Does Twin Range Filter repaint? Closed bars don't change. The current bar's line value and its label can both move while the bar is forming, and a label that appears mid-bar is deleted if the condition has gone by the close.

Why is the line completely flat for hours? Because no close has moved more than the smoothed range away from it. That's the intended behaviour and the reason the line exists.

Why do Long and Short always alternate? A state machine only emits a label when the condition flips from one side to the other, so you never get two of the same in a row.

Is it ATR-based? No. The range is the average absolute change between consecutive closes, smoothed twice. It ignores highs and lows entirely.

What does twin mean here? Two range calculations, one fast and one slow, averaged into a single band. They don't confirm each other.

Should I turn the bands on? Try it for a session. They show how far price has to travel for the next step, which makes the flat stretches much easier to read.

Can an EA read it? Yes, but check the buffer index per platform: filter is 0 on MT5 and 4 on MT4, signal is 13 on MT5 and 14 on MT4.

Best timeframe? M30 to H4. On M5 the range is small enough that the line steps on most bars and the alternation gets noisy.

MT4? Both platforms are included, one download each. Same maths, same inputs, same signals; only the buffer layout differs.

Support

Send me a message with a screenshot, the symbol and the timeframe, and I'll tell you what the tool was doing on that bar.

Analysis tool. It places no trades and makes no profitability claim. Past price behaviour is not a guide to future price behaviour.