著者:
Sergey Bochkanov. ALGLIB のサイト- http://www.alglib.net/. ライブラリデータ1999まで。
高速フーリエ変換や微分方程式を解く場合がありますか。ソースコードにすべてのメソッドを記述して、複雑なデータ解析を行いますか。上記に当てはまる場合、ALGLIBの算術ライブラリが役に立ちます!
ALGLIB は、今のところマルチ言語アルゴリズムに対応した最良のライブラリです。オフィシャルサイトにはALGLIB の特徴が下記のように述べられています:
ALGLIB はクロスプラットフォームの算術分析ライブラリで、データ加工が可能です。いくつかのプログラミング言語(C++, C#, Pascal, VBA) と OS (Windows, Linux, Solaris)をサポートしています。ALGLIB の特徴:
ALGLIBを選ぶ理由下記参照:
ALGLIB ライブラリは、ユーザーの意見に添って新しい関数や改善など常に拡張されていて、定期的に更新されています。最新版は 3.6.0.
また、このライブラリはほとんどすべての想定されたメソッドの使い方のサンプルが格納されています。これにより、サンプルを試すことができ、もしエラーなどがあれば、report detected errorsで作成者に報告できます。
CAlglib クラスは、ライブラリを利用するのに必要です。すべてのライブラリの関数はstatic関数としてCAlglibを経由します。
testclasses.mq5 と testinterfaces.mq5 のスクリプトは、usealglib.mq5 デモスクリプトと共に付属されています。名前を変更せずに (testclasses.mqh と testinterfaces.mqh) を格納してください。サンプルを起動するのに利用します。ディレクトリの場所は \MQL5\Scripts\Alglib\Testcases\ です。
注意: testclasses.mq5 スクリプトの実行にはかなり時間がかかります。 (約 30 分).
ALGLIB MQL4 の詳細情報は下記にあります:
| パッケージ | 詳細 |
|---|---|
| alglib.mqh | メインのライブラリには、カスタム関数が格納されています。 この関数はライブラリと同様に呼び出してください。 |
| alglibinternal.mqh | 他のライブラリの追加のクラス |
| alglibmisc.mqh | このパックには下記のクラスがあります:
|
| ap.mqh | 他のパックに必要な関数もあります。 |
| bitconvert.mqh | デフォルトのMQL5では利用できない С++ の基本的なクラスと関数:
|
| complex.mqh | 複素数を使った構造の定義 |
| dataanalysis.mqh | データ分析のクラス:
|
| delegatefunctions.mqh | このパッケージには代用として生成されたクラスが含まれています。このクラスのオブジェクトは、数々のライブラリによって最適化された関数です。 |
| diffequations.mqh | 微分方程式を解くためのクラス:
|
| fasttransforms.mqh | 高速変換クラス:
|
| integration.mqh | 数値積分のクラス:
|
| interpolation.mqh | 補間、近似、微分のクラス:
|
| linalg.mqh | 線形代数の計算用クラス:
|
| matrix.mqh | 行列のクラス: integer型、連続型、複素数型 |
| optimization.mqh | 次元、多次元最適化クラス:
|
| solvers.mqh | 線形・非線形方程式を解くクラス:
|
| specialfunctions.mqh | 分布関数のクラス、インテグラルと多項式:
|
| statistics.mqh | 統計データ分析のクラス:
|
コード:
ライブラリの関数は利用法に詳細が記載されています。
//+------------------------------------------------------------------+ //| Calculation of the distribution moments: mean, variance, | //| skewness, kurtosis. | //| INPUT PARAMETERS: | //| X - sample | //| N - N>=0, sample size: | //| * if given, only leading N elements of X are | //| processed | //| * if not given, automatically determined from | //| size of X | //| OUTPUT PARAMETERS | //| Mean - mean. | //| Variance- variance. | //| Skewness- skewness (if variance<>0; zero otherwise). | //| Kurtosis- kurtosis (if variance<>0; zero otherwise). | //+------------------------------------------------------------------+ static bool CBaseStat::SampleMoments(const double &cx[],const int n,double &mean, double &variance,double &skewness,double &kurtosis) { //--- check if(!CAp::Assert(n>=0,__FUNCTION__+": the error variable")) return(false); //--- check if(!CAp::Assert(CAp::Len(cx)>=n,__FUNCTION__+": length(x)<n")) return(false); //--- check if(!CAp::Assert(CApServ::IsFiniteVector(cx,n),__FUNCTION__+": x is not finite vector")) return(false); //--- create variables double v=0; double v1=0; double v2=0; double stddev=0; //--- Init, special case 'N=0' mean=0; variance=0; skewness=0; kurtosis=0; //--- check if(n<=0) return(true); //--- Mean for(int i=0;i<n;i++) mean+=cx[i]; mean/=n; //--- Variance (using corrected two-pass algorithm) if(n!=1) { //--- calculation for(int i=0;i<n;i++) v1+=CMath::Sqr(cx[i]-mean); for(int i=0;i<n;i++) v2+=cx[i]-mean; v2=CMath::Sqr(v2)/n; variance=(v1-v2)/(n-1); //--- calculation stddev=MathSqrt(variance); } else variance=EMPTY_VALUE; //--- Skewness and kurtosis if(stddev!=0) { //--- calculation for(int i=0;i<n;i++) { v=(cx[i]-mean)/stddev; v2=CMath::Sqr(v); skewness+=v2*v; kurtosis+=CMath::Sqr(v2); } //--- change values skewness=skewness/n; kurtosis=kurtosis/n-3; } //--- successful execution return(true); }
CAlglib の統計系関数をライブラリと一緒に使う必要があります。下記は、 統計的パラメタの計算用の usealglib.mq5 関数のスクリプトのソースコードです:
//+------------------------------------------------------------------+ //| UseAlglib.mq5 | //| Copyright 2012, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2012, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| Connecting the libraries | //+------------------------------------------------------------------+ #include <Math\Alglib\alglib.mqh> #include <Trade\DealInfo.mqh> #include <Arrays\ArrayDouble.mqh> //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- object to access data on deals CDealInfo deal; //--- object for storing profit/loss of each deal CArrayDouble *profit=new CArrayDouble; //--- objects for storing the balance CArrayDouble *balance_total=new CArrayDouble; //--- initial balance double balance=0; //--- receive history HistorySelect(0,TimeCurrent()); //--- total amount of deals int deals_total=HistoryDealsTotal(); //--- receive data on deals' profit and balance for(int i=0;i<deals_total;i++) { //--- move to the deal having i index deal.SelectByIndex(i); //--- receive initial balance if(deal.DealType()==DEAL_TYPE_BALANCE) { if(NormalizeDouble(deal.Profit()+deal.Swap(),2)>=0.0) if(balance==0.0) balance=deal.Profit(); } //--- receive profit and balance if(deal.DealType()==DEAL_TYPE_BUY || deal.DealType()==DEAL_TYPE_SELL) if(deal.Entry()==DEAL_ENTRY_OUT || deal.Entry()==DEAL_ENTRY_INOUT) { profit.Add(NormalizeDouble(deal.Profit()+deal.Swap()+deal.Commission(),2)); balance_total.Add(balance); balance=balance+NormalizeDouble(deal.Profit()+deal.Swap()+deal.Commission(),2); } } balance_total.Add(balance_total.At(balance_total.Total()-1)+profit.At(balance_total.Total()-1)); //--- copy data on the balance to double type array double arr_balance[]; ArrayResize(arr_balance,balance_total.Total()); for(int i=0;i<balance_total.Total();i++) arr_balance[i]=balance_total.At(i); //--- copy data on profit to double type array double arr_profit[]; ArrayResize(arr_profit,profit.Total()); for(int i=0;i<profit.Total();i++) arr_profit[i]=profit.At(i); //--- linear regression //--- number of independent variables int nvars=1; //--- sample volume int npoints=balance_total.Total(); //--- create the matrix of parameters for the linear regression CMatrixDouble xy(npoints,nvars+1); for(int i=0;i<npoints;i++) { xy[i].Set(0,i); xy[i].Set(1,arr_balance[i]); } //--- variable for detecting calculations result (successful, unsuccessful) int info; //--- class objects necessary for storing data on calculations CLinearModelShell lm; CLRReportShell ar; //--- arrays for storing regression results double lr_coeff[]; double lr_values[]; ArrayResize(lr_values,npoints); //--- calculate linear regression ratios CAlglib::LRBuild(xy,npoints,nvars,info,lm,ar); //--- receive linear regression ratios CAlglib::LRUnpack(lm,lr_coeff,nvars); //--- receive recovered linear regression values for(int i=0;i<npoints;i++) lr_values[i]=lr_coeff[0]*i+lr_coeff[1]; //--- calculate Expected Payoff double exp_payoff,tmp1,tmp2,tmp3; CAlglib::SampleMoments(arr_profit,exp_payoff,tmp1,tmp2,tmp3); //--- calculate HPR array double HPR[]; ArrayResize(HPR,balance_total.Total()-1); for(int i=0;i<balance_total.Total()-1;i++) HPR[i]=balance_total.At(i+1)/balance_total.At(i); //--- calculate standard deviation and math expectation from HPR double AHPR,SD; CAlglib::SampleMoments(HPR,AHPR,SD,tmp2,tmp3); SD=MathSqrt(SD); //--- calculate LR Correlation double lr_corr=CAlglib::PearsonCorr2(arr_balance,lr_values); //--- receive LR Standard Error double lr_stand_err=0; for(int i=0;i<npoints;i++) { double delta=MathAbs(arr_balance[i]-lr_values[i]); lr_stand_err=lr_stand_err+delta*delta; } lr_stand_err=MathSqrt(lr_stand_err/(npoints-2)); //--- calculate Sharpe Ratio double sharpe_ratio=(AHPR-1)/SD; //--- print PrintFormat("-----------------------------------------------"); PrintFormat("Correlation function: y = %.2fx + %.2f",lr_coeff[0],lr_coeff[1]); //--- parameters PrintFormat("Expected Payoff = %.2f",exp_payoff); PrintFormat("AHPR = %.4f",AHPR); PrintFormat("Sharpe Ratio = %.2f",sharpe_ratio); PrintFormat("LR Correlation = %.2f",lr_corr); PrintFormat("LR Standard Error = %.2f",lr_stand_err); PrintFormat("-----------------------------------------------"); //--- delete objects delete profit; delete balance_total; } //+------------------------------------------------------------------+
下記の結果が得られます:

MetaQuotes Ltdによってロシア語から翻訳されました。
元のコード: /ru/code/11077
Price_Action
Price_ActionEA trades with "PRICE ACTION" strategy has Trailing Stop Loss &Take Profit works on all time frames major forex pairs and stocks NASDAQ.
4H Swing
4H Swing EA trades with 3 EMA's and "STOCHASTIC" indicator and swing strategy has Trailing Stop Loss &Take Profit works best on 4H & 1D time frame major forex pairs and stocks NASDAQ.
Color MACD
MACD indicator, red color mean bullish, blue color mean bearish.
Demarker Martingale
This Martingale EA trades with "Demarker" indicator, it is considered relatively safe because it takes a single trade at a time has Trailing Stop Loss &Take Profit works on all time frames major forex pairs and stocks NASDAQ.