Loading…

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 · MT4 · v1.0 · Free

About Range Break Direction Bias Study

Range Break Direction Bias Study is a script for MetaTrader 4 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.mq4, RangeBreakDirectionBias.txt.

Settings

SettingDefaultWhat it does
SymbolSymbol to study, blank = this chart's symbol
TimeframePERIOD_H1Timeframe to study
Max bars5000Most recent bars to include
Atr period14ATR period used to judge compression
Range bars20Bars in the candidate consolidation window
Compression atr mult1.5Window range must be at most this multiple of ATR
Breakout buffer pips3.0Close must clear the edge by this many pips to count as a break
Breakout search bars10Bars after the window checked for a breakout
Trend lookback bars20Bars before the window used to judge the prior trend
Trend min pips10.0Minimum prior move to call a trend, else "no clear trend"
Save csvtrueWrite every resolved breakout to a CSV file
DelimiterDelimiterCommaCSV column separator

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Breakout · ATR · Trend · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria