Consecutive Bar Direction Study
"It's had five green bars in a row, it's due a red one" is a claim about mean reversion that almost never gets checked against the instrument it is said about. This script checks it: it classifies every bar as up or down by close versus the prior close, tracks runs of the same direction, and for each run length that was actually reached in the loaded history, reports how often the very next bar continued the streak. Continuation is measured at the EXACT length reached, not "length or more". Folding a six-bar streak into a "three or more" bucket's average hides whether whatever edge exists grows, fades or stays flat as the streak extends, which is the entire point of laying the table out by length in the first place. The table also shows how many times a run of each length ended there, independent of the continuation statistic - a length that gets reached often but rarely continues is a different finding from one that is simply rare. Notes and limitations - Direction is close versus the PRIOR close, not open versus close of the same bar, so it reflects the actual price path rather than a single bar's internal shape. - Run lengths of 10 bars or more are pooled into one "10+" bucket to keep the table readable; long streaks are rare enough that a per-length row beyond that point would usually hold only a handful of samples. - This is a descriptive study, not a trading signal. A continuation rate above or below fifty percent by a small margin on a small sample is not evidence of an edge; check the sample counts before acting on the table. - Says nothing about spread, slippage or the size of the move on continuation versus reversal - only whether the direction continued.
Script · MT4 · v1.0 · Free
About Consecutive Bar Direction Study
Consecutive Bar Direction Study is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Symbol, Timeframe and Max bars. MQL source code included.
Files in the download: ConsecutiveBarDirectionStudy.ex4, ConsecutiveBarDirectionStudy.mq4, ConsecutiveBarDirectionStudy.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Symbol | Symbol to study, blank = this chart's symbol | |
| Timeframe | PERIOD_D1 | Timeframe to study |
| Max bars | 3000 | Most recent bars to include |
| Save csv | true | Write the run-length table to a CSV file |
| Delimiter | DelimiterComma | CSV column separator |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Script · MQL4 Source Code