ALGLIB - Numerical Analysis Library - Library for MetaTrader 4 | MT4 EA Download - MetaTrader 4 Resources

Sergei Bochkanov. ALGLIB project website - http://www.alglib.net/ . Library dates back to 1999 .
Note: The Expert Advisor works with MetaTrader 4 build 555 and higher .
Do you need to perform a Fast Fourier Transform or solve a system of differential equations? Are you performing complex data analysis trying to collect all methods in one place as source code? Then ALGLIB library of numerical methods is for you!
ALGLIB is one of the best multi-language algorithm libraries available. The following are the ALGLIB functions mentioned on the official website:
ALGLIB is a cross-platform numerical analysis and data processing library. It supports multiple programming languages (C++, C#, Pascal, VBA) and multiple operating systems (Windows, Linux, Solaris). ALGLIB functionality includes:
Why choose ALGLIB? Because it is:
The ALGLIB library is continuously enhanced, with new features and improvements regularly implemented based on user input. The latest version is 3.6.0.
Furthermore, the library contains a large number of test cases covering the main functionality of the proposed method. This will enable you to test and report detected bugs to the project's authors.
CAlglib class static functions should be used to work with the library - all library functions were moved to the CAlglib system class as static functions.
The testclasses.mq4 and testinterfaces.mq5 test case scripts are attached together with the simple usealglib.mq4 demo script. Included files with the same names (testclasses.mqh and testinterfaces.mqh) are used to start test cases. They must be placed in \MQL4\Scripts\Alglib\Testcases\.
Notes: The testclasses.mq4 script takes quite a long time to execute (about 30 minutes).
Here are more details about the ALGLIB MQL4 porting library package:
The package contains the following classes:
Library functions have detailed comments on their use.
//+------------------------------------------------------------------+ //|Calculation of distribution moments: mean, variance, | //|skewness, kurtosis. | //|Input parameters: | //| //| N - N>=0, sample size: | //| * If given, only the first N elements of X are | //| Processed | //| * If not given, automatically determined from | //| Size of X | //|Output parameters | //| average - the average value. | //| Variance - Variance. | //| Skewness - Skewness (if variance <> 0; otherwise zero). | //| kurtosis - kurtosis (if variance <> 0; otherwise zero). | //+------------------------------------------------------------------+ static boolean CBaseStat::SampleMoments( const double &cx[], const integer , double & means, Double & variance, double & skewness, double & kurtosis) { // - - Check if (!CAp::assert(n>= 0 , __function__ + ":error variable" )) return ( false ); // - - see if (!CAp::Assert(CAp::Len(cx)>=n, __function__ + ":length(x))) return ( false ); // - - see if (!CAp::Assert(CApServ::IsFiniteVector(cx,n), __function__ + ":x is not a finite vector" )) return ( false ); //--- create variable double v= 0 ; Double v1= 0 ; Double v2= 0 ; Double standard deviation = 0 ; //--- initialization, special case 'N=0' mean = 0 ; variance = 0 ; Skewness = 0 ; kurtosis = 0 ; // - - check if (n<= 0 ) return ( true ); // - - means for ( integer i = 0 ; i if (n!= 1 ) { // - - calculated as ( integer i = 0 ; i//--- Variance (using modified two-pass algorithm) for ( integer i = 0 ;i 1); // - - Calculate standard deviation = mathematical square root (variance); } else variance= null_VALUE ; //--- skewness and kurtosis if (standard equipment!= 0 ) { // - - calculated as ( integer i = 0 ; i(v); Skewness+=v2*v; Kurtosis+=CMath::Sqr(v2); } //--- Change value skewness=skewness/n; Kurtosis=kurtosis/n- 3 ; } //--- Return ( true ) on successful execution; }
CAlglib class static functions should be used to work with the library. The following is the source code of usealglib.mq5 function script, which is used to calculate some statistical trading parameters:
//+------------------------------------------------------------------+ //| Using Alglib.mq4 | //| Copyright 2012, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #Property Copyright "Copyright 2012, MetaQuotes Software Corp." #Property association "https://www.mql5.com" # Property version "1.00" #propertystrict //+------------------------------------------------------------------+ //|Include libraries | //+------------------------------------------------------------------+ #Include <Math\Alglib\alglib.mqh> #Include <Array\ArrayDouble.mqh> //+----------------------------------------------------------------------------------+ //|Script program startup function | //+------------------------------------------------------------------+ blank start () { //--- Object used to store profit and loss data for each order CArrayDouble *profit = new CArrayDouble; //--- Object used to store balance data CArrayDouble *balance_total = new CArrayDouble; //--- Initial balance doubled balance = 0 ; //--- Historical data request //--- Get the total order amount integer order_total=OrdersHistoryTotal(); //--- Get the profit data for ( integer i = 0 ; i<total number of orders; i++) { if ( order selection (i,SELECT_BY_POS,MODE_HISTORY)== wrong ) { print ( "Order Selection Error(" , GetLastError (), ")" ); return ; } Integer order_type=order type(); //--- Initial balance if (order type == 6 ) // OP_BALANCE=6 { if ( Normalized Double (OrderProfit()+OrderSwap(), 2 )>= 0.0 ) if (balance == 0.0 ) Balance = Order Profit(); } //--- Add order profit if (order type == OP_BUY || order type == OP_SELL) { Double order_profit=OrderProfit()+OrderSwap()+OrderCommission(); profit.add( NormalizedDouble (OrderProfit, 2 )); Balance_total.Add(balance); balance = balance + normalized double (order profit, 2 ); } } //--- Balance_total.Add(balance_total.At(balance_total.Total()- 1 )+profit.At(balance_total.Total()- 1 )); //--- Copy the balance data to a double array double arr_balance[]; Array resize (arr_balance,balance_total.Total()); for ( integer i = 0 ;i//--- Copy profit data to double type array double arr_profit[]; Array resize (arr_profit,profit.Total()); for ( integer i = 0 ;i<profit.Total();i++) arr_profit[i; 0, i); Array used to store regression results double lr_coeff[]; double lr_values[]; array resize (lr_value, n points); //--- Calculate linear regression coefficients CAlglib:: LRBuild (xy,npoints,nvars,info,lm,ar); //--- Get linear regression coefficients CAlglib::LRUnpack(lm,lr_coeff,nvars); //--- Get the recovered linear regression values for ( integer i = 0 ; i 0 | 1 ) ; for ( integer i = 0 ; i 1 ;i++) HPR[i]=balance_total.At(i+ 1 )/balance_total.At(i); //--- Calculate the standard deviation of HPR and double the mean AHPR, SD; CAlglib::SampleMoments(HPR,AHPR,SD,tmp2,tmp3); Standard deviation = mathematical square root (SD); //--- LR calculation of correlation doubled lr_corr = CAlglib::PearsonCorr2(arr_balance,lr_values); //--- LR calculation of standard error doubled lr_stand_err = 0 ; for ( integer i = 0 ; i Double delta = mathematical antibody (arr_balance[i]-lr_values[i]); lr_stand_err=lr_stand_err+delta*delta; } lr_stand_err= mathematical square root (lr_stand_err/(npoints- 2 )); //--- Calculation of Sharpe ratio Double Sharpe_ratio=(AHPR- 1 )/SD; // - - Print print format ( "--------------------------------------------------------" ); print format ( "Linear regression: y = %.2fx + %.2f" , lr_coeff[ 0 ], lr_coeff[ 1 ]); // - - Parameter print format ( "Expected return = %.2f" , exp_payoff); print format ( "AHPR = %.4f" , AHPR); print format ( "Sharpe ratio = %.2f" , sharp ratio); print format ( "LR correlation = %.2f" , lr_corr); print format ( "LR standard error = %.2f" , lr_stand_err); print format ( "--------------------------------------------------------" ); //--- delete object delete profit; delete total balance; } //+--------------------------------------------------------------------------------+
We will receive the following results (depending on the outcome of your transaction):

Attachment download
📎 alglib.mqh (1372.18 KB)
📎 alglibinternal.mqh (325.33 KB)
📎 alglibmisc.mqh (60.23 KB)
📎 ap.mqh (75.68 KB)
📎 arrayresize.mqh (6.59 KB)
📎 bitconvert.mqh (17.24 KB)
📎 complex.mqh (14.07 KB)
📎 dataanalysis.mqh (574.08 KB)
📎 delegatefunctions.mqh (17.68 KB)
📎 diffequations.mqh (35.66 KB)
📎 fasttransforms.mqh (85.21 KB)
📎 integration.mqh (243.57 KB)
📎 interpolation.mqh (522.71 KB)
📎linalg.mqh (712.14 KB)
📎 matrix.mqh (23.83 KB)
📎 optimization.mqh (501.04 KB)
📎 solvers.mqh (149.25 KB)
📎 specialfunctions.mqh (234.36 KB)
📎 statistics.mqh (398.3 KB)
📎 TestClasses.mq4 (14.31 KB)
📎 TestClasses.mqh (1380.85 KB)
📎 TestInterfaces.mq4 (8.86 KB)
📎 TestInterfaces.mqh (403.03 KB)
📎UseAlglib.mq4 (6.31 KB)
Source: MQL5 #11077
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •