Loading…

Synthetic Price Series Generator

Every backtest, however careful, runs on the one sequence of prices that already happened. A strategy tuned against that exact sequence can look excellent and still be fitted to noise that will never repeat. Testing against a synthetic series generated from the same symbol's statistical properties - same rough volatility, same style of return - is a cheap way to see whether a strategy's edge survives a market that resembles the real one without being it. Two generation methods are offered because they fail differently, and knowing which one broke a strategy is useful information. A Gaussian random walk draws each bar's return independently from a normal distribution fitted to the source symbol's mean and standard deviation of log returns - the textbook null model, useful precisely because real markets are not actually like this. A strategy that only works because it profits from Gaussian noise is not doing anything real. Block bootstrap instead resamples contiguous chunks of the symbol's own historical returns and stitches them together, which keeps real fat tails and real volatility clustering while still breaking the specific ordering of events the strategy may have been tuned around. Each synthetic close is built from cumulative returns starting at a chosen price. Wick range around each bar's body is drawn from the source symbol's own distribution of (high-low)/close, and volume is resampled from the source's own tick volumes, so the file has plausible-looking bars rather than a bare line of closes. Notes and limitations - This is a statistical stand-in, not a simulation of any real future. It exists to stress-test a strategy against plausible-looking noise, not to forecast anything. - Bars are spaced evenly by the timeframe's step with no weekend or holiday gaps modelled - the output is a continuous synthetic tape, not a calendar match to a real trading week. - Wick range and volume are drawn independently of the bar's own return, so the file will not show the real correlation between a big move and a wide range on the same bar. This keeps the model simple and honest about what it does and does not capture; see the source for exactly what is sampled. - The Gaussian method assumes independent, identically distributed returns, which real markets are not. That mismatch is the point of offering the bootstrap method alongside it, not a flaw to be fixed. - Needs at least 30 real source bars to calibrate from; fewer than that and the script refuses to run rather than produce a series calibrated on almost nothing.

Script · MT5 · v1.0 · Free

About Synthetic Price Series Generator

Synthetic Price Series Generator is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 8 settings, such as Source symbol, Source timeframe and Source history bars. MQL source code included.

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

Settings

SettingDefaultWhat it does
Source symbolSource symbol for calibration ("" = this chart's symbol)
Source timeframePERIOD_CURRENTSource timeframe for calibration
Source history bars2000Real bars read from the source to calibrate/bootstrap from
MethodMethodRandomWalkGaussianGeneration method
Block length20Bars per resampled block (bootstrap method only)
Bar count1000Number of synthetic bars to generate
Start price0.0Starting price (0 = source symbol's latest close)
Random seed00 = a different series every run, otherwise reproducible

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