Random Baseline Generator
A raw win rate on its own is close to meaningless. A fixed 30-pip stop and 90-pip target wins more than half the time on pure noise purely because the target sits three times further away than the stop - that is arithmetic, not edge. Comparing a strategy's win rate to 50% is comparing it to the wrong number. This header builds the right number instead: for every real trade's exit rule (buy or sell, holding period in bars, stop distance, target distance) it enters at a RANDOM bar chosen from the symbol's own price history, then walks the exact same stop/target/time-exit logic forward against real candles. The result is a control group with identical exit mechanics to the real trade list, differing only in when it got in - the one variable a strategy's entry signal is actually supposed to add value on. RBG_RunBatch takes an array of RBG_TradeSpec (one per real trade, so uneven holding periods and mixed buy/sell trade lists are matched exactly, not averaged into one generic rule) and returns one RBG_TrialResult per trial with the resolved entry/exit prices and outcome in both points and R-multiples. RBG_EdgeZScore then reads how many standard deviations the real strategy's mean R sits from the baseline's own mean, using the baseline's sampling standard error - a plain z-score against the random control, not a formal significance test, since trade counts in this domain are usually too small for one. MathSrand is seeded explicitly from InpRandomSeed so a given seed reproduces an identical baseline on every run - reviewing a strategy against a target that moves every time you press F7 would make the whole comparison worthless. Notes and limitations - RBG_MAX_TRIALS (500) bounds one RBG_RunBatch call - raise it in the header if a review genuinely needs more trials at once. - Random entries are drawn uniformly across the requested shift range, independent of each other - the generator does not avoid overlapping entry/holding windows between trials, so at high trial counts near- identical windows can repeat. This matches how an entry-timing null hypothesis should behave and is not a bug. - A bar with a missing/zero High or Low (a gap in local history) is skipped rather than treated as a stop/target hit, which can very rarely let a trial run slightly past its intended holding window before a valid bar is found to exit on. - RBG_EdgeZScore is a plain z-score against the baseline's own sampling distribution, not a peer-reviewed significance test - treat a large value as evidence worth investigating further, not as proof.
Script · MT5 · v1.0 · Free
About Random Baseline Generator
Random Baseline Generator is a script for MetaTrader 5. It has 7 settings, such as Trade count, Holding bars and Sl points. MQL source code included.
Files in the download: RandomBaselineGenerator.mq5.mqh, RandomBaselineGenerator.txt, RandomBaselineGeneratorDemo.ex5, RandomBaselineGeneratorDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Trade count | 40 | Number of trades in the synthetic real trade list to match |
| Holding bars | 12 | Bars held per trade before a time-based exit |
| Sl points | 300 | Stop distance in points |
| Tp points | 300 | Target distance in points (equal to stop -> pure coin-flip exit shape) |
| Oldest shift | 400 | Oldest bar shift random entries may be drawn from |
| Newest shift | 20 | Newest bar shift random entries may be drawn from (leaves room to walk forward) |
| Random seed | 20260817 | Seed for reproducible baseline generation |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT5 Script · MQL5 Source Code