MACD基本人人用,今天在原版的基础上说几种优化思路,交流参考: 第一种:金叉死叉文字以及颜色处理快慢线交叉就是常说的金叉死叉提示,在快慢线的区域中填充颜色更方便区分。 DIFF:EMA(CLOSE,12)-EMA(CLOSE,26); DEA:EMA(DIFF,9); MACD:2*(DIFF-DEA),COLORSTICK; J:=CROSS(DIFF,DEA); S:=CROSSDOWN(DIFF,DEA); DRAWTEXT(J,DEA,'多'); DRAWTEXT(S,DEA,'空'); FILLRGN(DIFF>DEA,DIFF,DEA,RGB(87,0,0)); FILLRGN(DEA>DIFF,DIFF,DEA,RGB(2,58,1)); 点评:这个优化就是给传统的MACD穿了件外套,金叉死叉简单文字提示和颜色提示,当然在震荡盘整行情中信号还是很多,错误率很高。这样必须对信号进一步进行筛选。 第二种:MACD信号与均线信号进行共振均线共振这里有两种思路,第一采用5和10两条均线的交叉信号,与MACD金叉死叉同时出现或者前后出现不超过2根K线,也就是基本主附图信号同时出现信号这种逻辑。另外一种是单根均线比如20日均线作为多空分界线,只做20日均线以上的金叉或者以下的死叉。这两种会筛选出一部分信号。 思路如上,源码如下: (1)5和10两条均线的交叉信号:DIFF:EMA(CLOSE,12)-EMA(CLOSE,26); DEA:EMA(DIFF,9); MACD:2*(DIFF-DEA),COLORSTICK; COND1:=CROSS(MA(CLOSE,5),MA(CLOSE,10)); COND2:=CROSSDOWN(MA(CLOSE,5),MA(CLOSE,10)); J:=CROSS(DIFF,DEA); S:=CROSSDOWN(DIFF,DEA); DRAWTEXT(J AND COND1 ,DEA,'多'); DRAWTEXT(S AND COND2,DEA,'空'); FILLRGN(DIFF>DEA,DIFF,DEA,RGB(87,0,0)); FILLRGN(DEA>DIFF,DIFF,DEA,RGB(2,58,1)); 点评:这种信号就会非常少,会把大部分信号给筛选掉,过犹不及,没信号,所以需要加这个条件:与MACD金叉死叉同时出现或者前后出现不超过2根K线。 DIFF:EMA(CLOSE,12)-EMA(CLOSE,26); DEA:EMA(DIFF,9); MACD:2*(DIFF-DEA),COLORSTICK; COND1:=CROSS(MA(CLOSE,5),MA(CLOSE,10)); COND2:=CROSSDOWN(MA(CLOSE,5),MA(CLOSE,10)); J:=CROSS(DIFF,DEA); S:=CROSSDOWN(DIFF,DEA); DRAWTEXT(BARSLAST(J)<2 AND BARSLAST(COND1)<2,DEA,'多'); DRAWTEXT(BARSLAST(S)<2 AND BARSLAST(COND2)<2,DEA,'空'); FILLRGN(DIFF>DEA,DIFF,DEA,RGB(87,0,0)); FILLRGN(DEA>DIFF,DIFF,DEA,RGB(2,58,1)); 点评:这种信号数量就会比较适中。 (2)20日均线作为多空分界线DIFF:EMA(CLOSE,12)-EMA(CLOSE,26); DEA:EMA(DIFF,9); MACD:2*(DIFF-DEA),COLORSTICK; J:=CROSS(DIFF,DEA); S:=CROSSDOWN(DIFF,DEA); DRAWTEXT(J AND CLOSE>MA(CLOSE,20) ,DEA,'多'); DRAWTEXT(S AND CLOSE<MA(CLOSE,20),DEA,'空'); FILLRGN(DIFF>DEA,DIFF,DEA,RGB(87,0,0)); FILLRGN(DEA>DIFF,DIFF,DEA,RGB(2,58,1)); 点评:这种相对于原来的信号会筛选一部分信号,这个优化的核心主要是均线参数的选择,个人观点,小周期一定不能用小周期参数。那样信号会非常多。 第三种:MACD能量柱颜色变化//红绿柱 STICKLINE1(MACD>=0,MACD,0,1,0),COLORMAGENTA; STICKLINE1(MACD>=0 AND MACD<REF(MACD,1),MACD,0,1,0),COLORYELLOW; STICKLINE1(MACD<0,MACD,0,1,0),COLORBLUE; STICKLINE1(MACD<0 AND MACD>REF(MACD,1),MACD,0,1,0),COLORWHITE; 能量柱会出现山顶和谷底,这种主要是通道与前值对比通过颜色变化标识出来,颜色可以按照自己操作习惯灵活调整。 第四种:MACD背离提示N133:=BARSLAST(J)+1; N233:=BARSLAST(S)+1; HH:=REF(HHV(H,N133),N233);//上次MACD红柱期间合约最大值 HH2:=REF(REF(HH,1),N233);//上上次MACD红柱期间合约最大值 MHD:=VALUEWHEN(SC222,HHV(DIFF,N133));//上次MACD红柱期间DIFF最大值 MHD2:=VALUEWHEN(SC222,REF(MHD,1));//上上次MACD红柱期间DIFF最大值 LL:=REF(LLV(L,N233),N133); LL2:=REF(REF(LL,1),N133); MLD:=VALUEWHEN(JC222,LLV(DIFF,N233)); MLD2:=VALUEWHEN(JC222,REF(MLD,1)); A:=MACD<0&&HH>HH2&&MHD<MHD2;//顶背离 B:=MACD>0&&LL<LL2&&MLD>MLD2;//底背离 A122:=BACKSET(CROSS(A,0.5),REF(HHVBARS(DIFF,N133),1)+1+1); A222:=BACKSET(CROSS(A,0.5),REF(HHVBARS(DIFF,N133),SUMBARS(SC222,2))+SUMBARS(SC222,2)+1); B1:=BACKSET(CROSS(B,0.5),REF(LLVBARS(DIFF,N233),1)+1+1); B2:=BACKSET(CROSS(B,0.5),REF(LLVBARS(DIFF,N233),SUMBARS(JC222,2))+SUMBARS(JC222,2)+1); DRAWLINE1(CROSS(A222,0.5),DIFF,CROSS(A122,0.5),DIFF,0),COLORRED,LINETHICK2; DRAWLINE1(CROSS(B2,0.5),DIFF,CROSS(B1,0.5),DIFF,0),COLORGREEN,LINETHICK2; VAR6:=(2*CLOSE+HIGH+LOW)/4; VAR8:=LLV(LOW,20); VARAA:=HHV(HIGH,26); B8:=EMA((VAR6-VAR8)/(VARAA-VAR8)*100,8); B18:=EMA(B8,5); K22:=B8>80 AND CROSS(B18,B8); K1:=BARSLAST(K22); K2:=REF(K1,1); K底:=B8<20 AND CROSS(B8,B18); K底1:=BARSLAST(K底); K底2:=REF(K底1,1); DRAWTEXT(REF(B8,1)>80 AND CROSS(B18,B8) AND REF(B8,1)<REF(B8,K2+2) AND REF(C,1)>REF(C,K2+2),MAX(DIFF,DEA),'顶背离'),COLORCYAN,VALIGN0; DRAWTEXT(B8<25 AND CROSS(B8,B18) AND B8>REF(B8,K底2) AND C<REF(C,K底2),MAX(DIFF,DEA),'底背离'),COLORFF00FF,VALIGN0; 点评:背离的原理是和价格走势对比,比如顶背离,当价格不断创出新高,但是快慢线并没有同步新高,这种就是顶背离,顶背离出现预示着价格即将反转走弱,预备做空。反之底背离同理。 第五种:MACD放至主图与布林通道共振MID:MA(CLOSE,26); TMP2:=STD(CLOSE,26); TOP:MID+2*TMP2; BOTTOM:MID-2*TMP2; DIFF:=(EMA(CLOSE,12) - EMA(CLOSE,26))*4.1; DEA:=EMA(DIFF,9); MA60:=MA(C,60); DKB:MA60+DIFF; DKA:MA60+DEA; FILLRGN(DKB>DKA,DKB,DKA,RGB(81,18,2)); FILLRGN(DKB<DKA,DKB,DKA, COLOR007300); DRAWKLINE1(H,O,L,C); 点评:这个优化把MACD从附图放到主图,截长补短,一方面尽量做布林向上突破下轨的金叉,或向下突破上轨的死叉,在一定程度上对于布林通道的假顶假底有一定判断作用。 结尾 |
|