请大家注意。并请高手回答,
大家注意到了没有,许多看盘器上的MACD 指标(同一时间周期)不一样,特别是柱状图差距很大,有的甚至还是相反的。这将影响买卖的时间点。MT4 的就和 FutureTrader及招行 的彼此不一样,不仅图形的方向不一样,而且图形也不一样。这样MACD指标就很难给出正确的买卖时间了。我本想自己从编辑一下MT的macd 指标,可没看明白,所以想求高手给解释一下。 特说明参数是一样的,都是,12。26。9 两个算法不一样的,我研究了一下。有这样的算法:
DIFF : EMA(CLOSE,SHORT) - EMA(CLOSE,LONG);
DEA: EMA(DIFF,M,1);
MACD : 2*(DIFF-DEA), COLORSTICK
MT4 是这样的:
DIFF : EMA(CLOSE,SHORT) - EMA(CLOSE,LONG);
DEASMA(DIFF,M);
MACD : 2*(DIFF-DEA), COLORSTICK
图形是有一定差距的。 //+------------------------------------------------------------------+
//| Custom MACD.mq4 |
//| Copyright ?2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#propertycopyright "Copyright ?2004, MetaQuotes Software Corp."
#propertylink "http://www.metaquotes.net/"
//---- indicator settings
#propertyindicator_separate_window
#propertyindicator_buffers 4
#propertyindicator_color1Blue
#propertyindicator_color2Yellow
#propertyindicator_color3Red
#propertyindicator_color4Green
//int indicator_color3;
//---- indicator parameters
extern int FastEMA=5;
extern int SlowEMA=34;
extern int SignalSMA=5;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double temp;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2)&& !SetIndexBuffer(2,ind_buffer3)&& !SetIndexBuffer(3,ind_buffer4))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
ind_buffer1=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
ind_buffer2=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);
for(i=0; i<limit; i++)
{
temp=1.3*(ind_buffer1-ind_buffer2);
if(temp>0) {ind_buffer3=temp;ind_buffer4=0;}
else {ind_buffer3=0;ind_buffer4=temp;}
}
//---- done
return(0);
}
MT中调试通过
页:
[1]