php计算macd,MT4里的MACD和平常所用的MACD计算公式是什么?

你这个 要看 MT4 macd指标的源代码来分析:

//+------------------------------------------------------------------+

//|                                                  Custom MACD.mq4 |

//|                   Copyright 2005-2014, MetaQuotes Software Corp. |

//|                                              http://www.mql4.com |

//+------------------------------------------------------------------+

#property copyright   "2005-2014, MetaQuotes Software Corp."

#property link        "http://www.mql4.com"

#property description "Moving Averages Convergence/Divergence"

#property strict

#include

//--- indicator settings

#property  indicator_separate_window

#property  indicator_buffers 2

#property  indicator_color1  Silver

#property  indicator_color2  Red

#property  indicator_width1  2

//--- indicator parameters

input int InpFastEMA=12;   // Fast EMA Period

input int InpSlowEMA=26;   // Slow EMA Period

input int InpSignalSMA=9;  // Signal SMA Period

//--- indicator buffers

double    ExtMacdBuffer[];

double    ExtSignalBuffer[];

//--- right input parameters flag

bool      ExtParameters=false;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit(void)

{

IndicatorDigits(Digits+1);

//--- drawing settings

SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexStyle(1,DRAW_LINE);

SetIndexDrawBegin(1,InpSignalSMA);

//--- indicator buffers mapping

SetIndexBuffer(0,ExtMacdBuffer);

SetIndexBuffer(1,ExtSignalBuffer);

//--- name for DataWindow and indicator subwindow label

IndicatorShortName("MACD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")");

SetIndexLabel(0,"MACD");

SetIndexLabel(1,"Signal");

//--- check for input parameters

if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA)

{

Print("Wrong input parameters");

ExtParameters=false;

return(INIT_FAILED);

}

else

ExtParameters=true;

//--- initialization done

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Moving Averages Convergence/Divergence                           |

//+------------------------------------------------------------------+

int OnCalculate (const int rates_total,

const int prev_calculated,

const datetime& time[],

const double& open[],

const double& high[],

const double& low[],

const double& close[],

const long& tick_volume[],

const long& volume[],

const int& spread[])

{

int i,limit;

//---

if(rates_total<=InpSignalSMA || !ExtParameters)

return(0);

//--- last counted bar will be recounted

limit=rates_total-prev_calculated;

if(prev_calculated>0)

limit++;

//--- macd counted in the 1-st buffer

for(i=0; i

ExtMacdBuffer=iMA(NULL,0,InpFastEMA,0,MODE_EMA,PRICE_CLOSE,i)-

iMA(NULL,0,InpSlowEMA,0,MODE_EMA,PRICE_CLOSE,i);

//--- signal line counted in the 2-nd buffer

SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);

//--- done

return(rates_total);

}

//+------------------------------------------------------------------+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值