Loading…

Random Walk Versus Market Comparison

A backtest report that shows a rising equity curve, a plausible drawdown and a healthy-looking win rate feels like evidence of an edge. Often it is not, and the uncomfortable way to see that is to build a synthetic series that has zero real predictive structure - pure random noise - matched only to the real market's volatility, and look at whether its statistics land in the same neighbourhood. They frequently do. This script does exactly that comparison, on demand, against whatever chart it is run on. It measures the real series' bar-to-bar return volatility, generates a same-length synthetic walk with zero drift and that same volatility using a Box-Muller transform over MathRand() - a uniform generator alone would produce a visibly different-shaped distribution, so a proper normal approximation is used - and reports both series' total return, maximum drawdown, percentage of up bars, longest run of same-direction bars, and lag-1 autocorrelation of returns. None of this proves a strategy has or lacks an edge. It demonstrates the narrower and more useful thing: which of the metrics a typical strategy report leads with are also produced by structureless noise at the same volatility, and are therefore weak evidence on their own. Autocorrelation is the one number here that a pure random walk should sit near zero on while real price action sometimes does not - that gap, not the shape of the equity curve, is closer to what "edge" actually needs to look like statistically. Notes and limitations - The synthetic walk is built with zero drift on purpose, so its total return is driven by volatility and randomness only. It is not trying to reproduce the real series' trend, only its volatility. - MathRand() has a limited period and is not cryptographically random; it is entirely adequate for this purpose, which needs plausible noise, not unpredictability that matters for anything security-sensitive. - This tool does not evaluate any specific trading strategy. It compares aggregate statistics of price series, real and synthetic, and says nothing about the profitability of any rule applied to either one. - A single run's synthetic walk is one random draw. Statistics that happen to differ noticeably from the real series in one run can land much closer in another - re-run a few times, or fix InpRandomSeed across several manual runs with different seeds, before drawing a conclusion.

Script · MT5 · v1.0 · Free

About Random Walk Versus Market Comparison

Random Walk Versus Market Comparison is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Bars to analyze and Random seed. MQL source code included.

Files in the download: RandomWalkVersusMarketComparison.ex5, RandomWalkVersusMarketComparison.mq5, RandomWalkVersusMarketComparison.txt.

Settings

SettingDefaultWhat it does
Bars to analyze500How many recent closed bars to use from the real chart
Random seed0Seed for the synthetic walk (0 = derive from the current time)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria