Loading…

Runs Test Randomness

"This market feels trendy" or "this market feels choppy" is usually a judgement call. The runs test turns it into a number: count the directional runs (unbroken streaks of up-closes or down-closes) in a window, compare that count against the number of runs a genuinely random up/down sequence with the same proportion of up and down bars would be expected to produce, and express the gap as a z-score. A strongly negative z-score means far fewer runs happened than chance would predict - closes are clumping into longer streaks than random, the signature of persistence. A strongly positive z-score means far more runs happened than chance would predict - the market is flipping direction more often than random, the signature of choppiness or mean reversion. Values near zero say the sign sequence looks statistically unremarkable, which is itself useful information before trusting a trend or mean-reversion system on this instrument right now. Flat bars (a close identical to the previous close) are excluded from the sequence entirely rather than assigned an arbitrary sign, matching the standard textbook treatment of the runs test - assigning them a sign either way biases the run count in that direction's favour. Notes and limitations - This tests the SIGN sequence only; it says nothing about the size of moves, so a streak of tiny up-bars scores identically to a streak of large ones. - A window that happens to be all up-bars or all down-bars produces an undefined variance and is left blank rather than reported as an infinite z-score. - Statistical significance is not the same as profitability - a genuinely non-random sign sequence does not by itself imply an exploitable edge net of spread and slippage. - This does not size a position, place a stop, or generate trade signals.

Indicator · MT4 · v1.0 · Free

About Runs Test Randomness

Runs Test Randomness is an indicator for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Period, Min non flat bars and Significance level. MQL source code included.

Files in the download: RunsTestRandomness.ex4, RunsTestRandomness.mq4, RunsTestRandomness.txt.

Settings

SettingDefaultWhat it does
Period60Bars in the rolling runs-test window
Min non flat bars20Minimum non-flat bars required before a reading is produced
Significance level1.96|Z| beyond this is treated as statistically significant (1.96 = 5%)
AlertstrueAlert once per closed bar when significance is newly crossed

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 → Indicators.
  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 indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Trend · Alerts · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria