MACD背离通达信公式 副图 源码附图
DIF:=EMA(CLOSE,12)-EMA(CLOSE,26);
MACD:=EMA(DIF,9),COLOR33CCFF;
DEF:2*(DIF-MACD),COLORFFFF00,LINETHICK0;
STICKLINE(DEF>=0 AND DEF>=REF(DEF,1),0,DEF,0,0),COLORRED;
STICKLINE(DEF>=0 AND DEF< REF(DEF,1),0,DEF,0.0,0),COLORRED;
STICKLINE(DEF<0 AND DEF>=REF(DEF,1),0,DEF,0.0,0),COLORCYAN;
STICKLINE(DEF<0 AND DEF< REF(DEF,1),0,DEF,0.0,0),COLORCYAN;
IF(DIF<1000,0,DRAWNULL),COLORBROWN;
K1:=BACKSET(DIF>REF(DIF,1),2);
强DIF:IF(K1,DIF,DRAWNULL),COLORRED;
K2:=BACKSET(DIF<REF(DIF,1),2);
弱DIF:IF(K2,DIF,DRAWNULL),COLORFF8B80;
K3:=BACKSET(MACD>REF(MACD,1),2);
强MACD:IF(K3,MACD,DRAWNULL),COLORLIRED;
K4:=BACKSET(MACD<REF(MACD,1),2);
弱MACD:IF(K4,MACD,DRAWNULL),COLORFF8B80;
底拐: DRAWLINE(DIF>=HHV(DIF,21),DIF,DIF<=LLV(DIF,21),DIF,1),COLORWHITE,POINTDOT;
DRAWICON(强DIF>底拐 AND REF(DIF,1)=REF(底拐,1) AND REF(DIF,2)>REF(DIF,1),0,1);
A1:=BARSLAST(REF(CROSS(DIF,MACD),1));
底背离:=REF(CLOSE,A1+1)>CLOSE AND DIF>REF(DIF,A1+1) AND CROSS(DIF,MACD);
DRAWLINE(A1=0,MACD,底背离,MACD,0),COLORYELLOW,LINETHICK2;
A2:=BARSLAST(REF(CROSS(MACD,DIF),1));
顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIF,A2+1)>DIF AND CROSS(MACD,DIF);
DRAWLINE(A2=0,MACD,顶背离,MACD,0),COLORGREEN,LINETHICK2;
AA1:=IF(DEF>0,1,-1);
AA2:=REF(AA1,1);
AA3:=AA1*AA2;
AA4:=BARSLAST(AA3<0);
AA5:=AA4+1;
面积:SUM(DEF,AA5)/10,COLORGREEN;
未来函数检测结果如下:
该公式包含未来函数:BACKSET
解密、编写股票、期货策略请联系QQ或微信同号:88652583
相关股票指标公式
原理解析:
DIF赋值:收盘价的12日指数移动平均-收盘价的26日指数移动平均
MACD赋值:DIF的9日指数移动平均,COLOR33CCFF
输出
DEF:2*(DIF-MACD),COLORFFFF00,LINETHICK0
STICKLINE(DEF>=0 AND DEF>=1日前的DEF,0,DEF,0,0),画红色
STICKLINE(DEF>=0 AND DEF< 1日前的DEF,0,DEF,0.0,0),画红色
STICKLINE(DEF<0 AND DEF>=1日前的DEF,0,DEF,0.0,0),画青色
STICKLINE(DEF<0 AND DEF< 1日前的DEF,0,DEF,0.0,0),画青色
如果D<1000返回0否则返回DRAWNULL
K1赋值:BACKSET(DIF>1日前的DIF,2)
如果:K1返回DIF否则返回DRAWNULL
K2赋值:BACKSET(DIF<1日前的DIF,2)
如果:K2返回DIF否则返回DRAWNULL
K3赋值:BACKSET(MACD>1日前的MACD,2)
如果K3返回MACD否则返回DRAWNULL
K4赋值:BACKSET(MACD<1日前的MACD,2)
如果K4返回MACD否则返回DRAWNULL
输出
底拐: DRAWLINE(DIF>=21日内DIF最高值,DIF,DIF<=21日内DIF最低值,DIF,1),画白色,POINTDOT
DRAWICON(强DIF>底拐 AND 1日前的DIF=1日前的底拐 AND 2日前的DIF>1日前的DIF,0,1)
A1赋值:上次1日前的DIF上穿MACD距今天数
底背离赋值:A1+1日前的收盘价>收盘价 AND DIF>A1+1日前的DIF AND DIF上穿MACD
DRAWLINE(A1=0,MACD,底背离,MACD,0),画黄色, 线宽为2
A2赋值:上次1日前的MACD上穿DIF距今天数
顶背离赋值:A2+1日前的收盘价<收盘价 AND A2+1日前的DIF>DIF AND MACD上穿DIF
DRAWLINE(A2=0,MACD,顶背离,MACD,0),画绿色, 线宽为2
如果DEF>0返回1否则返回-1
AA2赋值:1日前的AA1
AA3赋值:AA1*AA2
AA4赋值:上次AA3<0距今天数
AA5赋值:AA4+1
输出
面积:AA5的DEF日累和/10,画绿色