Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Statistics.mqh function - MetaTrader 5 library | MT5 EA download

author EAcpu | 2 reads | 0 comments |

This library contains a set of basic statistical functions required for user data processing.

This library was released for the first time in CodeBase for MQL4 - statistics.mqh function library . Some typographical errors have been detected and corrected in transferring functions to MQL5. The code becomes more intuitive and clearer. Most functions are written using S's algorithms. Bratislava book "Trader Statistics".

The library functions are as follows:

This file can be included in projects that require parameter processing of random samples, their parameter evaluation, histograms, etc.

Let's check some function calls:

 //+------------------------------------------------------------------+
//| test.mq5 |
//| Copyright 2012, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#propertycopyright "Copyright 2012, MetaQuotes Software Corp."
#Attribute link "http://www.mql5.com"
#Attribute version "1.00"

#include <statistics.mqh>
//+------------------------------------------------------------------+
//|Script program startup function |
//+------------------------------------------------------------------+
blank start ()
  { //--- Specify two value samples. Double arrX[ 10 ]={ 3 , 4 , 5 , 2 , 3 , 4 , 5 , 6 , 4 , 7 };
Double permutation [ 10 ] = { 7 , 4 , 1 , 2 , 1 , 6 , 9 , 2 , 1 , 5 }; //--- Calculate the average double mx = average (arrX);
Double my = mean(arrY); //--- Calculate variance using mean Double dx = variance(arrX,mx);
Double dy = variance(arrY,my); //--- Asymmetry value and excess Double as = asymmetry(arrX,mx,dx);
Doubled exc=excess(arrX,mx,dx); //--- Covariance and correlation values ​​doubled cov=Cov(arrX,arrY,mx,my);
Double corr=Corr(cov,dx,dy); //--- Display the result printing format in the log file ( "mx=%.6e" ,mx);
printFormat ( "i=%.6e" ,my);
Printing format ( “dx=%.6e” ,dx);
Printing format ( “dy=%.6e” ,dy);
printFormat ( "eg=%.6e" , as);
Print format ( "Exception=%.6e" , except);
print format ( "cov=%.6e" , coronavirus);
print format ( "Correction=%.6e" , correction);
  }

As you can see, most functions require values ​​(as input parameters) that can be calculated using other functions.

 Double dx = variance(arrX,mx);

In order to calculate the variance, we must first calculate the mean. This gives certain advantages in terms of computational optimization. In case the variance needs to be calculated multiple times, it would be better to average it once rather than multiple times within the averaging function. This saves time.

This feature is available for most functions of the library.


Attachment download

📎 statistics.mqh (27.16 KB)

📎 test.mq5 (1.64 KB)

Source: MQL5 #866

Verification code Refresh