Loading…

Synthetic Price Series Generator

Backtesting against real history answers "did this work on what happened". It cannot answer "does my mean-reversion filter actually find mean reversion", because real history was not built to have that property on demand. This header generates series that were. SynthGenerateBrownian produces geometric Brownian motion: log returns drawn independently from Normal(drift, volatility) each bar, so price stays positive and the series' empirical log-return mean and standard deviation converge to the drift and volatility requested - the demo verifies this directly rather than asserting it. SynthGenerateJumpDiffusion adds a Merton-style jump on top: each bar also has an independent chance of an extra, larger log-return jump. Useful for checking that a stop-loss engine or a filter survives a gap instead of only ever being tested against smooth diffusion. SynthGenerateTrending is a plain arithmetic random walk with a fixed per-bar drift - additive, not compounding, because a moving-average or breakout test usually wants a checkable straight-line slope rather than exponential growth. SynthGenerateRanging produces a sine wave of known amplitude and period plus Gaussian noise, for testing oscillators and range-bound logic against a series that is mean-reverting by construction, with a period you chose rather than one you have to go looking for in history. SynthGenerateOHLC turns any of the above close-price series into full OHLC bars - open equals the prior close, and the high/low are built to satisfy High >= max(Open,Close) and Low <= min(Open,Close) by construction, an invariant most indicators assume and that a naive random-high random-low generator quietly violates. Every generator takes an explicit integer seed and reads from its own SynthRng stream - a small xorshift generator, not MathRand/MathSrand. That matters because this catalogue has other libraries that reseed the global generator for their own purposes; sharing it here would make "same seed, same series" a promise this header could not keep. Two SynthRng streams seeded identically always produce identical output, independent of anything else running in the same terminal. Both headers are self-contained. No dependencies, no DLLs, plain functions and one small struct, and no order, position or price-series API anywhere in either file - this is pure arithmetic, so both platform versions are the same algorithm end to end. Notes and limitations - xorshift32 is a fast, well-distributed PRNG, not a cryptographic one. It is the right tool for generating test fixtures, the wrong tool for anything security-sensitive - this header is only ever the former. - Box-Muller here discards the second Gaussian value from each pair of uniforms for simplicity. Costs roughly 2x the uniform draws a full implementation would need; does not affect the statistical validity of the output. - SynthGenerateOHLC's wick sizing is a Gaussian magnitude, not a realistic microstructure model - it exists to give indicators valid, non-degenerate O/H/L/C, not to resemble real intrabar path shape. - All generators overwrite the output array's contents entirely via ArrayResize; do not rely on any prior contents surviving a call. - Identical limitations on both platforms - none of them are platform specific.

Script · MT5 · v1.0 · Free

About Synthetic Price Series Generator

Synthetic Price Series Generator is a script for MetaTrader 5. It has 2 settings, such as Bars and Seed. MQL source code included.

Files in the download: SyntheticPriceGenerator.mq5.mqh, SyntheticPriceGenerator.txt, SyntheticPriceGeneratorDemo.ex5, SyntheticPriceGeneratorDemo.mq5.

Settings

SettingDefaultWhat it does
Bars2000Series length used for every generator below
Seed42Seed - same seed always reproduces the same series

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: Trend · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria