Range Compression Detector

779
WHAT THIS SCRIPT DOES

This indicator answers one question before you take a trade: is the market currently trending, or is it going sideways?

It does not generate entries. It classifies conditions, so you can tell whether the tools you are about to use are appropriate right now.

The chart is shaded by state — yellow for a range, green for an uptrend, red for a downtrend — and when a range is active the script draws its boundaries and reports its height in both points and percent.


THE MEASUREMENT

Most traders identify a range visually, after it has already cost them several stops. There is an earlier and more mechanical signal.

The script measures the distance between a fast and a slow moving average, expressed as a percentage of price:

separation = |EMA(fast) - EMA(slow)| / close x 100

In a trending market this number expands. Price pulls away from its own average and the two lines fan out. In a range it collapses toward zero — the averages sit on top of each other because price keeps returning to the same area.

Expressing it as a percentage rather than in points is what makes it portable. Fifty points of separation means something very different on an instrument priced at 4,000 than on one priced at 1.10. The percentage normalises that.


WHY IT MATTERS

Almost every pullback or trend-following system contains a version of this condition:

uptrend = EMA(fast) > EMA(slow)
downtrend = EMA(fast) < EMA(slow)

When the two averages are a fraction of a percent apart, ordinary noise flips that condition back and forth. The system declares an uptrend, fires a long, then declares a downtrend two bars later and fires a short. Both get stopped.

That is not a broken system. It is a system being asked a question it was not built to answer. This indicator is intended to tell you when you are asking it.


THE THREE STATES

Two thresholds create three zones rather than a binary switch.

Range — separation at or below the compression threshold. The averages have converged. Trend logic is unreliable here.

Trend — separation at or above the trend threshold, with direction taken from which average is on top.

Transition — separation between the two thresholds. Neither condition is established. This band exists deliberately: a single line would produce constant flipping at the boundary, which is the same problem the indicator is meant to diagnose.

A state must also hold for a set number of consecutive bars before it is accepted. That adds lag, and it removes almost all of the flicker.

Transition is shaded but not labelled. It is the least actionable of the three, and labelling every entry into it was the single largest source of chart clutter during testing.


TIMEFRAMES DISAGREE, AND THAT IS THE POINT

Running this on three timeframes of the same instrument at the same moment will often give three different answers. In testing on gold, the 15-minute chart read transition, the 4-hour read range, and the daily read trend — simultaneously, with the default thresholds.

None of those is wrong. A market can be trending on the daily while going nowhere on the 4-hour.

The indicator reports the state of the timeframe you are looking at, which is the state that matters for the trade you are about to take on it. If you trade intraday inside a daily uptrend, the daily reading tells you the background; the lower timeframe reading tells you whether your entry tool will work this afternoon.


READING THE PANEL

The panel shows the current state, the live separation figure, your two thresholds for reference, and — once a range has lasted long enough to qualify — its boundaries, its height in points and percent, and how many bars it has run.

The height figure is the useful one for sizing expectations. A range measuring 2% of price gives very different room than one measuring 0.4%.


SETTINGS

Moving averages — the fast and slow lengths. Defaults are 20 and 50.

Classification — compression threshold, trend threshold, minimum bars before a range is drawn, and confirmation bars before a state is accepted.

Display — shading, range boundaries, status panel and state labels can each be turned off independently.

Colours — all three state colours are adjustable.


CALIBRATING THE THRESHOLDS

This is the part that requires work from you, and the defaults will not suit every chart.

The right threshold depends on the instrument's volatility and on the timeframe. Separation naturally widens as bar size grows, so a daily chart produces larger figures than a 15-minute chart of the same instrument.

To calibrate: add the indicator, open the Data Window, and watch the separation value through a period you already recognise as a clear trend, then through a period you recognise as a clear range. The threshold belongs between those two observed bands.

Suggested starting points, from testing on gold:

4-hour 0.10% / 0.25% (the defaults)
15-minute 0.06% / 0.18%
Daily 0.40% / 1.00%

Only the 4-hour pair was tested in depth. The other two are extrapolated from observed readings and should be verified on your own chart before you rely on them.

If the indicator shows transition almost all of the time, your thresholds are too far apart. If it flips between range and trend, they are too close together or the confirmation period is too short.


LIMITATIONS - PLEASE READ

It is descriptive, not predictive. It tells you what conditions have been, not what they will be. A range can end on the next bar.

It lags. The confirmation period means a state is recognised after it has already been in place for several bars. That is a deliberate trade-off against false classification, and it cannot be removed without reintroducing the flicker.

Thresholds are instrument-specific and timeframe-specific. Using the defaults on an unfamiliar chart will produce misleading classifications. Calibration is not optional.

Two moving averages are a crude proxy. They capture the most common form of directionless market, but not every one. A market can trend slowly enough that separation stays low, and it can spike violently inside a range and briefly read as trending.

Range boundaries are drawn from the bars observed so far. The box grows as the range develops and reflects what has happened, not where the range will ultimately be contained. The boundaries are also not redrawn retroactively once the range ends.

It produces no entries, no targets and no stops. Combining it with a signal system is left to you, and this publication makes no claim about what that combination would produce.


ON PERFORMANCE CLAIMS

This publication makes no claim about win rate, accuracy or profitability. No such claim can be substantiated for future market conditions. What the script does is make one property of the market measurable and visible so you can decide which of your own tools fits it.


ORIGINALITY

Moving average separation is not a new observation, and neither are EMAs. The original work is in the treatment: a normalised percentage measure rather than a raw distance, a three-state classification with an explicit transition band instead of a binary switch, a confirmation requirement to suppress boundary flicker, a minimum-duration filter so brief pauses are not drawn as ranges, and automatic measurement of the range that the compression identifies — its boundaries, its height in points and percent, and its duration.

The intent is different from most published trend filters as well. This does not filter signals for you or tell you what to trade. It reports a condition and leaves the decision where it belongs. The code is published open-source so every threshold and every rule can be inspected and changed.

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.