Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Indicator | Range Compression Zones Breakout | Trading Tool Update

RobotFX curates the best open-source MetaTrader code to inspire your trading automation.

Data How it is used
High, low, close Range measurement, zone boundaries and the cross test.
Next bar's open Reference entry price of a confirmed signal.
Tick or real volume Two summed volume windows are compared by the volume filter.
H1, D1 or W1 high and low The latest completed reference bar is compared with the bar Lookback bars earlier.
Bar times Placing boxes, markers and lines, and deciding which reference bars were complete at the signal time.



How to interpret signals and visual elements

Confirmed buy and sell signals

Capture price channel breakouts with the Price Channel Expert Advisor. Precise entries and exits. Explore now.

A buy signal needs a closed candle that crosses above the zone high, a latest completed reference low that is higher than the reference low Lookback bars earlier, and recent volume that is rising. A sell signal needs a close below the zone low, a latest completed reference high that is lower than the reference high Lookback bars earlier, and rising volume. A buy arrow sits below the signal candle and a sell arrow above it.

The arrow is placed on the signal candle, not at the reference entry price. The entry is the open of the next bar. A cross always closes the zone, whether it passes the filters or not. After a confirmed signal the zone is cleared and no new zone is armed on that bar.

The reference filter can be switched off. In that case a cross is accepted when the volume check and the trade plan are valid.

Element Interpretation
Active zone Dashed box in the active zone colour (blue by default), stretched to the current bar. Its edges are the highest high and lowest low of the arming window.
Finished zone box Solid box from the start of the zone window to the signal candle. Green for a confirmed buy, red for a confirmed sell, grey for a cross rejected by a filter.
Zone tag For example RC HL 54.2% (<75%): range mode, compression ratio at the arming bar, threshold, then the outcome (BUY, SELL or FILTERED). The ratio is a measurement, not a quality score.
Buy / sell arrow A confirmed signal on a closed candle. Green up arrow below the candle for a buy, red down arrow above it for a sell.
Grey cross mark A breakout that crossed the zone edge but was rejected by a filter or by an invalid trade plan. It is shown so you can see what was filtered out.
Entry, SL, TP lines Short horizontal lines starting at the bar after the signal: dotted entry, solid stop, solid target, each with a price tag.
Reference lines The latest completed reference high and low (solid) and the high and low Lookback bars earlier (dotted). Lows are drawn in the buy colour and highs in the sell colour. They show the current state, not the state at the time of an older signal.
Status overlay Text rows in the chosen chart corner, described below.


Entry, stop and target

  • Entry: the open of the bar after the signal candle. Spread is not modelled.
  • Buy stop: the bottom of the zone. Sell stop: the top of the zone.
  • Risk: the distance between the entry and the stop. If the entry is not on the correct side of the stop (for example after a gap), there is no valid trade plan and the cross is shown as filtered.
  • Target: the entry plus (buy) or minus (sell) the risk multiplied by the Reward-to-Risk Ratio (default 2.0).

The stop is based on the zone boundary, not on the candle wick. There is a single target. The levels are a reference plan, not a broker position, and no trailing or break-even logic is applied.

Status overlay

Row Meaning
Mode Range mode, Length and threshold in use.
Ratio Compression ratio of the last closed bar, flagged COMPRESSED or normal.
Zone ARMED with the zone low and high, or none.
Ref Whether the reference filter would currently accept a buy and a sell, as of now. It describes the present state of the reference timeframe, not a past signal.
Volume Whether the volume condition is met on the last closed bar.
Signals Count of confirmed buys, confirmed sells and filtered crosses in the calculated history.
Last Direction and time of the latest confirmed signal.


Alerts and buffers

  • Alerts: popup, mobile push and sound, sent once per confirmed signal bar with the symbol, timeframe, direction, entry, stop and target. Because a signal is confirmed on a closed candle, the alert appears when the next bar opens. Signals that already exist when the indicator starts, or that reappear after a recalculation, do not alert.
  • Buffers: RangeRatio (0), Compression (1), Range (2), BuySignal (3) and SellSignal (4). The signal buffers hold the close of the signal bar. A ratio and a compression flag are empty while history is too short or the earlier range is unusable.
Image for Range Compression Zones Breakout


Key settings and parameters

The table covers every input. Colour defaults can be changed in the input dialog.

Setting (input name) Default Description
Range Compression
Range Length / Offset (InpLength) 4 Range window and comparison offset, in bars of the chart timeframe. Range 1-10000.
Compression Threshold (%) (InpFactor) 75 A bar is compressed when the recent range is strictly below this percentage of the past range. Lower values find only stronger compressions. Range 0-1000.
Calculation Mode (InpMode) High-Low High-Low range or ATR with Wilder smoothing, both using Length.
Volume Confirmation
Minimum Volume Ratio (InpVolRatio) 1.0 Recent volume must be greater than the earlier volume multiplied by this value.
Volume Average Length (InpVolAvgLength) 4 Number of bars summed in each of the two windows being compared.
Volume Average Delay (InpVolDelay) 4 The recent window ends this many bars before the signal candle. The earlier window is one averaging length further back.
Volume Source (InpVolumeType) Tick volume Tick volume or real volume.
Higher-Timeframe Filter
Enable High/Low Filter (InpUseReferenceFilter) true Turns the higher-timeframe filter on or off.
Reference Timeframe (InpReferenceTf) D1 H1, D1 or W1.
Lookback Bars on Reference Timeframe (InpReferenceLookback) 12 The latest completed reference bar is compared with the bar this many bars earlier. W1 with 12 compares with 12 weeks earlier; D1 with 12 compares with 12 days earlier.
Risk and Targets
Reward-to-Risk Ratio (1:R) (InpRewardRisk) 2.0 The target is placed at this multiple of the distance between the entry and the stop. There is one target; no separate TP levels.
Display
Max History Bars to Render (InpDisplayBars) 1500 Zones, arrows and trade levels are drawn only for this many recent bars. Older history is still calculated.
Fill Zone Boxes (InpFillZones) true Fills the zone boxes. Turn it off for outline-only boxes.
Show Zone and Price Tags (InpShowLabels) true Shows the zone tags and the price tags on trade levels and reference lines.
Show Entry / SL / TP Lines (InpShowTradeLevels) true Draws the entry, stop and target lines for confirmed signals. Does not change the signal buffers.
Trade Line Length (Bars) (InpTradeBars) 12 Length of the trade-level lines in bars.
Show Filtered-Out Crosses (InpShowRejected) true Draws a grey cross mark where a breakout was rejected.
Show Reference High/Low Lines (InpShowReference) true Draws the latest and the lookback reference highs and lows.
Show Status Overlay (InpShowOverlay) true Shows or hides the status overlay. Calculations continue while hidden.
Overlay Corner (InpOverlayCorner) Top left Chart corner for the status overlay.
Colours
Active Zone Color (InpZoneColor) DodgerBlue Colour of the active zone and of the entry line.
Buy Signal and Target Color (InpBullColor) SpringGreen Colour of buy signals, buy zones, target lines and reference lows.
Sell Signal and Stop Color (InpBearColor) Crimson Colour of sell signals, sell zones, stop lines and reference highs.
Filtered Cross Color (InpRejectedColor) SlateGray Colour of crosses rejected by a filter.
Alerts
Pop-Up Alert on Signal (InpAlertPopup) true Shows a terminal popup when a confirmed signal appears.
Mobile Push Notification (InpAlertPush) false Sends the signal to the MetaQuotes ID configured in the terminal.
Play Sound on Signal (InpAlertSound) false Plays a sound when a confirmed signal appears.
Alert Sound File (InpAlertSoundFile) alert2.wav WAV file in the terminal's Sounds folder.

Image for Range Compression Zones Breakout


Typical use cases and trading scenarios

Use case Example scenario Interpretation
Breakout after compression (buy) A zone forms, a candle closes above its high, the reference low is higher than 12 reference bars earlier, and volume is rising. A buy signal is confirmed on that candle. Review the stop at the bottom of the zone and the resulting target before relying on it.
Breakdown (sell) A candle closes below the zone low, the reference high is lower than 12 reference bars earlier, and volume is rising. A sell signal is confirmed. The stop is at the top of the zone.
Filtered breakout A candle closes above the zone high but the reference low is not higher, or volume is not rising. No signal. A grey cross is drawn, the zone is closed and the box turns grey.
Choosing the reference timeframe Trading M5 with D1 and a lookback of 12 versus W1 and a lookback of 12. The first compares today's context with about 12 days earlier, the second with about 12 weeks earlier. Compare the two on the same chart and data.
High-Low versus ATR mode Switching the mode while keeping Length and the threshold unchanged. The two modes measure range differently, so they find different compressions. Judge them on the same symbol and period.
Threshold research Lowering the threshold from 75% to 60%. Fewer, stricter compressions. It changes what qualifies, not how good a signal is.
Expert Advisor integration An EA reads BuySignal and SellSignal through iCustom. The EA can use the confirmed signals and apply its own execution, sizing and position rules.


Example workflow

  1. Attach the indicator and choose the range mode, Length and threshold. Make sure the chart has enough history: roughly two Length windows are needed before the first ratio appears.
  2. Pick the reference timeframe and lookback. The reference series must have history available; until it is loaded, the indicator waits and recalculates automatically.
  3. Watch the overlay: the ratio row shows when the last closed bar is compressed, and the zone row shows when a zone is armed.
  4. Wait for a closed candle to cross the zone. Check whether the result is an arrow or a grey cross, and read the zone tag.
  5. For a confirmed signal, review the stop at the zone boundary and the target at your reward-to-risk multiple.
  6. When comparing settings, keep the symbol, timeframe and period fixed and change one input at a time.


Who is this indicator best suited for?

User profile How it helps
Breakout and price-action traders Shows periods of narrowing range as boxes and applies the same rules to every breakout of them.
Multi-timeframe analysts Adds a higher-timeframe high/low comparison and shows the reference levels it uses.
Strategy developers Supplies the ratio, compression flag, range and signal buffers for custom indicators and Expert Advisors.
Researchers Makes it easy to compare thresholds, range modes, reference timeframes and volume settings on the same data.
Learners Separates the steps of compression, zone, cross, filters and trade plan, and shows which step rejected a breakout.

The indicator is best suited to users who understand range, ATR, higher-timeframe context and risk multiples. It supplies signals and reference levels. Execution, position sizing and account risk are left to you.


Important limitations and usage notes

  • Closed-bar timing: Zones and signals are evaluated on closed bars, and a confirmed signal does not change afterwards. The active zone box and the status overlay update while the current bar forms.
  • Alert timing: The alert appears when the bar after the signal candle opens. Each signal bar alerts once, and signals that existed when the indicator started do not alert.
  • Simple reference filter: The filter compares one reference bar with another Lookback bars earlier. It is not a trend measure and does not check what happened in between.
  • Reference lines show now: The reference lines and the Ref overlay row use the current state, so they do not show the levels that applied to older signals.
  • Reference data: The selected reference timeframe must have history available. Until it is loaded, the indicator waits and recalculates automatically.
  • Volume source: Tick volume is the default and its meaning depends on the broker and symbol. Select real volume if your symbol provides it.
  • Zones are not forecasts: A compression zone does not predict the direction of the next move or the chance of success, and a tighter ratio is not a quality score.
  • No performance statistics: The indicator does not report win rates, target hit rates or profitability. Counts in the overlay are detections only.
  • No order management: It does not place or modify orders and applies no trailing stop or break-even logic.
  • Settings change results: Length, threshold, mode, volume settings and the reference timeframe all change which zones and signals appear. More signals are not better signals.
  • Display range: Only the last Max History Bars to Render bars get boxes, arrows and trade lines. Older history is still calculated.
  • Independent implementation: The indicator is inspired by the range compression concept in D'Errico's study and is not a literal port of it.

Complement community code with advanced automation from RobotFX.

80037

Best MetaTrader Indicators + Profitable Expert Advisors