Loading…

Spread Percentile Sampler

An average spread hides exactly the thing that matters for entry timing: how bad the occasional spike gets. Two symbols with the same mean spread can have very different tails - one stays calm, the other blows out around news or a thin liquidity window - and a single average number cannot tell them apart. The median shows the "normal" spread a trader should expect most of the time; the 90th percentile shows the "watch out for this" number that a fixed-distance stop or a spread filter needs to be sized against; the worst case is exactly that, the single widest moment observed during the sampling window. The script accepts a comma-separated symbol list (or defaults to the current chart symbol), samples MODE_SPREAD in rounds at a configurable interval, and reports all three figures per symbol once the burst finishes. Notes and limitations Spread is read via MarketInfo(symbol, MODE_SPREAD) once per round for every symbol in the list - this is the broker-quoted spread at that instant, not a tick-by-tick record of every spread change between rounds, so genuinely brief spikes shorter than the sampling interval can be missed entirely. A symbol not already selected in Market Watch is added automatically (SymbolSelect) so its spread can be read live; if a symbol is unknown to the broker it is skipped and reported as such rather than silently producing a zero row. Percentile uses the nearest-rank method on the sorted sample set, which is simple and adequate for a burst of a few dozen samples - it is not a smoothed/interpolated percentile estimator.

Script · MT5 · v1.0 · Free

About Spread Percentile Sampler

Spread Percentile Sampler is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Symbols, Sample count and Interval ms. MQL source code included.

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

Settings

SettingDefaultWhat it does
SymbolsComma-separated symbols (blank = current chart symbol)
Sample count50Samples to take per symbol
Interval ms500Delay between sampling rounds (milliseconds)

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

MQL4 & MQL5 scripts · PolyMaria