A rolling Wald–Wolfowitz runs-test engine classifies recent bar direction as persistent, alternating, or indistinguishable from noise before any entry logic is applied. The package includes full MQL5 source, a chart indicator, a three-mode Expert Advisor (Gated, No gate, Placebo), validation scripts, and an audit log. An 18‑run Strategy Tester matrix with fixed window and critical value, plus a null‑rate calibration on real history, shows how a regime gate changes trade frequency and drawdown.
Most of what a trader calls "momentum" or "mean reversion" is a claim about the order that bars arrive in, not just their count. The Wald–Wolfowitz runs test is a classic statistic built for exactly that question: given a sequence of up and down bars, does the pattern of switching between them look random, or does it cluster into runs that are too long or too short to be chance? I kept coming back to it because it answers a narrower, more honest question than most "trend detectors" do: not "is the market trending," but "given exactly this many up bars and down bars, is the order they arrived in distinguishable from a random shuffle of the same ups and downs, at this window length, right now." That's a conditional test on the observed mix of signs, not a claim that bar direction itself is a fair coin flip with p=0.5 — the runs test never assumes that, and neither does anything built on top of it here.
This article is a diagnostic and research tool, not a plug-and-play profit system. It ships a rolling runs-test engine, a chart indicator, two validation scripts, and an Expert Advisor that trades off the regime label the engine produces. The backtest section reports what that gate actually did across eighteen runs, including the runs where it lost money and the one where almost all of the profit came from a single cluster of trades. None of the numbers below are illustrative — every one is read off a real Strategy Tester report.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Gating Trades with the Wald-Wolfowitz Runs Test: An O(1) Randomness Filter for Bar Direction.
Most of what a trader calls "momentum" or "mean reversion" is a claim about the order that bars arrive in, not just their count. The Wald–Wolfowitz runs test is a classic statistic built for exactly that question: given a sequence of up and down bars, does the pattern of switching between them look random, or does it cluster into runs that are too long or too short to be chance? I kept coming back to it because it answers a narrower, more honest question than most "trend detectors" do: not "is the market trending," but "given exactly this many up bars and down bars, is the order they arrived in distinguishable from a random shuffle of the same ups and downs, at this window length, right now." That's a conditional test on the observed mix of signs, not a claim that bar direction itself is a fair coin flip with p=0.5 — the runs test never assumes that, and neither does anything built on top of it here.
This article is a diagnostic and research tool, not a plug-and-play profit system. It ships a rolling runs-test engine, a chart indicator, two validation scripts, and an Expert Advisor that trades off the regime label the engine produces. The backtest section reports what that gate actually did across eighteen runs, including the runs where it lost money and the one where almost all of the profit came from a single cluster of trades. None of the numbers below are illustrative — every one is read off a real Strategy Tester report.
Author: Olamide Daniel Adebayo