Where are the statements for indicator buffers?
init() { SetIndex(0,DIFF0); SetIndex(0,DIFF1); SetIndex(0,DIFF2); SetIndex(0,DEA0); SetIndex(0,DEA1); SetIndex(0,DEA2); }See the Moving Average Convergence/Divergence, MACD (indicator) and MACD Sample (Expert Advisor)
能详细更改一下吗?我看不懂
DEA0=iMAOnArray(DIFF0,Bars,SignalSMA,0,MODE_SMA,0);是MACD中的慢线吗?
DIFF0=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,0)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,0);是快线吗?
1.3*(DIFF0-DEA0);是MACD的值吗?
See the custom MACD indicator:
//+------------------------------------------------------------------+ //| Custom MACD.mq4 | //| Copyright © 2004, MetaQuotes Software Corp. | //| https://www.metaquotes.net// | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, MetaQuotes Software Corp." #property link "https://www.metaquotes.net//" //---- indicator settings #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Silver #property indicator_color2 Red #property indicator_width1 2 //---- indicator parameters extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; //---- indicator buffers double MacdBuffer[]; double SignalBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_LINE); SetIndexDrawBegin(1,SignalSMA); IndicatorDigits(Digits+1); //---- indicator buffers mapping SetIndexBuffer(0,MacdBuffer); SetIndexBuffer(1,SignalBuffer); //---- 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(); //---- 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++) MacdBuffer[i]=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++) SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i); //---- done return(0); } //+------------------------------------------------------------------+Here are main line(fast) of MACD
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);and signal line (slow) of MACD
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);You can get value both of lines (indicator buffers) on each bar with function iCustom. As shown in expert adviser MACD Sample
例如双线的MACD快线金叉慢线
..........
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
double DIFF0,DIFF1,DIFF2,DEA0,DEA1,DEA2;
DIFF0=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,0)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,0);//股票MACD的快线DIFF的当前值
DIFF1=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,1)-iMA(NULL, 0,SlowEMA, 0, MODE_EMA, PRICE_CLOSE, 1);//股票MACD的快线DIFF的前1值
DIFF2=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,2)-iMA(NULL, 0,SlowEMA, 0, MODE_EMA, PRICE_CLOSE, 2);//股票MACD的快线DIFF的前2值
DEA0=iMAOnArray(DIFF0,Bars,SignalSMA,0,MODE_SMA,0);//股票MACD的慢线DEA的当前值
DEA1=iMAOnArray(DIFF1,Bars,SignalSMA,0,MODE_SMA,1);//股票MACD的慢线DEA的前1值
DEA2=iMAOnArray(DIFF2,Bars,SignalSMA,0,MODE_SMA,2);//股票MACD慢线DEA的前2值
if(DIFF0>DIFF1&&DIFF1>DIFF2&&DIFF0>DEA0&&DIFF2<DEA2)//快线向上并交叉慢线
{
............)//执行买进定单
...............
return(0);