Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2015.05.27 17:09

Statistical Functions - library for MetaTrader 5

| English 日本語 Русский 中文 Español Deutsch Português

votes: 29
statistics.mqh (9.53 KB)view


Set of statistical functions which allows you to calculate some values describing timeseries like correlation between two time series, linear regression, standard deviation etc. It includes also more advanced functions like definite integral.

Header file "Statistics.mqh" includes following functions:

Syntax Description Return type
 mean(T &arr[])  Mean  (generic) 
 std(double &arr[])  Standard deviation  double
 correlation(&arr1[], &arr2[])  Correlation coefficient  double
 detrend(arr[], resultArray[])  Timeseries decomposition  void
 regression(&arr1[], &arr2[], &res[])  Regression line  void
 regression(double &arr1[], double &arr2[], double &res[], double &aCoeff,double &bCoeff)  Regression line with coefficients  void
 dickeyFuller(double &arr[])   Dickey-Fuller test for stationarity  bool
 engleGrangerTest(double &arr1[], double &arr2[],double &cointCoeff)   Engle-Granger 2-step method for testing cointegration  bool
 AR1(double &arr[])  Autoregressive model with lag 1  double
 signedIntegral(double a, double b, int n) *  Definite integral  double
 erf(double x)   Error function  double
 normDistZ(double z)   Probability that variable is from normal distrbution  double

* You should add your own implementation of "foo" function which you want to integrate. Default function is: f(x) = x.

You should also remember that timeseries avaliable in MQL are indexed in a way that the newest data have a 0 index. It's a good idea to reverse the order of such arrays and is absolutely necessay in AR model (arrays are not reversed inside of the method to avoid confusion).

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

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

Average Directional Movement Index (ADX) Average Directional Movement Index (ADX)

The Average Directional Movement Index Indicator (ADX) helps to determine if there is a price trend.

TP-SL_Removing TP-SL_Removing

Immediately deletes the SL/TP of all positions.

Closed_TOTAL Closed_TOTAL

Total closure of all positions (winners/losers). You can also select which are of a single instrument.