# 移动极小化极大：技术分析的新指标及其在 MQL5 中的实施

31 十二月 2013, 10:09
0
1 518

### 简介

“移动极小化极大”[2] 原文的作者是 Z.K. Silagadze，一位来自 Budker 核物理研究所和新西伯利亚国立大学的量子物理学家。论文和 MQL5 源代码的链接附在本文的末尾。

### 指标

• 价格的支撑位和阻力位；
• 短期和长期趋势的方向；
• 趋势的顶部和底部。

成为某些时间窗口的价格序列。移动极小化极大是价格序列的非线性变换：

### 实施

```double S[];
ArrayResize(S,n+2*m);
CopyClose(Symbol(),0,0,n+2*m,S);
```

```void calcQii()
{
int i,k;

for(i=0; i<n; i++)
{
double sqiip1=0;
double sqiim1=0;
double dqiip1=0;
double dqiim1=0;

for(k=0; k<m; k++)
{
sqiip1 += MathExp(2*(S[m-1+i+k]-S[i])/(S[m-1+i+k]+S[i]));
sqiim1 += MathExp(2*(S[m-1+i-k]-S[i])/(S[m-1+i-k]+S[i]));

dqiip1 += MathExp(-2*(S[m-1+i+k]-S[i])/(S[m-1+i+k]+S[i]));
dqiim1 += MathExp(-2*(S[m-1+i-k]-S[i])/(S[m-1+i-k]+S[i]));
}
sQiip1[i] = sqiip1;
sQiim1[i] = sqiim1;
dQiip1[i] = dqiip1;
dQiim1[i] = dqiim1;

}
}
```

```void calcPii()
{
int i;

for(i=0; i<n; i++)
{
sPiip1[i] = sQiip1[i] / (sQiip1[i] + sQiim1[i]);
sPiim1[i] = sQiim1[i] / (sQiip1[i] + sQiim1[i]);
dPiip1[i] = dQiip1[i] / (dQiip1[i] + dQiim1[i]);
dPiim1[i] = dQiim1[i] / (dQiip1[i] + dQiim1[i]);
}
}
```

```void calcui()
{
int i;

sui[0] = 1;
dui[0] = 1;

for(i=1; i<n; i++)
{
sui[i] = (sPiim1[i]/sPiip1[i])*sui[i-1];
dui[i] = (dPiim1[i]/dPiip1[i])*dui[i-1];
}

double uSum = 0;
double dSum = 0;

ArrayInitialize(uSi, 0.0);
ArrayInitialize(dSi, 0.0);

for(i=0; i<n; i++) { uSum+=sui[i]; dSum+=dui[i]; }
for(i=0; i<n; i++) { uSi[n-1-i] = sui[i] / uSum; dSi[n-1-i] = dui[i] / dSum; }

}```

```   double result=0;
for(i=0; i<n; i++) { /* Print("i = "+i+" uSi = "+uSi[i]); */ result+=uSi[i]; }

Print("Result = "+ DoubleToString(result));
```

```    #property indicator_separate_window

#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_color1 SeaGreen
#property indicator_color2 BlueViolet```

```   SetIndexBuffer(0,uSi,INDICATOR_DATA);
SetIndexBuffer(1,dSi,INDICATOR_DATA);

PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

PlotIndexSetInteger(0,PLOT_SHIFT,-(m-1));
PlotIndexSetInteger(1,PLOT_SHIFT,-(m-1));```

图 2. 实施的移动极小化极大指标

```void SR()
{
// if price goes through local maximum and crosses a moving average draw resistance
int i, cnt=0;
int rCnt=CopyClose(Symbol(),0,0,n+2*m,S);

for (i=n-2; i>=0; i--)
if (uSi[i]<uSi_MA[i] && uSi[i+1]>=uSi_MA[i+1])
{
Print("Resistance at " + i);
CChartObjectHLine *line=new CChartObjectHLine();
line.Create(0, "MiniMaxResistanceLine:"+IntegerToString(cnt), 0, S[i]);
line.Color(LightSkyBlue);
line.Width(1);
line.Background(true);
line.Selectable(false);
cnt++;
}
// if price goes through local minimum and crosses a moving average draw support

for (i=n-2; i>=0; i--)
if (dSi[i]<dSi_MA[i] && dSi[i+1]>=dSi_MA[i+1])
{
Print("Support at " + i);
CChartObjectHLine *line=new CChartObjectHLine();
line.Create(0, "MiniMaxSupportLine:"+IntegerToString(cnt), 0, S[i]);
line.Color(Tomato);
line.Width(1);
line.Background(true);
line.Selectable(false);
cnt++;
}
}
```

```//+------------------------------------------------------------------+
//|                                                MovingMiniMax.mq5 |
//|                                               http://Investeo.pl |
//+------------------------------------------------------------------+

#property description "Moving Mini-Max indicator"
#property description "proposed by Z.K. Silagadze"
#property description "from Budker Institute of Nuclear Physics"
#property description "and Novosibirsk State University"
#property description "http://arxiv.org/abs/0802.0984"

#property version     "0.6"
#property indicator_separate_window

#property indicator_buffers 5
#property indicator_plots 3

#property indicator_type1 DRAW_COLOR_HISTOGRAM2
#property indicator_type2 DRAW_ARROW
#property indicator_type3 DRAW_ARROW

#property indicator_color1 Chartreuse, OrangeRed, Yellow
#property indicator_color2 RoyalBlue
#property indicator_color3 RoyalBlue

#property indicator_width1 5
#property indicator_width2 4
#property indicator_width3 4```

```   SetIndexBuffer(0,uSi,INDICATOR_DATA);
SetIndexBuffer(1,dSi,INDICATOR_DATA);
SetIndexBuffer(2,trend,INDICATOR_COLOR_INDEX);
SetIndexBuffer(3,upArrows,INDICATOR_DATA);
SetIndexBuffer(4,dnArrows,INDICATOR_DATA);

PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);

PlotIndexSetInteger(1,PLOT_ARROW,234);
PlotIndexSetInteger(2,PLOT_ARROW,233); ```

```   if (upind<dnind)
{
for (i=0; i<upind; i++) trend[i]=0;
for (i=upind; i<dnind; i++) trend[i]=1;
for (i=dnind; i<n; i++) trend[i]=0 ;
} else
{
for (i=0; i<dnind; i++) trend[i]=1;
for (i=dnind; i<upind; i++) trend[i]=0;
for (i=upind; i<n; i++) trend[i]=1;
}

trend[upind] = 2;
trend[dnind] = 2;
```

### 参考文献：

1. G.Gamov，《阿尔法衰变理论》

movingminimax.mq5 (7.34 KB)

MQL5 向导：如何创建未平仓位的追踪模块

MQL5 向导的交易策略生成器极大简化了交易理念的检验过程。本文介绍了如何编写自己的未平仓位管理类，以及如何将其连接至 MQL5 向导的交易策略生成器；当价格呈持仓方向移动时，该类可将止损水平移入无损区域，从而在交易过程中保护您的利益并减少亏损。本文还介绍了为 MQL5 向导创建的类的说明的结构和格式。