量化交易技术指标操盘手实战法
MACD是根据移动平均线较易掌握趋势变动的方向之优点所发展出来的,它是利用二条不同速度(一条变动的速率快──短期的移动平均线,另一条较慢──长期的移动平均线)的指数平滑移动平均线来计算二者之间的差离状况(DIF)作为研判行情的基础,然后再求取其DIF之9日平滑移动平均线,即MACD线。MACD实际就是运用快速与慢速移动平均线聚合与分离的征兆,来研判买进与卖进的时机和讯号。(1)MACD的基本运用方法:MACD在应用上,是以12日为快速移动平均线(12日EMA),而以26日为慢速移动平均线(26日EMA),首先计算出此两条移动平均线数值,再计算出两者数值间的差离值,即差离值(DIF)=12日EMA-26日EMA。然后根据此差离值,计算9日EMA值(即为MACD值);将DIF与MACD值分别绘出线条,然后依“交错分析法”分析,当DIF线向上突破MACD平滑线即为涨势确认之点,也就是买入讯号。反之,当DIF线向下跌破MACD平滑线时,即为跌势确认之点,也就是卖出讯号。(2)应用法则:① DIF和MACD在0以上,大势属多头市场。② DIF向上突破MACD时,可作买;若DIF向下跌破MACD时,只可作原单的平仓,不可新卖单进场。③ DIF和MACD在0以下,大势属空头市场。④ DIF向下跌破MACD时,可作卖;若DIF向上突破MACD时,只可作原单的平仓,不可新买单进场。⑤ 高档二次向下交叉大跌,低档二次向上交叉大涨。
《提示:上图MACD指标的参数是修改过的和正常参数不一致》
以下是量化提示MACD 指标源码
DIFF:EMA(CLOSE,12) – EMA(CLOSE,26);
DEA:EMA(DIFF,9);
MACD:2*(DIFF-DEA),COLORSTICK;
JC:=CROSS(DIFF,DEA);
SC:=CROSSDOWN(DIFF,DEA);
N1:=BARSLAST(JC)+1;
N2:=BARSLAST(SC)+1;
MA5:=MA(C,5),NODRAW;
HH:=VALUEWHEN(CROSSDOWN(DIFF,DEA),DIFF),NODRAW;//B点DIFF值
HHM:=VALUEWHEN(CROSSDOWN(DIFF,DEA),MA5),NODRAW;//B叉点5均线值
HHC:=VALUEWHEN(CROSSDOWN(DIFF,DEA),C),NODRAW;//B叉点K收盘价
HH2:=REF(HH,N2),NODRAW;//A点DIFF值
HHM2:=REF(HHM,N2),NODRAW;//A点5均线值
HHC2:=REF(HHC,N2),NODRAW;//A点K收盘价
CON:=HH2>HH&&(HHM2<HHM||HHC2<HHC);
BB:=BACKSET(CON&&SC,HHVBARS(DIFF,N1)+1);
AA:=BACKSET(CON&&SC,REF(HHVBARS(DIFF,N1),N1)+N1+1);
DRAWLINE1(CROSS(AA=1,0.5),DIFF,CROSS(BB=1,0.5),DIFF,0),COLORGREEN;
DRAWTEXT(CROSS(BB=1,0.5),DIFF,顶背离),VALIGN0,COLORGREEN;
LL:=VALUEWHEN(CROSS(DIFF,DEA),DIFF),NODRAW;//B点DIFF值
LLM:=VALUEWHEN(CROSS(DIFF,DEA),MA5),NODRAW;//B叉点5均线值
LLC:=VALUEWHEN(CROSS(DIFF,DEA),C),NODRAW;//B叉点K收盘价
LL2:=REF(LL,N1),NODRAW;//A点DIFF值
LLM2:=REF(LLM,N1),NODRAW;//A点5均线值
LLC2:=REF(LLC,N1),NODRAW;//A点K收盘价
COM:=LL2<LL&&(LLM2>LLM||LLC2>LLC);
CC:=BACKSET(COM&&JC,LLVBARS(DIFF,N2)+1);
DD:=BACKSET(COM&&JC,REF(LLVBARS(DIFF,N2),N2)+N2+1);
DRAWLINE1(CROSS(DD=1,0.5),DIFF,CROSS(CC=1,0.5),DIFF,0),COLORGREEN;
DRAWTEXT(CROSS(CC=1,0.5),DIFF,低背离),VALIGN0,COLORYELLOW;
DRAWTEXT(CROSS(DIFF,0),DIFF,多,COLORGREEN),FONTSIZE20;
DRAWTEXT(CROSS(0,DIFF),DIFF,空,COLORRED),FONTSIZE20;
DRAWTEXT(CROSS(0,DEA),DEA,持仓空),FONTSIZE15,COLORGREEN;
DRAWTEXT(CROSSDOWN(0,DEA),DEA,持仓多),FONTSIZE15,COLORRED;
JCCOUNT:=COUNT(CROSS(DIFF,DEA),BARSLAST(DEA>=0));
二次金叉:=CROSS(DIFF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1;
DRAWTEXT(二次金叉,DEA,M二次金叉),COLORRED,FONTSIZE14,VALIGN0,ALIGN0;
DRAWICON(CROSS(DIFF,DEA),DIFF,ICO1);
DRAWICON(CROSS(DEA,DIFF),DEA,ICO91);
STICKLINE1(MACD>MA(MACD,5),MACD,1.2*MA(MACD,5),0,0),COLORYELLOW;
RIQIZSDQF:=230228;
发表回复