Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Scripts

A script for a tester that extends the standard MetaTrader 5 optimisation features - script for MetaTrader 5

Published by:
Vladimir Novikov
Views:
211
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
Explanation of the code and its application

What is this code?

This code is acustom optimisation function for the MetaTrader 5 Strategy Tester. It is not an Expert Advisor, indicator or script in the classical sense, but a special script for analysing test results.

How the code works:

1. Data collection

  • Gets the history of trades from the tester

  • Checks minimum requirements (at least 50 trades)

  • Determines initial deposit and time periods

2. Splits the data

  • Splits trades into two periods:

    • In-Sample (IS) - the first 70% of the testing period

    • Out-of-Sample (OOS) - the last 30% of the period with a 1-day interval

3. Calculation of metrics

Calculates a set of metrics for both periods:

  • Profitability and drawdown

  • Sharpe and Sortino ratios

  • Profit factor and probability of profitable transactions

  • Statistical indicators (skewness, kurtosis)

  • Special metrics (Serenity Ratio)

4. Statistical analysis

  • Compares IS and OOS distributions using the Kolmogorov-Smirnov test

  • Checks normality of distributions using the Jarque-Bera test

5. Strategy evaluation

Creates a comprehensive strategy evaluation that takes into account:

  • Profitability (30%)

  • Consistency of results (30%)

  • Risk-adjusted performance (25%)

  • Statistical quality (15%)

Where to use this code:

1. strategy optimisation

  • Place the code in the MQL5/Scripts/ folder.

  • In the strategy tester, select "Custom optimisation criterion"

  • Use this script to evaluate the results of optimisation

2. Strategy validation

  • Use to validate the stability of the strategy

  • Analyse discrepancies between IS and OOS periods

  • Identification of over-optimised strategies

3. Comparison of strategies

  • To objectively compare different strategies

  • To rank strategies according to a comprehensive criterion

Advantages of the approach:

  • Minimising over-optimisation through data partitioning

  • Comprehensive evaluation takes into account múltiples aspects of performance

  • Statistical verification of the robustness of the results

  • Automatic screening of non-viable strategies

Important Notes:

  • Requires a significant number of trades (at least 50)

  • Need sufficient historical period to split into IS/OOS

  • Code returns -DBL_MAX for strategies that do not pass minimum requirements

This approach is particularly useful for traders and developers who want to take testing and optimising trading strategies seriously, minimising the risk of fitting to historical data.


Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/63121

3 way Aroon value calculation 3 way Aroon value calculation

Showing different ways of the Aroon values calculation

Pinbar Detector Pinbar Detector

This MQL5 indicator identifies Upward (Bullish) and Downward (Bearish) Pinbars, displayed with customizable arrows (lime for upward, red for downward). It allows fine-tuning of detection parameters like tail body ratio and protrusion. Pop-up and push notification alerts signal new pinbars. Ideal for traders seeking precise reversal pattern detection.

Balance Of Power Balance Of Power

The Balance of Power (BOP) is an indicator originally developed by Igor Livshin in 2001 to measure the balance of power between buyers and sellers during each candle.

PriceVar PriceVar

PriceVar% is an indicator designed to measure the percentage difference between the price and a moving average, highlighting the strength of the market movement in relation to a reference value.