English Русский 中文 Español Deutsch Português
最小の遅れでの効果的な平均化アルゴリズム:インディケータおよび Expert Advisor での使用

最小の遅れでの効果的な平均化アルゴリズム:インディケータおよび Expert Advisor での使用

MetaTrader 4 | 22 4月 2016, 12:23
1 148 0
Nikolay Kositsin
Nikolay Kositsin

はじめに

平均化アルゴリズムに基づくインディケータを基に構築される機械的なトレーディングシステムでは、開発者が2つ以上の平均化アルゴリズムを使用することは稀です。多くの場合、のアルゴリズムが単純移動やターミナルの標準インディケータセットにインクルードされるインディケータを基にしている場合、4つの標準的アルゴリズムが使用されるだけです。単純平均、指数平均、平滑化平均、リニア加重平均です。そのような方法は Expert Advisor の可能性を大きく制限します。

異なる平均化アルゴリズムを使用する同一トレーディングシステムはトレード結果に実質的な差異を示します。そして、事前に利用可能なアルゴリズムのどれがトレーディングシステムの最大収益性を示すか言うことは不可能です。EA の外部変数値の変化によって選択される完全に異なる平均化アルゴリズムを使用する機能を持つコードを書くことの方が妥当です。その方法の結果として、 EA によって使用されるインディケータを平均化アルゴリズム選択のより柔軟な設定を持つ自分独自のインディケータと置き換えます。よって、その方法は次の3段階に分けられます。

1. 標準的移動に基づく Expert Advisor と、MetaTrader 4 クライアントターミナルの一連のテクニカルインディケータにインクルードされるコードを書く。
2. より柔軟な平滑化アルゴリズムを置換する機能を持つ標準インディケータの記述に従ったカスタムインディケータを書く。
3. EA の外部変数にこれらインディケータの外部パラメータを抽出るすことで、テクニカルインディケータの呼出しを、上記のカスタムインディケータ呼び出しと置き換える。


本稿では、インディケータで使用される平均化アルゴリズムの最新置換機能(そう呼べるなら)を持つユニバーサルインディケータについて細かく説明したいと思います。本稿は『ラグを最小に抑えた有効な平均化アルゴリズム:インディケータでの使用』 の続編です。よって本稿を読む前に先行記事を注意して学習されることをお薦めします。



平均化のユニバーサル関数

先行記事で、平均化関数を5個紹介しました。そこにもう一つ関数を追加したいと思います。平均化の古典的アルゴリズムを持つ MASeries() です。

double MASeries
(
  int number, int MA_Method, int MaxBar, int limit, int period, double series, int bar, int& reset
)

用法については、この関数は前出の5個とまったく類似しています。この関数のコードは本稿に添付があります-MASeries.mqh。

次にこれら6個の関数を基に、SmoothXSeries() と呼びファイル SmoothXSeries.mqh にある、平均化のユニバーサル関数を作成することができます。前出の関数同様、この関数は次のような #include < > 命令です。:

#include <SmoothXSeries.mqh>

外部変数については、この関数は JJMASeries() に類似していますが、平滑化アルゴリズムの識別子の新しい関数-SmoothMode、があります。

double SmoothXSeries
(
  int number,int SmoothMode, int din, int MaxBar, int limit, int Phase, int Length, double Series, int bar, int& reset
)

必要な平均化アルゴリズムのの選択は、0~8 で SmoothMode パラメータの値のバリエーションによって行われます。

  // 0 : JJMA
  // 1 : JurX        
  // 2 : ParMA
  // 3 : LRMA
  // 4 : T3
  // 5 : SMA
  // 6 : EMA
  // 7 : SSMA
  // 8 : LWMA

当然、変数 din および Phase は、これら平均化アルゴリズムにのみ適用されます。そのアルゴリズムに対してそれらは最初に定義されているのです。インディケータコードでこの関数を使用する前に、この関数の変数は初期化され、メモリがそこに割り当てられなければなりません。そのために、インディケータ初期化ブロックで、 SmoothXSeriesResize() 関数の呼び出しを作成します。その外部変数 Size の値として、インディケータコードでは SmoothXSeries() 関数呼び出しの数を使用します。

  //Ten calls of the SmoothXSeriesResize() function in the indicator code
  SmoothXSeriesResize(10);

これで平均化 SmoothXSeries() のユニバーサルなアルゴリズムを取得し、インディケータコードを書き始めることができます。



ユニバーサル移動

価格の時系列を平滑化することで任意の移動を取得します。先行記事で、時系列の価格行の値を選択するための PriceSeries() 関数について書きました。移動を構築するタスクは実際、SmoothXSeries() 関数によって価格系列の値を処理し、インディケータバッファに渡すことです。以下はコード実装のバリアントです。

/*
For the operation of the indicator the files

SmoothXSeries.mqh
T3Series.mqh
MASeries.mqh
LRMASeries.mqh
JurXSeries.mqh
ParMASeries.mqh
JJMASeries.mqh 
PriceSeries.mqh 
should be located in  the directory: MetaTrader\experts\include\

Heiken Ashi#.mq4
should be located in the directory: MetaTrader\indicators\
*/
//+X================================================================X+  
//|                                                         X1MA.mq4 | 
//|                        Copyright © 2009,        Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+X================================================================X+   
#property copyright "Copyright © 2009, Nikolay Kositsin"
#property link "farria@mail.redcom.ru" 
//---- drawing the indicator in the main window
#property indicator_chart_window 
//---- number of indicator buffers
#property indicator_buffers 1 
//---- color of the indicator
#property indicator_color1 Red
//---- INPUT PARAMETERS OF THE INDICATOR +--------------------------------------------+
extern int Smooth_Mode = 0;   // Choosing the smoothing algorithm 0 - JJMA, 1 - JurX,        
                 // 2 - ParMA, 3 - LRMA, 4 - T3, 5 - SMA, 6 - EMA, 7 - SSMA, 8 - LWMA
extern int Length = 11;   // depth of smoothing
extern int Phase  = 100; // parameter changing in limits -100 ... +100, 
                                       //influences the quality of the transient process; 
extern int Shift  = 0;   // indicator shift along the time axis
extern int Input_Price_Customs = 0; /* Selecting prices, upon which the calculation of
the indicator is performed (0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL, 
6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW, 
11-Heiken Ashi Low, 12-Heiken Ashi High, 13-Heiken Ashi Open, 14-Heiken Ashi Close.) */
//---- +------------------------------------------------------------------------------+
//---- buffers
double XMA[]; 
//---- variables
bool INIT;
int  StartBar;
//+X================================================================X+   
//| SmoothXSeries() function                                         |
//+X================================================================X+    
//----+ Declaring the function SmoothXSeries
//----+ Declaring the function SmoothXSeriesResize 
//----+ Declaring the function SmoothXSeriesAlert   
#include <SmoothXSeries.mqh> 
//+X================================================================X+   
//| PriceSeries() function                                           |
//+X================================================================X+    
//----+ Declaring the function PriceSeries
//----+ Declaring the function PriceSeriesAlert 
#include <PriceSeries.mqh>
//+X================================================================X+   
//| X1MA initialization function                                     |
//+X================================================================X+ 
int init() 
{ 
//----+
   //---- setting the style of the indicator presentation 
   SetIndexStyle(0, DRAW_LINE); 
   //---- defining a buffer for calculations 
   SetIndexBuffer(0, XMA);
   //---- setting the values of the indicator that will not be visible on the chart
   SetIndexEmptyValue(0, 0.0);  
   //---- setting alerts for not allowed values of external variables
   JJMASeriesAlert (0, "Length", Length);
   JJMASeriesAlert (1, "Phase",   Phase);
   PriceSeriesAlert(Input_Price_Customs);
   //----+ Changing sizes of buffer variables of the function
           //SmoothXSeries, number = 1(One call of the SmoothXSeries function)
   if (SmoothXSeriesResize(1) != 1)
    {
     INIT = false;
     return(0);
    }
   //---- initialization of variables
   if (Smooth_Mode > 0 && Smooth_Mode < 9) 
                              StartBar = Length;
   else StartBar = 30;
   //---- setting the bar number,
                     //starting from which the indicator will be drawn 
   SetIndexDrawBegin(0, StartBar); 
   //---- Setting the format of accuracy of the indicator drawing
   IndicatorDigits(Digits);
   //---- end of initialization
   INIT = true;
   return(0);
//----+ 
}
//+X================================================================X+  
//| X1MA iteration function                                          | 
//+X================================================================X+   
int start()
{
//----+ 
   //---- Getting the number of all bars
   int Bars_ = Bars - 1;
//---- checking the initialization end and 
     //checking if the number of bars is enough for calculation
if (!INIT || Bars_ <= StartBar)
                  return(-1); 
//---- Introducing variables with a floating point
double Price, xma;
//---- Introducing integer variables and obtaining the number 
                           //of already calculated bars
int reset, MaxBar, limit, bar, counted_bars = IndicatorCounted();
//---- checking for possible errors
if (counted_bars < 0)
    return(-1);
//---- the last calculated bar must be recalculated
if (counted_bars > 0)
counted_bars--;
//---- defining the number of the oldest bar, 
//starting from which new bars will be recalculated 
limit = Bars_ - counted_bars;
//---- defining the number of the oldest bar, 
//starting from which all bars will be recalculated 
MaxBar = Bars_;
//----+ the main cycle of the indicator calculation
for(bar = limit; bar >= 0; bar--)
{
  //---- Getting the initial value of the price series
  Price = PriceSeries(Input_Price_Customs, bar);
  //---- X1MA smoothing of the initial value of the price series 
  //---- Call of the SmoothXSeries function number 0, 
//parameters Phase and Length are not changed at each bar (din = 0)
  xma = SmoothXSeries(0, Smooth_Mode, 0, MaxBar, limit, 
                                     Phase, Length, Price, bar, reset);
  //---- checking that there are no errors in the previous operation
  if(reset != 0)
  return(-1);
  
  XMA[bar] = xma;
  //----
}
//---- end of the indicator values calculation
return(0); 
//----+  
} 
//+X--------------------+ <<< The End >>> +--------------------X+

このインディケータでは、平均化アルゴリズムは Smooth_Mode 変数の値を変えることで選択されます。



二つの平均化を使用したユニバーサルな移動

同じ SmoothXSeries() 関数によって取得されるインディケータの平均化を追加で行えば、そのような移動を処理する効率は、大幅に改善可能です。

/*
For the operation of the indicator the files 

SmoothXSeries.mqh
T3Series.mqh
MASeries.mqh
LRMASeries.mqh
JurXSeries.mqh
ParMASeries.mqh
JJMASeries.mqh 
PriceSeries.mqh 
should be located in the directory: MetaTrader\experts\include\

Heiken Ashi#.mq4
should be located in the directory: MetaTrader\indicators\
*/
//+X================================================================X+  
//|                                                         X2MA.mq4 | 
//|                        Copyright © 2009,        Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+X================================================================X+   
#property copyright "Copyright © 2009, Nikolay Kositsin"
#property link "farria@mail.redcom.ru" 
//---- drawing the indicator in the main window
#property indicator_chart_window 
//---- number of indicator buffers
#property indicator_buffers 1 
//---- color of the indicator
#property indicator_color1 Lime
//---- INPUT PARAMETERS OF THE INDICATOR +---------------------------------------------+
extern int Smooth_Mode1 = 0;   // Choosing the 1st smoothing algorithm 0 - JJMA, 1 - JurX,        
                 // 2 - ParMA, 3 - LRMA, 4 - T3, 5 - SMA, 6 - EMA, 7 - SSMA, 8 - LWMA
extern int Length1 = 9;   // depth of smoothing 
extern int Phase1  = 100; // parameter changing in limits -100 ... +100, 
                                       //influences the quality of the transient process;
extern int Smooth_Mode2 = 0;   // Choosing the 2nd smoothing algorithm 0 - JJMA, 1 - JurX,        
                 // 2 - ParMA, 3 - LRMA, 4 - T3, 5 - SMA, 6 - EMA, 7 - SSMA, 8 - LWMA
extern int Length2 = 5;   // depth of smoothing 
extern int Phase2  = 100; // parameter changing in limits -100 ... +100, 
                                       //influences the quality of the transient process;  
extern int Shift  = 0;   // indicator shift along the time axis 
extern int Input_Price_Customs = 0; /* Selecting prices, upon which the calculation of 
the indicator is performed (0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL, 
6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW, 
11-Heiken Ashi Low, 12-Heiken Ashi High, 13-Heiken Ashi Open, 14-Heiken Ashi Close.) */
//---- +------------------------------------------------------------------------------+
//---- buffers
double X2MA[];
//---- variables  
bool INIT;
int  StartBar, StartBar1, StartBar2;
//+X================================================================X+   
//| SmoothXSeries() function                                         |
//+X================================================================X+    
//----+ Declaring the function SmoothXSeries
//----+ Declaring the function SmoothXSeriesResize 
//----+ Declaring the function SmoothXSeriesAlert   
#include <SmoothXSeries.mqh> 
//+X================================================================X+   
//| PriceSeries() function                                           |
//+X================================================================X+    
//----+ Declaring the function PriceSeries
//----+ Declaring the function PriceSeriesAlert 
#include <PriceSeries.mqh>
//+X================================================================X+   
//| X2MA initialization function                                     |
//+X================================================================X+ 
int init() 
{ 
//----+
   //---- setting the style of the indicator presentation 
   SetIndexStyle(0, DRAW_LINE); 
   //---- defining a buffer for calculations 
   SetIndexBuffer(0, X2MA);
   //---- setting the values of the indicator that will not be visible on the chart
   SetIndexEmptyValue(0, 0.0); 
   //---- setting alerts for not allowed values of external variables
   JJMASeriesAlert (0, "Length1", Length1);
   JJMASeriesAlert (1, "Phase1",   Phase1);
   JJMASeriesAlert (0, "Length2", Length2);
   JJMASeriesAlert (1, "Phase2",   Phase2);
   PriceSeriesAlert(Input_Price_Customs);
   //----+ Changing sizes of buffer variables of the function
           //SmoothXSeries, number = 2(Two calls of the SmoothXSeries function)
   if (SmoothXSeriesResize(2) != 2)
    {
     INIT = false;
     return(0);
    }
   //---- initialization of variables
   if (Smooth_Mode1 > 0 && Smooth_Mode1 < 9) 
                              StartBar1 = Length1;
   else StartBar1 = 30;
   
   if (Smooth_Mode2 > 0 && Smooth_Mode2 < 9) 
                              StartBar2 = Length2;
   else StartBar2 = 30;
   StartBar = StartBar1 + StartBar2;
   //---- setting the bar number,
                     //starting from which the indicator will be drawn 
   SetIndexDrawBegin(0, StartBar); 
   //---- Setting the format of accuracy of the indicator drawing
   IndicatorDigits(Digits);
   //---- end of initialization
   INIT = true;
   return(0);
//----+ 
}
//+X================================================================X+  
//| X2MA iteration function                                          | 
//+X================================================================X+   
int start()
{
//----+ 
   //---- Getting the number of the last bar
   int Bars_ = Bars - 1;
//---- checking the initialization end and 
     //checking if the number of bars is enough for calculation
if (!INIT || Bars_ <= StartBar)
                  return(-1); 
//---- Introducing variables with a floating point
double Price, x1ma, x2ma;
//---- Introducing integer variables and obtaining the number 
                        //of already calculated bars
int reset, MaxBar1, MaxBar2, limit, 
                   bar, counted_bars = IndicatorCounted();
//---- checking for possible errors
if (counted_bars < 0)
    return(-1);
//---- the last calculated bar must be recalculated
if (counted_bars > 0)
counted_bars--;
//---- defining the number of the oldest bar, 
//starting from which new bars will be recalculated 
limit = Bars_ - counted_bars;
//---- defining the number of the oldest bar, 
//starting from which all bars will be recalculated 
MaxBar1 = Bars_;
MaxBar2 = MaxBar1 - StartBar1;

//----+ the main cycle of the indicator calculation
for(bar = limit; bar >= 0; bar--)
{
  //---- Getting the initial value of the price series
  Price = PriceSeries(Input_Price_Customs, bar);
  //---- X1MA smoothing of the initial value of the price series, 
  //---- Call of the SmoothXSeries function number 0, 
//parameters Phase and Length are not changed at each bar (din = 0)
  x1ma = SmoothXSeries(0, Smooth_Mode1, 0, MaxBar1, limit, 
                                     Phase1, Length1, Price, bar, reset);
  //---- checking that there are no errors in the previous operation
  if(reset != 0)
  return(-1);
  //---- X2MA smoothing of the obtained indicator, 
  //---- Call of the SmoothXSeries function number 1, 
//parameters Phase and Length are not changed at each bar (din = 0)
  x2ma = SmoothXSeries(1, Smooth_Mode2, 0, MaxBar2, limit, 
                                     Phase2, Length2, x1ma,  bar, reset);
  //---- checking that there are no errors in the previous operation
  if(reset != 0)
  return(-1);
  //----      
  X2MA[bar] = x2ma;
  //----
}
//----+ end of the indicator values calculation
return(0); 
//----+  
} 
//+X--------------------+ <<< The End >>> +--------------------X+

もちろん、最終的なインディケータは元のインディケータと比較するとわずかなディレイしかありませんが、そのような移動によって受け取られるディレイを補正する誤ったアラート数はずっと少なくなっています。

このインディケータは、素量的な(離散的)もので取得する一連の連続した値に変えることで改善されます。それにはシンプルなアルゴリズムが使用されます。

       //----+ normalizing the obtained value x2ma
       double Norma = Step * Point;
       //----
       x2ma /= Norma;
       x2ma = NormalizeDouble(x2ma, 0);
       x2ma *= Norma;

Step 変数はインディケータの外部パラメータ全体で、それがポイント表示で取得される値の裁量のステップを定義します。本稿にそのコードは入れていません。添付のインディケータ X2DigMa.mq4 によって参照ください。



X2DigMa.mq4 インディケータを使用する Expert Advisor の最適化における実用的推奨事項

この移動には外部変数が数多くあり、そのため、このインディケータに基づき作成される任意の Expert Advisor はどの市場に対してもひじょうによく調整されます。ただし、EA パラメータを正式に合わせるすることはのちの動作のためにプログラミングするもっとも最適な方法とは言えません。Expert Advisor においてそのような移動の外部変数を処理する動作詳細についてお話します。ある EA があり、そこで、移動 X2DigMA.mq4 の外部変数すべてが EA の外部変数によって作成されている、と仮定します。

extern int Smooth_Mode1 = 0; 
extern int Length1 = 9; 
extern int Phase1  = 100;
extern int Smooth_Mode2 = 0;
extern int Length2 = 5; 
extern int Phase2  = 100;
extern int Step = 10;
extern int Input_Price_Customs = 0;

Smooth_Mode1 変数は 0~8 の値を受け取りますが、遺伝的アルゴリズムによってテスターでこの変数値を最適化することはお薦めできません。この変数の値それぞれに対して独立した8個の最適化を行う方がよいでしょう。繰り返される平滑化 Smooth_Mode2 に対する類似の変数値はゼロに固定するのが良いです。その場合、JMA 平均化アルゴリズムは反復平滑化として使用されます。このアルゴリズムは最小の遅れしかなく、私の場合には追加の平均化として最良の結果を出します。

JMA 系列でのみ使用されるパラメータ Phase1 および Phase2 と、T3 系列平均化は 100 に固定するのがよいでしょう。Length2 パラメータは任意の値を取ることができますが、多くの状況で、完全に異なる EA では、もっともてきしているのは系列 3, 5, 7, 9, 11 からの同じ値であることがひじょうに多いものです。Length2 パラメータのこれら値の使用は概して十分です。Step は EA が操作される市場とチャート期間に左右されることがかなりあります。ただし、同一値に安定していることがひじょうに頻繁です。Input_Price_Customs パラメータのベストな値は通常 0 と9です。徹底的な調査の結果、ただ一つのパラメータ-Length1、が残り、その値は異なる可能性があります。



ユニバーサル MACD 図

私が提供する SmoothXSeries() 関数を使って、従来のテクニカル分析のインディケータはどんなものでも構築することができあす。たとえば、2つのインディケータのチャートである MACD 図です。1番目のものは、2つの移動の差を表す図で、2番目のものは、この差の移動平均です。

/*
For the operation of the indicator the files 

SmoothXSeries.mqh
T3Series.mqh
MASeries.mqh
LRMASeries.mqh
JurXSeries.mqh
ParMASeries.mqh
JJMASeries.mqh 
PriceSeries.mqh 
should be located in  the directory: MetaTrader\experts\include\

Heiken Ashi#.mq4
should be located in  the directory: MetaTrader\indicators\
*/
//+X================================================================X+  
//|                                                        XMACD.mq4 | 
//|                        Copyright © 2009,        Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+X================================================================X+   
#property copyright "Copyright © 2009, Nikolay Kositsin"
#property link "farria@mail.redcom.ru" 
//---- drawing the indicator in the main window
#property  indicator_separate_window 
//---- number of indicator buffers
#property indicator_buffers 2 
//---- colors of the indicator
#property  indicator_color1  Blue
#property  indicator_color2  Magenta
//---- width of the diagram line
#property  indicator_width1  2
//---- INPUT PARAMETERS OF THE INDICATOR
extern int MACD_Mode = 0;  // Choosing the smoothing algorithm for MACD 0 - JJMA, 1 - JurX,        
                 // 2 - ParMA, 3 - LRMA, 4 - T3, 5 - SMA, 6 - EMA, 7 - SSMA, 8 - LWMA
extern int MACD_Phase = 100;
extern int FastXMA = 12;
extern int SlowXMA = 26;
extern int Signal_Mode = 0;  // Choosing the smoothing algorithm for the signal line 
  //0 - JJMA, 1 - JurX, 2 - ParMA, 3 - LRMA, 4 - T3, 5 - SMA, 6 - EMA, 7 - SSMA, 8 - LWMA
extern int Signal_Phase = 100;
extern int SignalXMA = 9;
extern int Input_Price_Customs = 0; /* Selecting prices, upon which the calculation of 
the indicator is performed (0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL, 
6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW, 
11-Heiken Ashi Low, 12-Heiken Ashi High, 13-Heiken Ashi Open, 14-Heiken Ashi Close.) */
//---- indicator buffers
double     XMacdBuffer[];
double     XSignalBuffer[];
//---- variabless 
bool   INIT;
int    StartBar, StartBar1, StartBar2;
//+X================================================================X+   
//| SmoothXSeries() function                                         |
//+X================================================================X+    
//----+ Declaring the function SmoothXSeries
//----+ Declaring the function SmoothXSeriesResize 
//----+ Declaring the function SmoothXSeriesAlert   
#include <SmoothXSeries.mqh> 
//+X================================================================X+   
//| PriceSeries() function                                           |
//+X================================================================X+    
//----+ Declaring the function PriceSeries
//----+ Declaring the function PriceSeriesAlert 
#include <PriceSeries.mqh>
//+X================================================================X+ 
//| XMACD indicator initialization function                          |
//+X================================================================X+ 
int init()
  {
//----+
   //---- setting the style of the indicator presentation 
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexStyle(1, DRAW_LINE);
   //---- Setting the accuracy format (number of digits 
        //after the decimal point) for the visualization of the indicator values 
   IndicatorDigits(Digits + 1);
   //---- defining buffers for calculation 
   SetIndexBuffer(0, XMacdBuffer);
   SetIndexBuffer(1, XSignalBuffer);
   //---- names for data windows and labels for subwindows
   IndicatorShortName(StringConcatenate
            ("XMACD(", FastXMA, ",", SlowXMA, ",", SignalXMA, ")"));
   SetIndexLabel(0, "XMACD");
   SetIndexLabel(1, "XSignal");
   //---- setting alerts for not allowed values of external variables
   JJMASeriesAlert (0, "FastXMA", FastXMA);
   JJMASeriesAlert (0, "SlowXMA", SlowXMA);
   JJMASeriesAlert (0, "SignalXMA", SignalXMA);
   //----
   JJMASeriesAlert (1, "MACD_Phase", MACD_Phase);  
   JJMASeriesAlert (1, "Signal_Phase", Signal_Phase);
   PriceSeriesAlert(Input_Price_Customs);
   //---- Changing sizes of buffer variables of the function
           //SmoothXSeries, number = 3(Three calls of the SmoothXSeries function)
   if (SmoothXSeriesResize(3) != 3)
    {
     INIT = false;
     return(0);
    }
   //---- initialization of variables 
   if (MACD_Mode > 0 && MACD_Mode < 9) 
                            StartBar1 = MathMax( FastXMA, SlowXMA);
   else StartBar1 = 30;
   //----
   if (Signal_Mode > 0 && Signal_Mode < 9) 
                          StartBar2 = SignalXMA;
   else StartBar2 = 30;
   //----
   StartBar = StartBar1 + StartBar2;
   //----
   SetIndexDrawBegin(0, StartBar1);
   SetIndexDrawBegin(1, StartBar);
   //---- end of initialization
   INIT = true;
   return(0);
//----+
  }
//+X================================================================X+ 
//| XMACD indicator iteration function                               |
//+X================================================================X+ 
int start()
  {
//----+
   //---- Getting the number of the last bat
   int Bars_ = Bars - 1;
//---- checking the initialization end and 
     //checking if the number of bars is enough for calculation
if (!INIT || Bars_ <= StartBar)
                  return(-1); 
//---- Introducing variables with a floating point
double Price, FastXMA_, SlowXMA_, XMACD, SignalXMA_;
//---- Introducing integer variables and obtaining the number 
                        //of already calculated bars
int reset, MaxBar1, MaxBar2, limit, 
                   bar, counted_bars = IndicatorCounted();
//---- checking for possible errors
if (counted_bars < 0)
    return(-1);
//---- the last calculated bar must be recalculated
if (counted_bars > 0)
counted_bars--;
//---- defining the number of the oldest bar, 
//starting from which new bars will be recalculated 
limit = Bars_ - counted_bars;
//---- defining the number of the oldest bar, 
//starting from which all bars will be recalculated 
MaxBar1 = Bars_;
MaxBar2 = MaxBar1 - StartBar1;

   //----+ the main cycle of the indicator calculation
for(bar = limit; bar >= 0; bar--)
{
  //---- Getting the initial value of the price series
  Price = PriceSeries(Input_Price_Customs, bar);
  //---- FastXMA smoothing of the initial value of the price series, 
  //---- Call of the SmoothXSeries function number 0, 
//parameters Phase and Length are not changed at each bar (din = 0)
  FastXMA_ = SmoothXSeries(0, MACD_Mode, 0, MaxBar1, limit, 
                              MACD_Phase, FastXMA, Price, bar, reset);
  //---- checking that there are no errors in the previous operation
  if(reset != 0)
  return(-1);
  //---- SlowXMA smoothing of the initial value of the price series, 
  //---- Call of the SmoothXSeries function number 1, 
//parameters Phase and Length are not changed at each bar (din = 0)
  SlowXMA_ = SmoothXSeries(1, MACD_Mode, 0, MaxBar1, limit, 
                             MACD_Phase, SlowXMA, Price,  bar, reset);                       
  //---- checking that there are no errors in the previous operation
  if(reset != 0)
  return(-1);
  //----   
  if(bar < MaxBar2) 
         XMACD = FastXMA_ - SlowXMA_;
  
  //---- SignalXMA smoothing of the obtained XMACD diagram, 
  //---- Call of the SmoothXSeries function number 2, 
//parameters Phase and Length are not changed at each bar (din = 0)
  SignalXMA_ = SmoothXSeries(2, Signal_Mode, 0, MaxBar2, limit, 
                         Signal_Phase, SignalXMA, XMACD,  bar, reset);            
  //---- checking that there are no errors in the previous operation
  if(reset != 0)
  return(-1);
  //----
  XMacdBuffer[bar] = XMACD;
  XSignalBuffer[bar] = SignalXMA_;   
    }
   return(0);
  
//----+
  }
//+X----------------------+ <<< The End >>> +-----------------------X+

Expert Advisor におけるそのインディケータ処理のロジックは多くの面で上で書いたものと類似していますが、この場合、Signal_Mode 変数の値には遺伝的最適化を行うとよいでしょう。



おわりに

関数呼び出しにより、テクニカル分析のインディケータをどんなものでも構築することができます。その可能性は従来の類似したものよりも高いように見えます。もちろん、これにはインディケータ作成の一定の経験が必要ですが、最終結果は労力を遣っただけのことはあるものです。


MetaQuotes Ltdによってロシア語から翻訳されました。
元の記事: https://www.mql5.com/ru/articles/1563

添付されたファイル |
INCLUDE.zip (47.51 KB)
indicators.zip (11.54 KB)
チャネルアドバンスドモデルWolfe Waves チャネルアドバンスドモデルWolfe Waves
この記事は、Wolfe Wavesのマーキングパターンの法則を紹介します。波の正しい形成を理解する上で役に立つ正確なマーキングのルールや構築の詳細をご覧になれます。
ニューロネット用レシピ ニューロネット用レシピ
本稿は、『多層』ケーキを焼く初心者を対象としています。
メタトレーダーでニューラルネットワークを利用する メタトレーダーでニューラルネットワークを利用する
本稿は、みなさんのコードに複数のニューラルネットワークを取り入れて無料の人工ニューラルネットワークライブラリ(FANN)を活用し、MQL4 コードでニューラルネットワークを簡単に利用する方法をお見せします。
MQL4 でダブルスの作業をする MQL4 でダブルスの作業をする
本稿では、一般的なプログラムエラーについて考察します。それは MQL4 プログラムでdouble の数字を処理するときに発生するものです。