论坛风格切换切换到宽版
  • 492阅读
  • 0回复

请教双线macd的指标运用。 [复制链接]

上一主题 下一主题
离线nzl88
 
发帖
21
金钱
19
威望
0
贡献
40
交易币
0
用MT4以来一直喜欢双线的macd,不过很多交易策略中用的是单线的macd,请教如何使用双线macd的指标。  l7t  
这是我的双线macd源码: Ox)<"8M  
//+------------------------------------------------------------------+ =sW K;`  
//|                                                       macd-2.mq4 | gPn0-)<  
//|                   Copyright ?2004-07, MetaQuotes Software Corp. | >FeCa h Fn  
//|                                       http://www.metaquotes.net/ | 92j[b_P  
//+------------------------------------------------------------------+ ,L%]}8EL"  
#property copyright "Copyright ?2004-07, MetaQuotes Software Corp." Wt%Wpb8  
#property link "http://www.metaquotes.net/" o5]-Kuw`  
//---- indicator settings fx>QP?Z  
#property indicator_separate_window R.1.LB  
#property indicator_buffers 4 <XrXs  
#property indicator_color1 Red xm=Gt$>.o  
#property indicator_color2 DarkTurquoise mdbi@ms@  
#property indicator_color3 Gold uNEl]Q]<e]  
#property indicator_color4 Magenta ]?V:+>t=  
#property indicator_width1 1 ;mI^J=V3  
#property indicator_width2 1 [zl4"|_`  
//---- indicator parameters o;DK]o>kH  
extern int FastEMA=12; "1\GU1x  
extern int SlowEMA=26; %Cj_z  
extern int SignalEMA=9; -G7)Y:  
//---- indicator buffers $v_&j E  
double ind_buffer1[]; 3_9CREZCl  
double ind_buffer2[]; _PGd\>Ve  
double ind_buffer3[]; ;K7kBp\d  
double ind_buffer4[]; }(DH_0  
//+------------------------------------------------------------------+ IMM+g]#e  
//| Custom indicator initialization function | j(k%w  
//+------------------------------------------------------------------+ j[mII5e7g  
int init() +Q"~2_q5/;  
{ +e.w]\}  
//---- 2 additional buffers are used for counting. LXJ;8uW2y  
IndicatorBuffers(5); 8sBT&A6&j  
//---- drawing settings L^Q;M,.c;  
SetIndexStyle(0,DRAW_HISTOGRAM); ]9 _}S  
SetIndexStyle(1,DRAW_HISTOGRAM); =-r); d  
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 ); ]91QZ~4a  
SetIndexDrawBegin(0,SignalEMA); ]a uqf  
SetIndexDrawBegin(1,SignalEMA); Ol h{<~Fv  
//---- 4 indicator buffers mapping b5Q>e%i#  
if(!SetIndexBuffer(0,ind_buffer1) && o[WDPIG  
!SetIndexBuffer(1,ind_buffer2) && rev*G:  
!SetIndexBuffer(2,ind_buffer3) && ,d*hhe  
!SetIndexBuffer(3,ind_buffer4)) &dK !+  
Print("cannot set indicators\' buffers!"); WK7?~R%rq  
//---- name for DataWindow and indicator subwindow label :{lP9%J-  
IndicatorShortName("MACD-2 ("+FastEMA+","+SlowEMA+","+SignalEMA+")"); to,\n"$~!  
//---- initialization done v3XM-+Z4  
return(0); 3b]M\ F9  
} C&*1H`n  
//+------------------------------------------------------------------+ Qs59IZ  
//| Oscillator | YC56] Zp  
//+------------------------------------------------------------------+ Yb/*2iWX  
int start() xb9+-{<J  
{ ykPiZK  
int limit; ,#&7+e!]>P  
int counted_bars=IndicatorCounted(); rZaO^}u]  
double prev,current; Q!U}  
//---- check for possible errors X|eZpIA45  
if(counted_bars<0) return(-1); pxd=a!(  
//---- last counted bar will be recounted q=BljSX  
if(counted_bars>0) counted_bars--; l&qCgw  
limit=Bars-counted_bars; |.UY' B  
//---- macd counted in the 1-st additional buffer er)I".|  
for(int i=0; i<limit; i++) u%)gnj_  
ind_buffer3=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i); 6xJffl  
//---- signal line counted in the 2-nd additional buffer bP 9ly9FH  
for(i=0; i<limit; i++) #[lhem]IC  
ind_buffer4=iMAOnArray(ind_buffer3,Bars,SignalEMA,0,MODE_EMA, i); `<X-3)>;G  
//---- dispatch values between 2 buffers U-u?oU-.'  
bool up=true; chE!,gik  
for(i=limit-1; i>=0; i--) PFh ^Z L  
{ x [FLV8`b|  
current=ind_buffer3-ind_buffer4; +&`W\?.~  
prev=ind_buffer3[i+1]-ind_buffer4[i+1]; zzQWHg]/  
if(current>prev) up=true; b]+F/@h~]  
if(current<prev) up=false; (hzN(Dh  
if(!up) 6@J=n@J$p  
{ \beO5]KS<  
ind_buffer2=3*current; jV3PTU  
ind_buffer1=0.0; 5~JT*Ny  
} 1PkCWRpR  
else k&]nF,f  
{ V)`2 Kw  
ind_buffer1=3*current; bmfM_oz  
ind_buffer2=0.0; SA x9cjj+  
} _!\d?]Ya  
} T # \  
return(0); 2@&r!Q|1vR  
} J!6FlcsZm  
{4Of.  
H",B[ YK  
/:&!o2&1H  
C_.9qo]DT7  
这是截图,有个策略是柱状线从下跌后连续三个根上升(由蓝色变红色),然后报警,自动挂单交易。  +]db-  
柱状线的值就是上面的:ind_buffer2=3*current; yVd^A2  
Wgq|Q*  
请问怎么编写这个EA?试了好几次都没搞定,向高手请教。 Y Y:Bw W:  
092t6D}  
j =_rUc'Me  
[ 此帖被nzl88在2012-01-08 23:26重新编辑 ]
 

  • 在线咨询
  • 400-881-0680