Loading…

Empirical CDF Utilities

The empirical CDF is simply the sorted sample itself. EcdfBuild() sorts a copy once; EcdfEvaluate(x) then answers "what fraction of the sample is at or below x" via a binary search on the sorted copy; EcdfInverse(p) answers the reverse question, "what value sits at percentile p", by linearly interpolating between the two bracketing order statistics (the same convention as the widely used Hyndman & Fan type-7 quantile method, the default in many statistics packages). Neither direction assumes the sample is normally distributed, log-normal, or fits any other named parametric family - it works directly off whatever the recorded data actually looks like, which matters for trade P/L and slippage distributions in particular, since they are routinely fat-tailed and skewed in ways a normal-distribution assumption would understate. EcdfMedian() and EcdfInterquartileRange() are built directly on EcdfInverse() rather than separate implementations, so they inherit the exact same interpolation convention as any other percentile query against the same sample. Notes and limitations - EcdfBuild's sort is an O(n^2) insertion sort, chosen for simplicity over an external sort include - each CodeBase submission must stand alone. Fine for the tens-to-low-hundreds sample sizes typical of trade or bar statistics; not intended for thousands-of-points tick series. - All query functions expect sorted[] to already be ascending, as produced by EcdfBuild - passing an unsorted array silently produces wrong answers with no error, since there is no way to verify sortedness cheaply without re-sorting. - EcdfInverse's linear interpolation is one specific, common convention among several published quantile-estimation methods; a caller cross-checking against a different statistics package should confirm which convention that package uses, since small differences near the tails are expected. - This is purely descriptive (what the sample IS), not inferential - it makes no claim about a population the sample was drawn from, and offers no confidence intervals or hypothesis tests.

Script · MT5 · v1.0 · Free

About Empirical CDF Utilities

Empirical CDF Utilities is a script for MetaTrader 5. It has 1 setting, such as Sample size. MQL source code included.

Files in the download: EmpiricalCdfUtilities.mq5.mqh, EmpiricalCdfUtilities.txt, EmpiricalCdfUtilitiesDemo.ex5, EmpiricalCdfUtilitiesDemo.mq5.

Settings

SettingDefaultWhat it does
Sample size25Number of synthetic trade P/L values to build the ECDF from

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

MQL4 & MQL5 scripts · PolyMaria