Loading…

Optimisation Deflation Reporter

Run enough parameter combinations and the best one will look great by chance alone, even with a strategy that has no real edge. This is the multiple-testing problem, and the standard correction for it is the Deflated Sharpe Ratio from Bailey and Lopez de Prado: the observed best Sharpe ratio is checked not against zero, but against the expected maximum Sharpe ratio that N independent, skill-less trials would produce by luck, given how spread out the trial results were. What is left after that correction is reported as a probability that the true Sharpe is still above zero. The Strategy Tester's Optimization tab has no MQL4 API that lets an attached EA read the full results grid automatically - there is no function to enumerate every pass's Sharpe ratio from inside a running program. This tool is honest about that: the trader supplies the aggregate figures (best Sharpe, trial count, spread of Sharpe across trials, and the return distribution's skew/kurtosis if known) that the Optimization tab already shows, and this EA does the correction arithmetic that is otherwise easy to skip. It reimplements the normal CDF (Abramowitz & Stegun polynomial approximation) and the normal quantile function (Peter Acklam's rational approximation) locally, since MQL4 ships neither and house style forbids including another project's header. Notes and limitations The result is only as trustworthy as the four numbers typed in - this tool performs the correction arithmetic, it does not and cannot verify the inputs against the tester's own results grid. Treat InpSharpeStdDevAcrossTrials especially carefully: if it is guessed too low, the benchmark understates how much luck could explain the best result, and the reported Deflated Sharpe Ratio will look more convincing than it should. When skew/kurtosis are left at their normal-distribution defaults, the correction only accounts for trial-count bias, not fat tails in the strategy's own returns.

Expert advisor · MT4 · v1.0 · Free

About Optimisation Deflation Reporter

Optimisation Deflation Reporter is a script for MetaTrader 4. It has 11 settings, such as Corner, X offset and Y offset. MQL source code included.

Files in the download: OptimisationDeflationReporter.ex4, OptimisationDeflationReporter.mq4, OptimisationDeflationReporter.txt.

Settings

SettingDefaultWhat it does
Corner0Panel corner: 0=top-left 1=top-right 2=bottom-left 3=bottom-right
X offset12Panel offset from the chosen corner, X pixels
Y offset18Panel offset from the chosen corner, Y pixels
Best sharpe1.20Best (in-sample) annualised Sharpe ratio found across the optimisation
Num trials200Number of parameter combinations tested in the optimisation
Sharpe std dev across trials0.35Std dev of the Sharpe ratio across all trials - the "how spread out were the results" figure
Return skewness0.0Skewness of the strategy's per-period returns (0 if unknown)
Return kurtosis3.0Kurtosis of the strategy's per-period returns (3.0 = normal distribution, if unknown)
Num returns250Track record length: number of return observations behind InpBestSharpe (e.g. trading days)
Write report filetrueAlso write the report to MQL4\Files\
Report file nameOptimisationDeflationReport.txtOutput file name (only used if InpWriteReportFile)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria