Loading…

Winsorised Performance Metrics

A single enormous winning trade can make a mediocre system's Sharpe ratio and profit factor look outstanding; a single disastrous loss can make a genuinely good system look broken. Both plain metrics are computed from a sum and a variance, and neither statistic has any built-in resistance to one point sitting far outside the rest of the sample - the breakdown point of an ordinary mean and standard deviation is 0%, a single arbitrarily large value has unbounded influence on both. WinsorisedMetrics applies the same fix underlying most robust-statistics techniques: clip (winsorise) the most extreme trimFraction of the P&L sample at each end to the value sitting at that trim boundary, THEN compute Sharpe, profit factor and expectancy from the clipped sample. Winsorising CLIPS rather than discards, so every trade still counts once toward the sample size - it simply cannot pull the metric further than the boundary allows. Plain (non-winsorised) versions of each metric are exposed alongside the winsorised ones purely so a caller can print them side by side and see how much a given sample's metrics actually depend on its most extreme point. Profit factor is winsorised by clipping the WHOLE P&L array first (wins and losses share the same trim boundaries, exactly as a winsorised mean would), then splitting the clipped values by sign into gross profit and gross loss - not by separately winsorising the wins and losses as two independent samples, which would apply a different effective trim fraction to each side. Notes and limitations - trimFraction is clamped to 0.0..0.49 internally; trimming 50% or more from each end would leave nothing, so the clamp is silent rather than an error - check the returned metric against your intended fraction if you passed something outside that range. - WmWinsorisedProfitFactor returns 0.0 if the winsorised sample has no losses at all (the classic profit-factor formula is undefined/infinite in that case) - treat a returned 0.0 alongside a check of gross loss before assuming the system genuinely has a zero profit factor. - Winsorising trades the ordinary metrics' full sensitivity for resistance to outliers - a genuinely bimodal strategy (many small losses, occasional deliberately large wins by design, e.g. a trend system) will have its real edge partly clipped away by winsorising too. These are a robustness check to run ALONGSIDE the plain metrics, not a wholesale replacement for them. - All sorting inside WmWinsorisedCopy is an O(n^2) insertion sort, chosen for simplicity over an external sort include - fine for the tens-to-low-hundreds of trades a typical performance review covers.

Script · MT5 · v1.0 · Free

About Winsorised Performance Metrics

Winsorised Performance Metrics is a script for MetaTrader 5. It has 3 settings, such as Trade count, Outlier win and Trim fraction. MQL source code included.

Files in the download: WinsorisedMetrics.mq5.mqh, WinsorisedMetrics.txt, WinsorisedMetricsDemo.ex5, WinsorisedMetricsDemo.mq5.

Settings

SettingDefaultWhat it does
Trade count25Number of ordinary synthetic trades
Outlier win400.0Size of the single injected outlier winner
Trim fraction0.10Winsorising trim fraction, each end

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

MQL4 & MQL5 scripts · PolyMaria