MACD叠加KDJ各金叉和背离信号提示通达信公式 副图 源码附图
RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100;
K:=SMA(RSV,3,1);
D:=SMA(K,3,1);
J:=3*K-2*D;
DIFF:=EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD:=2*(DIFF-DEA);
RSV1:=(HHV(H,9.8)-C)/(HHV(H,9.8)-LLV(L,9.8))*101;
KK:=SMA(RSV1,3,1);
DD:=SMA(KK,3,1);
JJ:=3*KK-2*DD;
KX:=250;
KH:=HHV(K,KX);
DH:=HHV(D,KX);
JH:=HHV(J,KX);
KL:=LLV(K,KX);
DL:=LLV(D,KX);
JL:=LLV(J,KX);
HKMAX:=MAX(KH,MAX(DH,JH));
LKMIN:=MIN(KL,MIN(DL,JL));
KHLB:=(HKMAX+LKMIN)/2;
KHLC:=HKMAX-LKMIN;
MHF:=HHV(DIFF,KX);
MHD:=HHV(DEA,KX);
MHM:=HHV(MACD,KX);
MLF:=LLV(DIFF,KX);
MLD:=LLV(DEA,KX);
MLM:=LLV(MACD,KX);
HMAX:=MAX(MHF,MAX(MHD,MHM));
LMIN:=MIN(MLF,MIN(MLD,MLM));
FHLB:=(HMAX-LMIN)/100;
FHLC:=HMAX-LMIN;
SH:=(0-FHLB)*(KHLC/FHLC)+KHLB;
DIFFA:=(DIFF-FHLB)*(KHLC/FHLC)+KHLB;
DEAA:=(DEA-FHLB)*(KHLC/FHLC)+KHLB;
DRAWBAND(DIFFA,RGB(255,64,64),DEAA,RGB(64,255,64));
MACDA:=(MACD-FHLB)*(KHLC/FHLC)+KHLB;
CDA:=MACD<REF(MACD,1) AND MACD>0;
CDB:=MACD>=REF(MACD,1) AND MACD>0;
CDC:=MACD>REF(MACD,1) AND MACD<0;
CDD:=MACD<=REF(MACD,1) AND MACD<0;
STICKLINE(CDA,SH,MACDA,0.1,0),COLORBLUE;{0上蓝柱}
STICKLINE(CDB,SH,MACDA,0.1,0),COLOR8000FF; {0上红柱}
STICKLINE(CDC,SH,MACDA,0.1,0),COLOR8000FF;{0下红柱}
STICKLINE(CDD,SH,MACDA,0.1,0),COLORBLUE;{0下蓝柱}
DRAWTEXT(BARSTATUS=2,SH,' 0轴'),COLORWHITE;
{-------------------- 股票指标网 ----------------------------}
{传统KDJ}
KKK:SMA(RSV,3,1),COLORWHITE,LINETHICK2;
DDD:SMA(KKK,3,1),COLORYELLOW,LINETHICK2;
JJJ:3*KKK-2*DDD,COLORMAGENTA,LINETHICK2;
DRAWTEXT(ISLASTBAR,KKK,' ←K'),COLORWHITE;
DRAWTEXT(ISLASTBAR,DDD,' ←D'),COLORYELLOW;
DRAWTEXT(ISLASTBAR,JJJ,' ←J'),COLORMAGENTA;
{MACD KDJ 金叉.,共振 信号}
A:=CROSS(DIFF,DEA) AND CROSS(KKK,DDD) AND CROSS(JJJ,DDD);
{共振出现时图标}
DRAWICON(A,20,25);
DRAWTEXT(A,20,' MACD&KDJ金叉.,共振'),COLORYELLOW;
{低位金叉标识}
低位金叉:=CROSS(DIFF,DEA) AND DIFF<-0.1;
DRAWICON(低位金叉,10,41);
DRAWTEXT(低位金叉,10,' MACD低位金叉'),COLORWHITE;
{二次金叉}
JCCOUNT:=COUNT(CROSS(DIFF,DEA),BARSLAST(DEA>=0));
二次金叉:=CROSS(DIFF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1;
DRAWICON(二次金叉,0,41);
DRAWTEXT(二次金叉,0,' MACD二次金叉'),COLORYELLOW;
{MACD,KDJ,RSI顶底背离}
{MACD底背}
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
B1:=REF(C,A1+1)>C AND REF(DIFF,A1+1)<DIFF AND CROSS(DIFF,DEA);
{MACD顶背}
C1:=BARSLAST(REF(CROSS(DEA,DIFF),1));
D1:=REF(C,C1+1)<C AND REF(DIFF,C1+1)>DIFF AND CROSS(DEA,DIFF);
{MACD底背信号}
DRAWICON((B1>0),-10,41);
DRAWTEXT((B1>0),-10,' MACD底背离'),COLORRED;
{MACD顶背信号}
DRAWICON((D1>0),-10,37);
DRAWTEXT((D1>0),-10,' MACD顶背离'),COLORGREEN;
{KDJ底背}
A2:=BARSLAST(REF(CROSS("KDJ.K"(9,3,3),"KDJ.D"(9,3,3)),1));
B2:=REF(C,A2+1)>C AND REF("KDJ.K"(9,3,3),A2+1)<"KDJ.K"(9,3,3) AND CROSS
("KDJ.K"(9,3,3),"KDJ.D"(9,3,3));
{KDJ顶背}
C2:=BARSLAST(REF(CROSS("KDJ.D"(9,3,3),"KDJ.K"(9,3,3)),1));
D2:=REF(C,C2+1)<C AND REF("KDJ.K"(9,3,3),C2+1)>"KDJ.K"(9,3,3) AND CROSS
("KDJ.D"(9,3,3),"KDJ.K"(9,3,3));
{KDJ底背信号}
DRAWICON((B2>0),85,41);
DRAWTEXT((B2>0),85,' KDJ底背离'),COLORWHITE;
{KDJ顶背信号}
DRAWICON((D2>0),85,37);
DRAWTEXT((D2>0),85,' KDJ顶背离'),COLORGREEN;
{RSI底背}
A3:=BARSLAST(REF(CROSS("RSI.RSI1"(6,12,24),"RSI.RSI2"(6,12,24)),1));
B3:=REF(C,A3+1)>C AND REF("RSI.RSI1"(6,12,24),A3+1)<"RSI.RSI1"(6,12,24) AND CROSS
("RSI.RSI1"(6,12,24),"RSI.RSI2"(6,12,24));
{RSI顶背}
C3:=BARSLAST(REF(CROSS("RSI.RSI2"(6,12,24),"RSI.RSI1"(6,12,24)),1));
D3:=REF(C,C3+1)<C AND REF("RSI.RSI1"(6,12,24),C3+1)>"RSI.RSI1"(6,12,24) AND CROSS
("RSI.RSI2"(6,12,24),"RSI.RSI1"(6,12,24));
{RSI顶背信号 股票指标网 }
DRAWICON((D3>0),-20,37);
DRAWTEXT((D3>0),-20,' RSI顶背离'),COLORGREEN;
{RSI底背信号}
DRAWICON((B3>0),-20,41);
DRAWTEXT((B3>0),-20,' RSI底背离'),COLORRED;
{KDJ日周共振}
N:=1;
日K:=KDJ.K;
日D:=KDJ.D;
日J:=KDJ.J;
周K:=KDJ.K#WEEK,NODRAW;
周D:=KDJ.D#WEEK,NODRAW;
周J:=KDJ.J#WEEK,NODRAW;
日金叉:=CROSS(日K,日D) AND (日D<40 OR 日D>60);
周金叉:=CROSS(周K,周D) AND (周D<40 OR 周D>60);
{}
共振:=(周金叉 AND 日金叉);
DRAWTEXT((周金叉 AND 日金叉),75,' KDJ日周共振'),COLORYELLOW;
DRAWICON((周金叉 AND 日金叉),75,25);
未来函数检测结果如下:
该公式包含未来函数:#WEEK
解密、编写股票、期货策略请联系QQ或微信同号:88652583
相关股票指标公式
原理解析:
RSV赋值:(收盘价-9日内最低价最低值)/(9日内最高价最高值-9日内最低价最低值)*100
RSV的3日[1日权重]移动平均
K的3日[1日权重]移动平均
J赋值:3*K-2*D
DIFF:=收盘价的12日指数移动平均-收盘价的26日指数移动平均
DEA:=DIFF的9日指数移动平均
MACD赋值:2*(DIFF-DEA)
RSV1:=(9.8日内H最高值-C)/(9.8日内H最高值-9.8日内L最低值)*101
RSV1的3日[1日权重]移动平均
KK的3日[1日权重]移动平均
JJ赋值:3*KK-2*DD
KX:=250
KH:=KX日内K最高值
DH:=KX日内D最高值
JH:=KX日内J最高值
KL:=KX日内K最低值
DL:=KX日内D最低值
JL:=KX日内J最低值
HKMAX:=MAX(KH,MAX(DH,JH))
LKMIN:=MIN(KL,MIN(DL,JL))
KHLB:=(HKMAX+LKMIN)/2
KHLC:=HKMAX-LKMIN
MHF赋值:KX日内DIFF最高值
MHD赋值:KX日内DEA最高值
MHM赋值:KX日内MACD最高值
MLF赋值:KX日内DIFF最低值
MLD赋值:KX日内DEA最低值
MLM赋值:KX日内MACD最低值
HMAX赋值:MAX(MHF,MAX(MHD,MHM))
LMIN赋值:MIN(MLF,MIN(MLD,MLM))
FHLB赋值:(HMAX-LMIN)/100
FHLC赋值:HMAX-LMIN
SH赋值:(0-FHLB)*(KHLC/FHLC)+KHLB
DIFFA:=(DIFF-FHLB)*(KHLC/FHLC)+KHLB
DEAA:=(DEA-FHLB)*(KHLC/FHLC)+KHLB
DRAWBAND(DIFFA,RGB(255,64,64),DEAA,RGB(64,255,64))
MACDA:=(MACD-FHLB)*(KHLC/FHLC)+KHLB
CDA:=MACD<1日前的MACD AND MACD>0
CDB:=MACD>=1日前的MACD AND MACD>0
CDC:=MACD>1日前的MACD AND MACD<0
CDD赋值:MACD<=1日前的MACD AND MACD<0
当满足条件CDA时,在SH和MACDA之间画柱状线
当满足条件CDB时,在SH和MACDA之间画柱状线
当满足条件CDC时,在SH和MACDA之间画柱状线
当满足条件CDD时,在SH和MACDA之间画柱状线
当满足条件BARSTATUS=2时,在SH和' 0轴'位置书写文字
RSV的3日[1日权重]移动平均
KKK的3日[1日权重]移动平均
JJ输出J:3*KKK-2*DDD,画洋红色,LINETHICK2
当满足条件ISLASTBAR时,在KKK和' ←K'位置书写文字
当满足条件ISLASTBAR时,在DDD和' ←D'位置书写文字
当满足条件ISLASTBAR时,在JJJ和' ←J'位置书写文字
{MACD KDJ 金叉.,共振 信号}
A:=DIFF上穿DEA AND KKK上穿DDD AND JJJ上穿DDD
当满足条件A时,在20和25之间画图标
当满足条件A时,在20和' MACD&KDJ金叉.位置书写文字
{低位金叉标识}
低位金叉赋值:DIFF上穿DEA AND DIFF<-0.1
当满足条件低位金叉时,在10和41之间画图标
当满足条件低位金叉时,在10和' MACD低位金叉'位置书写文字
{二次金叉}
JCCOUNT:=COUNT(DIFF上穿DEA,上次DEA>=0距今天数)
二次金叉赋值:DIFF上穿DEA AND DEA<0 AND 统计21日满足JC=2的天数=1
当满足条件二次金叉时,在0和41之间画图标
当满足条件二次金叉时,在0和' MACD二次金叉'位置书写文字
{MACD,KDJ,RSI顶底背离}
{MACD底背}
A1:=上次1日前的DIFF上穿DEA距今天数
B1赋值:A1+1日前的C>C AND A1+1日前的DIFF
{MACD顶背}
C1:=上次1日前的DEA上穿DIFF距今天数
D1:=C1+1日前的CDIFF AND DEA上穿DIFF
{MACD底背信号}
DRAWICON((B1>0),-10,41)
DRAWTEXT((B1>0),-10,' MACD底背离'),COLORRED
{MACD顶背信号}
DRAWICON((D1>0),-10,37)
DRAWTEXT((D1>0),-10,' MACD顶背离'),画绿色
{KDJ底背}
A2:=上次REF(CROSS("KDJ.K"(9,3,3距今天数,"KDJ.D"(9,3,3)),1))
B2赋值:A2+1日前的C>C AND REF("KDJ.K"(9,3,3),A2+1)<"KDJ.K"(9,3,3) AND CROSS
("KDJ.K"(9,3,3),"KDJ.D"(9,3,3))
{KDJ顶背}
C2:=上次REF(CROSS("KDJ.D"(9,3,3距今天数,"KDJ.K"(9,3,3)),1))
D2:=C2+1日前的C"KDJ.K"(9,3,3) AND CROSS
("KDJ.D"(9,3,3),"KDJ.K"(9,3,3))
{KDJ底背信号}
DRAWICON((B2>0),85,41)
DRAWTEXT((B2>0),85,' KDJ底背离'),画白色
{KDJ顶背信号}
DRAWICON((D2>0),85,37)
DRAWTEXT((D2>0),85,' KDJ顶背离'),画绿色
{RSI底背}
A3赋值:上次REF(CROSS("RSI.RSI1"(6,12,24距今天数,"RSI.RSI2"(6,12,24)),1))
B3赋值:A3+1日前的C>C AND REF("RSI.RSI1"(6,12,24),A3+1)<"RSI.RSI1"(6,12,24) AND CROSS
("RSI.RSI1"(6,12,24),"RSI.RSI2"(6,12,24))
{RSI顶背}
C3赋值:上次REF(CROSS("RSI.RSI2"(6,12,24距今天数,"RSI.RSI1"(6,12,24)),1))
D3:=C3+1日前的C"RSI.RSI1"(6,12,24) AND CROSS
("RSI.RSI2"(6,12,24),"RSI.RSI1"(6,12,24))
{RSI顶背信号 股票指标网 }
DRAWICON((D3>0),-20,37)
DRAWTEXT((D3>0),-20,' RSI顶背离'),画绿色
{RSI底背信号}
DRAWICON((B3>0),-20,41)
DRAWTEXT((B3>0),-20,' RSI底背离'),COLORRED
{KDJ日周共振}
N:=1
日K赋值:KDJ.K
日D赋值:KDJ.D
日J赋值:KDJ.J
周K赋值:KDJ.K#WEEK,NODRAW
周D赋值:KDJ.D#WEEK,NODRAW
周J赋值:KDJ.J#WEEK,NODRAW
日金叉赋值:日K上穿日D AND (日D<40 OR 日D>60)
周金叉赋值:周K上穿周D AND (周D<40 OR 周D>60)
{}
共振赋值:(周金叉 AND 日金叉)
DRAWTEXT((周金叉 AND 日金叉),75,' KDJ日周共振'),画黄色
DRAWICON((周金叉 AND 日金叉),75,25)