Return Distribution And Tail Report
Most position sizing and stop placement, quietly or explicitly, assumes returns are roughly normal. They are not, and the gap matters most exactly when it is most expensive - in the tails. This script measures the actual shape of a symbol's close-to-close returns: mean, standard deviation, skewness, excess kurtosis, and a full set of quantiles from the 1st to the 99th percentile, computed directly from history rather than assumed. Returns are reported as percent, never as points or money. A percent return means the same thing on EURUSD, gold and an index CFD, so the shape of one instrument's tails can be compared honestly against another's - pip and point arithmetic cannot do that across instrument classes. Skewness and kurtosis use the bias-adjusted sample estimators - the same formulas behind Excel's SKEW and KURT functions - rather than the raw population moments some textbooks use instead. That choice means the numbers this script prints line up with what a trader checking the same series in a spreadsheet would see, instead of quietly disagreeing by a small but confusing amount. A simple tail-ratio figure is also printed: the distance from the median to the 99th percentile, divided by the distance from the 1st percentile to the median. A value near 1.0 says the tails are roughly symmetric; well above or below 1.0 says one side of the distribution runs further than the other, independent of any assumption about its shape. Notes and limitations - This is a descriptive study of the loaded history, not a forecast - a distribution measured over the last N bars is not guaranteed to hold for the next N. - Close-to-close returns miss any intrabar excursion; a report built on a higher timeframe will understate how large intrabar swings actually get. - Skewness and kurtosis are sensitive to sample size - a report run on a short history will move around more than the underlying shape actually does. Compare across similar sample sizes when judging whether a difference is real. - Quantiles use linear interpolation between the two nearest sorted observations, the same default most spreadsheet and statistics packages use.
Script · MT5 · v1.0 · Free
About Return Distribution And Tail Report
Return Distribution And Tail Report is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Symbol, Timeframe and Max bars. MQL source code included.
Files in the download: ReturnDistributionTailReport.ex5, ReturnDistributionTailReport.mq5, ReturnDistributionTailReport.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Symbol | Symbol to study, blank = this chart's symbol | |
| Timeframe | PERIOD_D1 | Timeframe whose bar returns are measured |
| Max bars | 2000 | Most recent bars to include |
| Save csv | true | Write every individual return to a CSV file |
| Delimiter | DelimiterComma | CSV column separator |
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: Risk & Lot Size · Alerts · MT5 Script · MQL5 Source Code