# 基于 MACD 扩展分析的交易助手

17 三月 2016, 13:01
0
1 472

### 简介

MACD 柱形图被视为最好的价格趋势指标之一。。根据 A. Elder 博士的建议，价格趋势由相应时间范围上最后两个柱决定。但是，根据那两个柱我们无法说明任何其他事情。当然，一名经验丰富的交易者通过观看柱形图可以根据他或她的直觉进行一些想象。如果我们取最后三个柱进行分析，则信息的数量和质量将大大提高

```//+------------------------------------------------------------------+
//|                                                 TrendMACD v5.mq4 |
//|MACD histogram analysis by the last three bars             Genkov |
//|                                                     genkov@bk.ru |
//+------------------------------------------------------------------+
//if you comment on the below line, the properties window will not be displayed
#property show_inputs
extern int a = 0;            // here you can specify any initial bar to be analyzed
//extern int period = 1;     //  1 minute
//extern int period = 5;     //  5 minutes
//extern int period = 15;    // 15 minutes
extern int period = 30;      //  30 minutes
//extern int period = 60;    // comment on the timeframe you need
//extern int period = 240;   // 4 hours
//extern int period = 1440;  // day
//extern int period = 10080; // week
//extern int period = 43200; // month
//+------------------------------------------------------------------+```

```int start()
{
int b,c;
b=a+1; c=b+1;
//----
double Macd_h1_a= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,a);
double Macd_h1_b= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,b);
double Macd_h1_c= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,c);```

```Print("   Macd_h1_c= ",Macd_h1_c*1000,"   Macd_h1_b= ",
Macd_h1_b*1000,"   Macd_h1_a= ",Macd_h1_a*1000);```

```int start=GetTickCount();
//…
//…, and at the end of the program:
Alert("   Calculation time  ", GetTickCount()-start," millisec"); ```

```// ----------------------for MACD below the axis-------------------------1--&
if(Macd_h1_c0.0&&Macd_h1_a<0.0&&Macd_h1_a<0.0)
{
//increment of bar "0" as related to the first one
double r1=MathAbs(MathAbs(Macd_h1_a)-MathAbs(Macd_h1_b));
//increment of bar "1" as related to bar "2"
double r2=MathAbs(MathAbs(Macd_h1_b)-MathAbs(Macd_h1_c));
// -- MACD is below - the trend is moving down
if(Macd_h1_c>Macd_h1_b&&Macd_h1_b>Macd_h1_a)
{
if(r1>r2)
{
Alert("On bar ",a," MACD<0 = ",Macd_h1_a,
"  The trend is moving down \\\'with acceleration");
}
if(r1<r2)
{
Alert("On bar ",a," MACD<0 = ",Macd_h1_a,
"  The trend is moving down \^with slowing down");
}
if((r1==r2)||MathAbs(r1-r2)<0.000015)
{
Alert("On bar ",a," MACD<0 = ",Macd_h1_a,
"  The trend is moving down with constant acceleration");
}
}
// -- MACD is below - the trend is moving up
if(Macd_h1_c<Macd_h1_b&&Macd_h1_b<Macd_h1_a)
{
if(r1>r2)
{
Alert("On bar ",a," MACD<0 =",Macd_h1_a,
"  The trend is moving up //''with acceleration");
}
if(r1<r2)
{
Alert("On bar",a," MACD<0 = ",Macd_h1_a,
"  The trend is moving up /^with slowing down");
}
if((r1==r2)||MathAbs(r1-r2)<0.000015)
{
Alert("On bar ",a," MACD<0 = ",Macd_h1_a,
"  The trend is moving up with constant acceleration");
}
}
// --- MACD is below - the trend reverses down
if(Macd_h1_c<Macd_h1_b&&Macd_h1_b>Macd_h1_a)
{
if(r1>r2)
{
Alert("On bar ",a," MACD<0 = ",Macd_h1_a,
"  The trend reverses down /\\'with acceleration");
}
if(r1<r2)
{
Alert("On bar",a," MACD<0 = ",Macd_h1_a,
"  The trend reverses down //^with slowing down");
}
}
// --- MACD is below - the trend reverses up
if(Macd_h1_c>Macd_h1_b&&Macd_h1_b<Macd_h1_a)
{
if(r1>r2)
{
Alert("On bar ",a," MACD<0 = ",Macd_h1_a,
"  The trend reverses up //''with acceleration");
}
if(r1<r2)
{
Alert("On bar ",a," MACD<0 = ",Macd_h1_a,
"  The trend reverses up \/^with slowing down");
}
}
if(MathAbs(MathAbs(Macd_h1_a)-MathAbs(Macd_h1_b))<0.0002 &&
MathAbs(MathAbs(Macd_h1_c)-MathAbs(Macd_h1_b))<0.0002)
{
Alert("On bar ",a,", it is Flat! within the range of:  ",Macd_h1_c,
"   ",Macd_h1_b,"   ",Macd_h1_a);
}
}```

```// ------------for up-crossing the axis------------------3--&
if(Macd_h1_c<0.0 && Macd_h1_b<0.0 && Macd_h1_a>0&&  // c<0 b<0
Macd_h1_c<Macd_h1_b&&Macd_h1_b<Macd_h1_a)
{
r1=MathAbs(Macd_h1_a)+MathAbs(Macd_h1_b);
r2=MathAbs(Macd_h1_c)-MathAbs(Macd_h1_b);
if(MathAbs(r1)>MathAbs(r2))
{
Alert("On bar ",a," the trend is up-crossing axis //'' with acceleration ");
}
if(MathAbs(r1)<MathAbs(r2))
{
Alert("On bar",a," the trend is up-crossing axis /^ with slowing down ");
}
}
//---
if(Macd_h1_c<0.0 && Macd_h1_b>0.0 && Macd_h1_a>0&&  // b>0 a>0
Macd_h1_c<Macd_h1_b&&Macd_h1_b<Macd_h1_a)
{
r1=MathAbs(Macd_h1_a)-MathAbs(Macd_h1_b);
r2=MathAbs(Macd_h1_c)+MathAbs(Macd_h1_b);
if(MathAbs(r1)>MathAbs(r2))
{
Alert("On bar ",a," the trend is up-crossing axis //''with acceleration");
}
if(MathAbs(r1)<MathAbs(r2))
{
Alert("On bar ",a," the trend is up-crossing axis /^ with slowing down");
}
}```

```//+------------------------------------------------------------------+
//|                                                 TrendMACD v6.mq4 |
//|     for trading                                                  |
//+------------------------------------------------------------------+

extern int a = 0;      // here you can specify the initial bar to be analyzed
extern int period = 30;       // set the value of the period you need
//+------------------------------------------------------------------+
int start()
{
int b,c; b=a+1; c=b+1;
//----
double Macd_h1_a= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,a);
double Macd_h1_b= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,b);
double Macd_h1_c= iMACD(NULL,period,12,26,9,PRICE_CLOSE,MODE_MAIN,c);
…
….```

，我想表达自己的希望，期待使用该脚本能帮助交易新手和富有经验的交易者，以及将错误量降低至少 10%。祝愿大家交易开心！

TrendMACD_v5.mq4 (11.36 KB)
TrendMACD_v6.mq4 (9.63 KB)
30 个指标和震荡指标的对比分析

Layman 的笔记：锯齿形调整浪...