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

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

上一主题 下一主题
离线nzl88
 
发帖
21
金钱
19
威望
0
贡献
40
交易币
0
用MT4以来一直喜欢双线的macd,不过很多交易策略中用的是单线的macd,请教如何使用双线macd的指标。 XJ\hd,R   
这是我的双线macd源码: qk{'!Ii  
//+------------------------------------------------------------------+ .-I|DVHe  
//|                                                       macd-2.mq4 | D@54QJ<  
//|                   Copyright ?2004-07, MetaQuotes Software Corp. | }6m?d!m  
//|                                       http://www.metaquotes.net/ | :- +4:S  
//+------------------------------------------------------------------+ kyUl{Zj  
#property copyright "Copyright ?2004-07, MetaQuotes Software Corp." i?}>.$j  
#property link "http://www.metaquotes.net/" [Eq<":)  
//---- indicator settings /p`&;/V|  
#property indicator_separate_window C3;[e0.1b  
#property indicator_buffers 4 FvImX  
#property indicator_color1 Red a5c'V   
#property indicator_color2 DarkTurquoise D'i6",Z>  
#property indicator_color3 Gold f6ZZ}lwaV  
#property indicator_color4 Magenta I0w%8bs  
#property indicator_width1 1 =4NqjSH  
#property indicator_width2 1 O.\h'3C  
//---- indicator parameters #+jUhxq  
extern int FastEMA=12; Da,Tav%b  
extern int SlowEMA=26; gA:TL{X0  
extern int SignalEMA=9; _w u*M  
//---- indicator buffers Mtp%co)f  
double ind_buffer1[]; L#j/0IHD  
double ind_buffer2[]; 5 si}i'in  
double ind_buffer3[]; #+G`!<7/@f  
double ind_buffer4[]; Z3;=w%W  
//+------------------------------------------------------------------+ 9q|7<raS  
//| Custom indicator initialization function | $c =&0yt5  
//+------------------------------------------------------------------+ l%PnB )F  
int init() ,y.3Fe  
{ # #>a&,  
//---- 2 additional buffers are used for counting. }su6izx  
IndicatorBuffers(5); 6/7F">@j  
//---- drawing settings &;U|7l~vl  
SetIndexStyle(0,DRAW_HISTOGRAM); LDX y}hm)  
SetIndexStyle(1,DRAW_HISTOGRAM); gMay  
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 ); E{oB2;P  
SetIndexDrawBegin(0,SignalEMA); sH@  &*  
SetIndexDrawBegin(1,SignalEMA); ?o>6S EGW  
//---- 4 indicator buffers mapping %IU4\ZY>  
if(!SetIndexBuffer(0,ind_buffer1) && H<z30r/-w  
!SetIndexBuffer(1,ind_buffer2) && cf&C|U  
!SetIndexBuffer(2,ind_buffer3) && o{g@Nk'f  
!SetIndexBuffer(3,ind_buffer4)) QU%N*bFW%P  
Print("cannot set indicators\' buffers!"); %0 qc@4  
//---- name for DataWindow and indicator subwindow label C?(y2p`d\  
IndicatorShortName("MACD-2 ("+FastEMA+","+SlowEMA+","+SignalEMA+")"); ~Ji>[#W K  
//---- initialization done Cl{{H]QngX  
return(0); VrudR#q  
} [ns&Y0Y`t  
//+------------------------------------------------------------------+ Jfe~ ,cI  
//| Oscillator | >*Sv0#  
//+------------------------------------------------------------------+ 2"zIR (  
int start() XpOCQyFnM  
{ W;5N04ko  
int limit; ST#PMb'izn  
int counted_bars=IndicatorCounted(); T3 =)F%  
double prev,current; < JGYr 4V  
//---- check for possible errors CzK%x?~]  
if(counted_bars<0) return(-1); _P>1`IR  
//---- last counted bar will be recounted AsV8k _qZL  
if(counted_bars>0) counted_bars--; :Xb*m85y  
limit=Bars-counted_bars; o,iS&U"TC  
//---- macd counted in the 1-st additional buffer ^Z#<tN;  
for(int i=0; i<limit; i++) <t% Ao,"  
ind_buffer3=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i); '&rw=.cU  
//---- signal line counted in the 2-nd additional buffer <!$j9)~x  
for(i=0; i<limit; i++) O%r S;o  
ind_buffer4=iMAOnArray(ind_buffer3,Bars,SignalEMA,0,MODE_EMA, i); Fo--PtY`p  
//---- dispatch values between 2 buffers uOy\{5s8  
bool up=true; yTMGISX5  
for(i=limit-1; i>=0; i--) X7(rg W8  
{ KyVe0>{_u  
current=ind_buffer3-ind_buffer4; c/,|[ t  
prev=ind_buffer3[i+1]-ind_buffer4[i+1]; cHfK-R  
if(current>prev) up=true; _A# x&<c  
if(current<prev) up=false; * S+7BdP  
if(!up) 4.$hHFqS^5  
{ .-gm"lB  
ind_buffer2=3*current; |$i1]Dr6  
ind_buffer1=0.0; $txWVjR?\  
} ! 7#froh  
else 9=sMKc%!-  
{ ^Ypb"Wx8  
ind_buffer1=3*current; +RKE|*y  
ind_buffer2=0.0; VA*79I#_q  
} 1+y6W1m^R  
} mqfEs0~I  
return(0); /m|&nl8"qe  
} q2"'W|I  
d1LTyzLr  
RHA>fXp  
J7aK3 he  
6 GevO3  
这是截图,有个策略是柱状线从下跌后连续三个根上升(由蓝色变红色),然后报警,自动挂单交易。 uvc{RP  
柱状线的值就是上面的:ind_buffer2=3*current; -X[8soz  
m"> =QP  
请问怎么编写这个EA?试了好几次都没搞定,向高手请教。 $oBZe>s .  
IgnY* 2FT  
@%B!$\]  
[ 此帖被nzl88在2012-01-08 23:26重新编辑 ]
 

  • 在线咨询
  • 400-881-0680