Loading…

Quasi Random Sequences

Independent uniform random draws clump: with enough points some regions of the sweep space get several nearby draws while other regions get none, purely by chance. A low-discrepancy ("quasi-random") sequence is constructed deliberately to avoid that clumping - every new point fills whichever gap is currently largest, so a parameter sweep or scenario batch covers its space far more evenly for the same number of draws. This library implements the Halton sequence, built from the radical inverse of the point index in a chosen prime base: write the index in that base, then read its digits back to front after the "decimal point". Using a different prime per dimension keeps dimensions decorrelated from one another, which is the standard multi-dimensional Halton construction used here. HONEST SCOPE NOTE, read before use. Only Halton is implemented - not Sobol. A genuine Sobol sequence needs precomputed direction numbers per dimension, normally drawn from published tables of hundreds of primitive polynomials with their own associated direction-number sets. Embedding that correctly inside one self-contained header, without either shipping a large baked-in table or risking a subtly wrong from-scratch derivation, was judged impractical for this submission. Rather than publish a "Sobol" function that is actually something else, this library states plainly what it provides: a real Halton implementation, which already beats plain pseudo-random coverage for the same purpose, just via an older and simpler construction than Sobol. A largest-gap coverage statistic is included so the improvement over random draws can be checked numerically rather than taken on faith - see the demo. Notes and limitations - Sobol is not implemented - see the honest scope note above. Do not treat any function in this header as a Sobol generator. - Halton's coverage quality degrades in higher dimensions as the prime bases grow larger, a known and documented weakness of Halton relative to Sobol. This header caps multi-dimensional generation at 16 dimensions (the first 16 primes) as a practical ceiling, not a hard mathematical limit, but quality above roughly 6-8 dimensions should not be assumed good without checking. - The largest-gap coverage statistic in the demo is a simple proxy, not the formal star-discrepancy figure used in the academic literature (which needs a supremum over all sub-intervals and is expensive to compute exactly) - it is honest and directionally correct, not a rigorous metric. - No live account, order, or symbol-info call anywhere in this library - pure array arithmetic, no trading risk of its own.

Script · MT5 · v1.0 · Free

About Quasi Random Sequences

Quasi Random Sequences is a script for MetaTrader 5. It has 2 settings, such as Point count and Random seed. MQL source code included.

Files in the download: QuasiRandomSequences.mq5.mqh, QuasiRandomSequences.txt, QuasiRandomSequencesDemo.ex5, QuasiRandomSequencesDemo.mq5.

Settings

SettingDefaultWhat it does
Point count20How many sequence points to print/compare
Random seed7Seed for the comparison random sequence

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

MQL4 & MQL5 scripts · PolyMaria