HY黄金MACD通达信公式 副图 源码附图
DI1F:=(EMA(CLOSE,12) - EMA(CLOSE,26));
DE1A:=EMA(DI1F,9);
MACD:(2 * (DI1F - DE1A)),NODRAW,COLORFF8000;
0;
STICKLINE(MACD<REF(MACD,1) AND MACD>0,0,MACD,3,1),COLOR0080FF,LINETHICK2;
STICKLINE(MACD>=REF(MACD,1) AND MACD>0,0,MACD,3,1),COLOR0000FF,LINETHICK2;
STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,3,1),COLORFF8000,LINETHICK2;
STICKLINE(MACD<=REF(MACD,1) AND MACD<0,0,MACD,3,1),COLORFFFF00,LINETHICK2;
DIF:(EMA(CLOSE,12) - EMA(CLOSE,26)),COLORFFFFFF;
DEA:EMA(DIF,9),COLOR00FFFF;
{ 以下是可能出现的变盘点,关注 }
TJ:=MACD>0;
T:=MACD<0;
DRAWTEXT(BARSLAST(TJ)=5,0.03,'5'),COLORYELLOW;
DRAWTEXT(BARSLAST(TJ)=8,0.03,'8'),COLORYELLOW;
DRAWTEXT(BARSLAST(TJ)=13,0.03,'13'),COLORYELLOW;
DRAWTEXT(BARSLAST(TJ)=21,0.03,'21'),COLORYELLOW;
DRAWTEXT(BARSLAST(TJ)=34,0.03,'34'),COLORYELLOW;
DRAWTEXT(BARSLAST(TJ)=55,0.03,'55'),COLORYELLOW;
DRAWTEXT(BARSLAST(T)=5,-0.03,'5'),COLORGREEN;
DRAWTEXT(BARSLAST(T)=8,-0.03,'8'),COLORGREEN;
DRAWTEXT(BARSLAST(T)=13,-0.03,'13'),COLORGREEN;
DRAWTEXT(BARSLAST(T)=21,-0.03,'21'),COLORGREEN;
DRAWTEXT(BARSLAST(T)=34,-0.03,'34'),COLORGREEN;
DRAWTEXT(BARSLAST(T)=55,-0.03,'55'),COLORGREEN;
ZSJR4:=CROSS(DIF,0);
ZSJR5:=CROSS(0,DIF);
ZSJR6:=BARSLAST(ZSJR4);
ZSJR7:=BARSLAST(ZSJR5);
ZSJR8:=REF(ZSJR4,1);
ZSJR9:=REF(ZSJR5,1);
DIF0:=BARSLAST(ZSJR8);
DIF1:=BARSLAST(ZSJR9);
DIF2:=IF((DIF0 < DIF1),REF(HHV(HIGH,2),DIF0),REF(LLV(LOW,2),DIF1));
DIF3:=(((REF(CLOSE,1) <= REF(DIF2,1)) AND (CLOSE > DIF2)) AND (ZSJR6 < ZSJR7));
DIF33:=(((REF(CLOSE,1) >= REF(DIF2,1)) AND (CLOSE < DIF2)) AND (ZSJR7 < ZSJR6));
DIF4:=(DIF3 AND (COUNT(DIF3,ZSJR6) = 1));
DIF5:=(DIF33 AND (COUNT(DIF33,ZSJR7) = 1));
DIF6:=(DIF4 AND (REF(BARSLAST(DIF5),1) < REF(BARSLAST(DIF4),1)));
DIF7:=(DIF5 AND (REF(BARSLAST(DIF5),1) > REF(BARSLAST(DIF4),1)));
DIF8:=(DIF4 AND (REF(BARSLAST(DIF5),1) > REF(BARSLAST(DIF4),1)));
DIF9:=(DIF5 AND (REF(BARSLAST(DIF5),1) < REF(BARSLAST(DIF4),1)));
BSLINE:=IF((BARSLAST(DIF6) < BARSLAST(DIF7)),IF(REF(CROSS(0,MACD),1),LLV(LOW,2),REF(LLV(LOW,2),BARSLAST(REF(CROSS(0,MACD),1)))),IF(REF(CROSS(MACD,0),1),HHV(HIGH,2),REF(HHV(HIGH,2),BARSLAST(REF(CROSS(MACD,0),1)))));
DEA3:=BARSLAST(CROSS(MACD,0));
DEA5:=BARSLAST(CROSS(0,MACD));
DEA4:=IF((MACD >= 0),HHV(MACD,(DEA3 + 1)),REF(HHV(MACD,(DEA3 + 1)),(DEA5 + 1)));
DEA6:=IF((MACD < 0),LLV(MACD,(DEA5 + 1)),REF(LLV(MACD,(DEA5 + 1)),(DEA3 + 1)));
DEA7:=REF(DEA4,(DEA3 + 1));
DEA8:=REF(DEA6,(DEA5 + 1));
零下金叉:CROSS(DIF,DEA) AND DIF<0,NODRAW,COLOR0000FF;
零上金叉:CROSS(DIF,DEA) AND DIF>=0 AND DIF<0.25 ,NODRAW,COLOR4080FF;
DRAWICON(零上金叉,DEA,1) ;
DRAWICON(零下金叉,DEA,1) ;
JCCOUNT:=COUNT(CROSS(DIF,DEA),BARSLAST(DEA>=0));
二次金叉:CROSS(DIF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1,NODRAW,COLOR00FFFF;
DRAWTEXT(二次金叉,DEA*0.4,'★二金'),COLORYELLOW;
A1:=BARSLAST(REF(CROSS(DIF,DEA),1));
上次成立:=BARSLAST(REF(CROSS(DIF,DEA),1));
上次最低价:=REF(LLV(LOW,8),上次成立+1);
本次成立:=BARSLAST(CROSS(DIF,DEA));
本次最低价:=REF(LLV(LOW,8),本次成立);
底背离:=上次最低价>本次最低价 AND DIF>REF(DIF,A1+1) AND CROSS(DIF,DEA);
{底背离:=REF(CLOSE,A1+1)>CLOSE AND DIF>REF(DIF,A1+1) AND CROSS(DIF,DEA);}
{STICKLINE(底背离,-0.2,-0.3,6,1),COLOR00FF00;}
底背:DRAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,POINTDOT;
DRAWTEXT(底背离,DEA*0.6,'底背离'),COLORRED;
A2:=BARSLAST(REF(CROSS(DEA,DIF),1));
顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIF,A2+1)>DIF AND CROSS(DEA,DIF);
顶背:DRAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,POINTDOT;
DRAWTEXT(顶背离,DEA*1.3,'顶背离'),COLORGREEN;
DRAWTEXT(零下金叉 AND 二次金叉 AND 底背离,DIF*-1,'★底现★'),COLORFFFFFF;
H1J_19:=HHVBARS(MACD,BARSLAST(MACD<0)+1);
H1J_20:=CROSS(BACKSET(CROSS(0,MACD),REF(H1J_19,1)+2),0.5);
H1J_22:=DRAWLINE(H1J_20,MACD,REF(H1J_20,1),REF(MACD,1),1);
H1J_23:=LLVBARS(MACD,BARSLAST(MACD>0)+1);
H1J_24:=CROSS(BACKSET(CROSS(MACD,0),REF(H1J_23,1)+2),0.5);
H1J_25:=BARSLAST(FILTERX(CROSS(0,MACD),BARSCOUNT(CLOSE)));
H1J_26:=DRAWLINE(H1J_24,MACD,REF(H1J_24,1),REF(MACD,1),1);
MACD0:=BACKSET(ISLASTBAR,BARSLAST(H1J_20)+1);
MACD1:=MACD0>REF(MACD0,1);
前1高:REF(MACD,BARSLAST(MACD1)),COLORYELLOW,LINETHICK2;
STICKLINE(MACD>H1J_22,MACD,H1J_22,1,0),COLORYELLOW;
STICKLINE(MACD<0 AND MACD<H1J_26 AND H1J_26<0,MACD,H1J_26,1,0),COLORFFFFFF;
H7:=BARSLASTCOUNT(DIF>DEA );
DRAWNUMBER(ISLASTBAR,0,H7),COLORFFFFFF,LINETHICK9;
IF(DIF>REF(DIF,1),DIF,DRAWNULL),COLORRED;
STICKLINE(DIF<0 AND CROSS(DIF,DEA),DEA,0,0,0),COLORRED;
STICKLINE(DIF>0 AND CROSS(DEA,DIF),DEA,0,0,0),COLORGREEN;
STICKLINE(DIF<0 AND CROSS(DIF,DEA),DEA,0,0,0),COLORRED;
STICKLINE(DIF>0 AND CROSS(DEA,DIF),DEA,0,0,0),COLORGREEN;
DRAWTEXT(DIF<0 AND CROSS(DIF,DEA),DEA/2,'———————————');
DRAWTEXT(DIF>0 AND CROSS(DEA,DIF),DEA/2,'———————————');
DRAWTEXT_FIX(1,0.980,20,1,'★股票指标网'),COLOR666666;
X_21:=MACD.DIF#WEEK(12,26,9);
X_22:=MACD.DEA#WEEK(12,26,9);
X_23:=MACD.MACD#WEEK(12,26,9);
X_24:=CROSS(X_21,X_22);
0,COLOR00FF00;
IF(X_23>0,0,DRAWNULL),COLOR0000FF;
DRAWTEXT(X_24,DIF/2*-1,'周金叉'),COLORFF00FF;
DRAWTEXT(CROSS(X_22,X_21),DIF/2*-1,'周死叉'),COLORFFFF00;
未来函数检测结果如下:
该公式包含未来函数:BACKSET
该公式包含未来函数:#WEEK
解密、编写股票、期货策略请联系QQ或微信同号:88652583
相关股票指标公式
原理解析:
DI1F赋值:(收盘价的12日指数移动平均 - 收盘价的26日指数移动平均)
DE1A赋值:DI1F的9日指数移动平均
输出MACD:(2 * (DI1F - DE1A)),NODRAW,COLORFF8000
0
STICKLINE(MACD<1日前的MACD AND MACD>0,0,MACD,3,1),COLOR0080FF,LINETHICK2
STICKLINE(MACD>=1日前的MACD AND MACD>0,0,MACD,3,1),COLOR0000FF,LINETHICK2
STICKLINE(MACD>1日前的MACD AND MACD<0,0,MACD,3,1),COLORFF8000,LINETHICK2
STICKLINE(MACD<=1日前的MACD AND MACD<0,0,MACD,3,1),COLORFFFF00,LINETHICK2
输出DIF:(收盘价的12日指数移动平均 - 收盘价的26日指数移动平均),COLORFFFFFF
输出DEA:DIF的9日指数移动平均,COLOR00FFFF
{ 以下是可能出现的变盘点,关注 }
TJ赋值:MACD>0
T赋值:MACD<0
DRAWTEXT(上次TJ距今天数=5,0.03,'5'),画黄色
DRAWTEXT(上次TJ距今天数=8,0.03,'8'),画黄色
DRAWTEXT(上次TJ距今天数=13,0.03,'13'),画黄色
DRAWTEXT(上次TJ距今天数=21,0.03,'21'),画黄色
DRAWTEXT(上次TJ距今天数=34,0.03,'34'),画黄色
DRAWTEXT(上次TJ距今天数=55,0.03,'55'),画黄色
DRAWTEXT(上次T距今天数=5,-0.03,'5'),画绿色
DRAWTEXT(上次T距今天数=8,-0.03,'8'),画绿色
DRAWTEXT(上次T距今天数=13,-0.03,'13'),画绿色
DRAWTEXT(上次T距今天数=21,-0.03,'21'),画绿色
DRAWTEXT(上次T距今天数=34,-0.03,'34'),画绿色
DRAWTEXT(上次T距今天数=55,-0.03,'55'),画绿色
ZSJR4赋值:DIF上穿0
ZSJR5赋值:0上穿DIF
ZSJR6赋值:上次ZSJR4距今天数
ZSJR7赋值:上次ZSJR5距今天数
ZSJR8赋值:1日前的ZSJR4
ZSJR9赋值:1日前的ZSJR5
DIF0:=上次ZSJR8距今天数
DIF1:=上次ZSJR9距今天数
DIF2:=IF((DIF0 < DIF1),REF(2日内最高价最高值,DIF0),REF(2日内最低价最低值,DIF1))
DIF3:=(((1日前的收盘价 <= 1日前的DIF2) AND (收盘价 > DIF2)) AND (ZSJR6 < ZSJR7))
DIF33:=(((1日前的收盘价 >= 1日前的DIF2) AND (收盘价 < DIF2)) AND (ZSJR7 < ZSJR6))
DIF4:=(DIF3 AND (统计ZSJR6日满足DIF3的天数 = 1))
DIF5:=(DIF33 AND (统计ZSJR7日满足DIF33的天数 = 1))
DIF6:=(DIF4 AND (REF(上次DIF5距今天数,1) < REF(BARSLAST(DIF4),1)))
DIF7:=(DIF5 AND (REF(上次DIF5距今天数,1) > REF(BARSLAST(DIF4),1)))
DIF8:=(DIF4 AND (REF(上次DIF5距今天数,1) > REF(BARSLAST(DIF4),1)))
DIF9:=(DIF5 AND (REF(上次DIF5距今天数,1) < REF(BARSLAST(DIF4),1)))
BSLINE赋值:IF((上次DIF6距今天数 < BARSLAST(DIF7)),IF(1日前的0上穿MACD,2日内最低价最低值,REF(2日内最低价最低值,BARSLAST(1日前的0上穿MACD))),IF(REF(MACD上穿0,1),2日内最高价最高值,REF(2日内最高价最高值,BARSLAST(REF(MACD上穿0,1)))))
DEA3:=上次MACD上穿0距今天数
DEA5:=上次0上穿MACD距今天数
DEA4:=IF((MACD >= 0),HHV(MACD,(DEA3 + 1)),REF(HHV(MACD,(DEA3 + 1)),(DEA5 + 1)))
DEA6:=IF((MACD < 0),LLV(MACD,(DEA5 + 1)),REF(LLV(MACD,(DEA5 + 1)),(DEA3 + 1)))
DEA7:=REF(DEA4,(DEA3 + 1))
DEA8:=REF(DEA6,(DEA5 + 1))
输出零下金叉:DIF上穿DEA AND DIF<0,NODRAW,COLOR0000FF
输出零上金叉:DIF上穿DEA AND DIF>=0 AND DIF<0.25 ,NODRAW,COLOR4080FF
当满足条件零上金叉时,在DEA和1之间画图标
当满足条件零下金叉时,在DEA和1之间画图标
JCCOUNT赋值:COUNT(DIF上穿DEA,上次DEA>=0距今天数)
输出二次金叉:DIF上穿DEA AND DEA<0 AND 统计21日满足JC=2的天数=1,NODRAW,COLOR00FFFF
当满足条件二次金叉时,在DEA*0.4和'★二金'位置书写文字
A1赋值:上次1日前的DIF上穿DEA距今天数
上次成立赋值:上次1日前的DIF上穿DEA距今天数
上次最低价赋值:REF(8日内最低价最低值,上次成立+1)
本次成立赋值:上次DIF上穿DEA距今天数
本次最低价赋值:REF(8日内最低价最低值,本次成立)
底背离赋值:上次最低价>本次最低价 AND DIF>A1+1日前的DIF AND DIF上穿DEA
{底背离赋值:A1+1日前的收盘价>收盘价 AND DIF>A1+1日前的DIF AND DIF上穿DEA
当满足条件底背离时,在-0.2和-0.3之间画柱状线
输出}
底背:DRAWLINE(A1=0,DEA,底背离,DEA,0),画红色,POINTDOT
当满足条件底背离时,在DEA*0.6和'底背离'位置书写文字
A2赋值:上次1日前的DEA上穿DIF距今天数
顶背离赋值:A2+1日前的收盘价<收盘价 AND A2+1日前的DIF>DIF AND DEA上穿DIF
输出顶背:DRAWLINE(A2=0,DEA,顶背离,DEA,0),画绿色,POINTDOT
当满足条件顶背离时,在DEA*1.3和'顶背离'位置书写文字
当满足条件零下金叉 AND 二次金叉 AND 底背离时,在DIF*-1和'★底现★'位置书写文字
H1J_19赋值:HHVBARS(MACD,上次MACD<0距今天数+1)
H1J_20赋值:CROSS(BACKSET(CROSS(0,MACD),1日前的H1J_19+2),0.5)
H1J_22赋值:DRAWLINE(H1J_20,MACD,1日前的H1J_20,1日前的MACD,1)
H1J_23赋值:LLVBARS(MACD,上次MACD>0距今天数+1)
H1J_24赋值:CROSS(BACKSET(CROSS(MACD,0),1日前的H1J_23+2),0.5)
H1J_25赋值:上次FILTERX(0上穿MACD,收盘价的有效数据周期数距今天数)
H1J_26赋值:DRAWLINE(H1J_24,MACD,1日前的H1J_24,1日前的MACD,1)
MACD0:=BACKSET(ISLASTBAR,上次H1J_20距今天数+1)
MACD1:=MACD0>1日前的MACD0
输出前1高:REF(MACD,上次MACD1距今天数),画黄色,LINETHICK2
当满足条件MACD>H1J_22时,在MACD和H1J_22之间画柱状线
当满足条件MACD<0 AND MACD
H7赋值:BARSLASTCOUNT(DIF>DEA )
DRAWNUMBER(ISLASTBAR,0,H7),COLORFFFFFF,LINETHICK9
IF(DIF>1日前的DIF,DIF,DRAWNULL),画红色
STICKLINE(DIF<0 AND DIF上穿DEA,DEA,0,0,0),画红色
STICKLINE(DIF>0 AND DEA上穿DIF,DEA,0,0,0),画绿色
STICKLINE(DIF<0 AND DIF上穿DEA,DEA,0,0,0),画红色
STICKLINE(DIF>0 AND DEA上穿DIF,DEA,0,0,0),画绿色
DRAWTEXT(DIF<0 AND DIF上穿DEA,DEA/2,'———————————')
DRAWTEXT(DIF>0 AND DEA上穿DIF,DEA/2,'———————————')
当满足条件1时,在横轴0.980纵轴20位置书写文字
X_21赋值:MACD.DIF#WEEK(12,26,9)
X_22赋值:MACD.DEA#WEEK(12,26,9)
X_23赋值:MACD.MACD#WEEK(12,26,9)
X_24赋值:X_21上穿X_22
0,COLOR00FF00
如果X_23>0返回0否则返回DRAWNULL
当满足条件X_24时,在DIF/2*-1和'周金叉'位置书写文字
DRAWTEXT(X_22上穿X_21,DIF/2*-1,'周死叉'),COLORFFFF00