Watch how to download trading robots for free
Find us on Twitter!
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
Libraries

TesterStats: Strategy Tester report statistics in MQL5 code - library for MetaTrader 5

Mohamed-amine Baddir
Mohamed-amine Baddir
I build Expert Advisors for MetaTrader 5, and I test them properly before you trade them.
What I do:
- Turn your strategy, TradingView script or written rules into a clean MT5 Expert Advisor
Views:
54
Published:
\MQL5\Include\
TesterStats.mqh (17.1 KB) view
\MQL5\Experts\
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

TesterStats.mqh calculates the statistics of the Strategy Tester report from the deal history. It also gives the ones that TesterStatistics() does not return: Z-Score, AHPR, GHPR, LR Correlation and LR Standard Error. You can use them in a custom optimization criterion, or on a live account to get the same numbers as in a backtest report.

TesterStats in OnTester() and the tester report of the same test

#include <TesterStats.mqh>

CTesterStats stats;

void OnTick()
  {
   stats.TrackEquity();      // only needed for the equity drawdown and the recovery factor
   ...
  }

double OnTester()
  {
   stats.Calculate();        // or stats.Calculate(magic, symbol)
   Print(stats.Text());
   return(stats.ghpr);
  }

I checked it against the tester in 5 tests (EURUSD, USDJPY, XAUUSD, fixed lots and percent risk, with and without TesterWithdrawal) by comparing 44 values with TesterStatistics() and the HTML report. With "1 minute OHLC" and "Every tick" all 44 were the same. With "Every tick based on real ticks" the tester checks the equity less often, so the equity drawdown here was 0.05% to 0.26% deeper; the other values were the same.

Rules of the report that the code follows: a trade with a result of 0.00 counts as a profit trade; deposits and withdrawals after the start are kept out of the balance drawdown, and for the equity drawdown a withdrawal starts a new peak; AHPR and GHPR count a withdrawal as a loss; the Z-Score probability is taken from Z rounded to 2 digits. Sharpe Ratio is not included. Tested on accounts without commission.

TesterStatsExample.mq5 is a moving average cross whose optimization criterion is GHPR weighted by the LR Correlation.

ICT Kill Zones - Asian, London, New York in New York time, with summer time ICT Kill Zones - Asian, London, New York in New York time, with summer time

ICT kill zones (Asian, London, New York, London Close) at the right New York hours on any broker, with US and EU summer time. High / low boxes, levels until price takes them, midnight open. Alerts and buffers for EAs.

Order Blocks and Breaker Blocks (SMC) - no repaint, with mitigation and alerts Order Blocks and Breaker Blocks (SMC) - no repaint, with mitigation and alerts

Marks the order block behind each break of market structure (the last opposite candle before the move), tracks when it is used and turns failed blocks into breaker blocks. No repaint. Alerts and buffers for EAs.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.