Range Break Direction Bias Study
"Ranges resolve in the direction of the prior trend" is a common assumption behind breakout entries, but it is rarely checked against the specific instrument being traded. This script checks it directly: it scans for windows where price compressed to within a set multiple of ATR, then watches forward for the first close that clears either edge of that range by a buffer, and compares the breakout direction to the trend measured in the bars immediately before the range began. Consolidations are detected as non-overlapping events. Once a compressed window is found and its breakout is resolved (or the search window runs out with no breakout), the scan resumes after that point rather than re-testing every bar inside a range that is still compressed - without that, a single quiet stretch would be counted as dozens of near-identical "new" consolidations. Prior trend is measured over a separate lookback ending exactly where the consolidation window starts, using a minimum-pips threshold so that a genuinely flat run-up is reported honestly as "no clear trend" rather than forced into an up or down bucket by a coin-flip sign. Notes and limitations - This is a descriptive study, not a trading signal. A with-trend percentage a few points either side of fifty on a small sample is not evidence of an edge; check the resolved-event count first. - A compressed window with no qualifying breakout within InpBreakoutSearchBars is counted as "unresolved" and excluded from the direction statistics rather than forced into a guess. - ATR-based compression is one reasonable definition of a range, not the only one - a different InpCompressionAtrMult or InpRangeBars will find a different set of windows on the same data. - The prior-trend measurement is a plain price displacement over a fixed lookback, not a statistical significance test - it says nothing about how strong or clean that prior move was, only its net direction and size.
Script · MT5 · v1.0 · Free
About Range Break Direction Bias Study
Range Break Direction Bias Study is a script for MetaTrader 5 based on ATR. It can alert you with a pop-up, sound, email or push message. It has 12 settings, such as Symbol, Timeframe and Max bars. MQL source code included.
Files in the download: RangeBreakDirectionBias.ex5, RangeBreakDirectionBias.mq5, RangeBreakDirectionBias.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Symbol | Symbol to study, blank = this chart's symbol | |
| Timeframe | PERIOD_H1 | Timeframe to study |
| Max bars | 5000 | Most recent bars to include |
| Atr period | 14 | ATR period used to judge compression |
| Range bars | 20 | Bars in the candidate consolidation window |
| Compression atr mult | 1.5 | Window range must be at most this multiple of ATR |
| Breakout buffer pips | 3.0 | Close must clear the edge by this many pips to count as a break |
| Breakout search bars | 10 | Bars after the window checked for a breakout |
| Trend lookback bars | 20 | Bars before the window used to judge the prior trend |
| Trend min pips | 10.0 | Minimum prior move to call a trend, else "no clear trend" |
| Save csv | true | Write every resolved breakout to a CSV file |
| Delimiter | DelimiterComma | CSV column separator |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Breakout · ATR · Trend · Alerts · MT5 Script · MQL5 Source Code