去评论
彩虹桥投资充电站

MACD指标源码汇总,成功率极高,买卖点提前一目了然!

龙头战法爱好者
2023/11/12 08:20:27

在股市投资中,MACD指标作为一种技术分析的手段,得到了投资者的认知。但如何使用MACD指标,才能使投资收益达到最佳境界,却是知者甚微。在股市操作中。MACD指标在保护投资者利益方面,远超过它发现投资机会的功效。如何巧用MACD指标.在股海中盈利,今天韩薇就给大家讲解。

一、MACD标准背离公式和选股公式

MACD指标,终极指标,也就是MACD指标的背离(背驰),是很精确的买卖点,特别是在一分钟和五分钟上的macd背离,实战效果可以说无出其右。

以下的公式源码是个标准版的MACD背离公式源码,很不错,跟系统默认的macd指标一致,而且标出了背离、金叉等,非常好。

利用此公式的操作方法:

收盘后下载数据(同时下载5分钟数据)--利用MACD背离选股公式按照5、10、15、30、60分钟分别选股--加入自选---实盘择优买入--选股的次级别(当然也包括同级别或最小的一分钟级别)顶背离后短线离场,这样基本可以有赚不赔!

1、 MACD标准背驰公式源码如下:
DIFF:EMA(CLOSE,12)-EMA(CLOSE,27);
DEA:EMA(DIFF,9);
MACD:2*(DIFF-DEA), COLORSTICK,LINETHICK2;
低位金叉:=CROSS(DIFF,DEA) AND DIFF<-0.1;
STICKLINE(低位金叉,0,0.08,6,0),COLORYELLOW;
DRAWTEXT(低位金叉,0.16,' 低位金叉'),COLORWHITE;
JCCOUNT:=COUNT(CROSS(DIFF,DEA),BARSLAST(DEA>=0));
二次金叉:=CROSS(DIFF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1;
STICKLINE(二次金叉,0,0.06,6,0),COLORFF00FF;
DRAWICON(二次金叉,DEA*0.9,1) ;
DRAWTEXT(二次金叉,0.2,' 二次金叉'),COLORYELLOW;
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
底背离:=REF(CLOSE,A1 1)>CLOSE AND DIFF>REF(DIFF,A1 1) AND CROSS(DIFF,DEA);
STICKLINE(底背离,0,0.03,6,0),COLOR00FF00;
底背RAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,LINETHICK4;
DRAWTEXT(底背离,0.12,' 底背离'),COLORFF00FF;
A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
顶背离:=REF(CLOSE,A2 1)DIFF AND CROSS(DEA,DIFF);
顶背RAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,LINETHICK4;
DRAWTEXT(低位金叉 AND 二次金叉 AND 底背离,0.25,'三全项'),COLOR0000FF,LINETHICK2;

2、MACD标准背驰选股公式:
DIFF:=EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD:=2*(DIFF-DEA);
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
底背离:REF(CLOSE,A1 1)>CLOSE AND DIFF>REF(DIFF,A1 1) AND CROSS(DIFF,DEA);

3、MACD标准背驰选股公式:
DIF:=EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:=EMA(DIF,9);
MACD0:=(DIF-DEA)*2;
MJ:=MACD0;
S05:=SUM(MJ,0);
QST:=BARSLAST(MJ<0 AND REF(MJ,1)>0) 1;
QXT:=BARSLAST(MJ>0 AND REF(MJ,1)<0) 1;
S5:=IF(MJ>0,S05-REF(S05,BARSLAST(MJ<0)),S05-REF(S05,BARSLAST(MJ>0)))/10;
ST:=IF(MJ>0,REF(QST,QXT) QXT,REF(QXT,QST) QST);
RS5:=REF(S5,ST);
BC:IF(MJ>0 AND S5<0 AND S5>RS5 AND DEA<0,1,0));

二、MACD多周期(日、周、月)

MACD多周期指标公式:(通达信)

DIF:EMA(CLOSE,10)-EMA(CLOSE,22);
DEA:EMA(DIF,7);
MACDDIF-DEA)*2,COLORSTICK;
DRAWTEXT(CROSS(DIF,DEA),DIF,'☆'),COLORRED;
{DRAWICON(CROSS(DIF,DEA),DIF*1.05,1);
DRAWICON(CROSS(DEA,DIF),DEA*0.90,2);}
月DIF:="MACD.DIF#MONTH"COLOR0080FF;
月DEA:="MACD.DEA#MONTH",COLOR0080FF,LINETHICK2;
周DIF:="MACD.DIF#WEEK"COLORRED;
周DEA:="MACD.DEA#WEEK",COLORRED,LINETHICK2;
日DIF:="MACD.DIF",COLORWHITE;
日DEA:="MACD.DEA",COLORWHITE,LINETHICK2;
日金:IF(CROSS(日DIF,日DEA),0.1,0),COLORYELLOW;
周金:IF(CROSS(周DIF,周DEA),0.125,0),COLORRED;
月金:IF(CROSS(月DIF,月DEA),0.15,0),COLORGREEN;
DRAWICON(周金 AND 日金,-0.1,7);
DRAWICON(周金 AND 月金,-0.15,11);
DRAWICON(日金 AND 月金,-0.1,1);
日死:IF(CROSS(日DEA,日DIF),-0.1,0),COLORYELLOW;
周死:IF(CROSS(周DEA,周DIF),-0.125,0),COLORRED;
月死:IF(CROSS(月DEA,月DIF),-0.15,0),COLORGREEN;
DRAWICON(周死 AND 日死,-0.1,8);
DRAWICON(周死 AND 月死,-0.15,12);
DRAWICON(日死 AND 月死,-0.15,2);



三、二次金叉,二次翻红,DIF下破0轴及0轴附近金叉

(1)二次金叉:

DIFF:=EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD:=2*(DIFF-DEA);
JCCOUNT:=COUNT(CROSS(DIFF,DEA),BARSLAST(DEA>=0));
二次金叉:CROSS(DIFF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1;

(2)二次翻红:

DIFF:=EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD:=2*(DIFF-DEA);
FH1:=REF(MACD,1)FH2:=MACD>=0 AND COUNT(MACD>REF(MACD,1),1)=1;
FH3:=FH1 AND FH2 AND EMA(C,13)>REF(EMA(C,13),1);
FH4:=FH1 AND FH2 AND ABS((DIFF-DEA)/C)<0.018;
FH5:=FH1 AND FH2 AND MACD<0.10;
FH3 OR FH4 OR FH5;

(3)DIF下破0轴:

DIFF:=EMA(CLOSE,12)-EMA(CLOSE,26);

DEA:=EMA(DIFF,9);

MACD:=2*(DIFF-DEA);

均线向上:=EMA(C,144)>=REF(EMA(C,144),1) AND EMA(C,233)>=REF(EMA(C,233),1);

破0轴:均线向上 AND REF(DIFF,1)>0 AND DIFF<0;

(4)0轴附近金叉(特别是0轴之上):

DIF:=EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:=EMA(DIF,9),LINETHICK1;
CROSS(DIF,DEA) AND DEA>-0.05;

四、MACD空中加油

其中参数P1的含义:MACD 0轴之上至当前交易日的天数内曾发生过死叉
P2含义: MACD 0轴之上几日内已发生金叉.
即将发生金叉的条件为:
DIFF在DEA之下, DEA-DIFF小于等于0.05, 且DEA与DIFF差值比前一交易周期小. (这种情况可以关注,有利于激进的朋友提前介入)

N1:="MACD.DIFF"(12,26,9);
N2:="MACD.DEA"(12,26,9);
M1:=COUNT(CROSS(N2,N1),P1)>=1;
M2:=(COUNT(CROSS(N1,N2),P2)>=1 OR (N2-N1>=0 AND N2-N1<=0.05 AND N2-N1M3:=COUNT(N1>=0,P1)=P1;
M1 AND M2 AND M3;



五、MACD双回试选出4连板牛股

{MACD双回试选股-通达信V2.1 SDCCN}

DIF:=EMA(CLOSE,12)-EMA(CLOSE,26);

DEA:=EMA(DIF,9);

MACD:=(DIF-DEA)*2;

A1:=BARSLAST(REF(CROSS(DIF,DEA),1));

DIF多头发散:=DIF/REF(DIF,1)>1.03 AND DIF>0;

N:=4;

DIF1:=EMA(CLOSE,12*N)-EMA(CLOSE,26*N);

DIF1多头发散:=DIF1/REF(DIF1,1)>1.03 AND DIF1>0;

量价关系:=C>REF(C,1) AND VOL/REF(VOL,1)>2;

XUANGU:A1>=5 AND A1<=13 AND CROSS(DIF,DEA) AND DIF多头发散 AND DIF1多头发散 AND 量价关系;

说明:近日符合MACD双回试选股的股票越来越多,V2.1版增加了量价关系限制条件。



六、MACD5分 15分 30分 60分跨周期在同一图表看盘







使用【MACD】5分 15分 30分 60分跨周期在同一图表看盘,做T和做短,使你更清楚自己要做什麽。体验60分与30分如图
{MACD 5分}
分DIFF:="MACD.DIF#MIN5"(10,22,7.5);
分DEAF:="MACD.DEA#MIN5"(10,22,7.5);
MACD分:2*(分DIFF-分DEAF),NODRAW;
DRAWBAND(分DIFF,RGB(255,157,255),分DEAF,RGB(21,138,255));
STICKLINE(MACD分>0,0,MACD分,0.01,0) ,COLOR0000FF;
STICKLINE(MACD分<0,0,MACD分,0.01,0) ,COLORFFF000;
GMB:IF(CROSS(分DIFF,分DEAF) AND 分DIFF>0,-0.02,DRAWNULL),CROSSDOT,LINETHICK3,COLOR0000FF;
GMC:IF(CROSS(分DIFF,分DEAF) AND 分DIFF<0,-0.02,DRAWNULL),CROSSDOT,LINETHICK3,COLOR208FFF;
0,COLORFFFF00,LINETHICK1;

{MACD 15分}
分DIFF:="MACD.DIF#MIN15"(10,22,7.5);
分DEAF:="MACD.DEA#MIN15"(10,22,7.5);
MACD分:2*(分DIFF-分DEAF),NODRAW;
DRAWBAND(分DIFF,RGB(255,157,255),分DEAF,RGB(21,138,255));
STICKLINE(MACD分>0,0,MACD分,0.01,0) ,COLOR0000FF;
STICKLINE(MACD分<0,0,MACD分,0.01,0) ,COLORFFF000;
GMB:IF(CROSS(分DIFF,分DEAF) AND 分DIFF>0,-0.02,DRAWNULL),CROSSDOT,LINETHICK3,COLOR0000FF;
GMC:IF(CROSS(分DIFF,分DEAF) AND 分DIFF<0,-0.02,DRAWNULL),CROSSDOT,LINETHICK3,COLOR208FFF;
0,COLORFFFF00,LINETHICK1;

{MACD 30分}
分DIFF:="MACD.DIF#MIN30"(10,22,7.5);
分DEAF:="MACD.DEA#MIN30"(10,22,7.5);
MACD分:2*(分DIFF-分DEAF),NODRAW;
DRAWBAND(分DIFF,RGB(255,157,255),分DEAF,RGB(21,138,255));
STICKLINE(MACD分>0,0,MACD分,0.01,0) ,COLOR0000FF;
STICKLINE(MACD分<0,0,MACD分,0.01,0) ,COLORFFF000;
GMB:IF(CROSS(分DIFF,分DEAF) AND 分DIFF>0,-0.02,DRAWNULL),CROSSDOT,LINETHICK3,COLOR0000FF;
GMC:IF(CROSS(分DIFF,分DEAF) AND 分DIFF<0,-0.02,DRAWNULL),CROSSDOT,LINETHICK3,COLOR208FFF;
0,COLORFFFF00,LINETHICK1;

{MACD 60分}
分DIFF:="MACD.DIF#MIN60"(10,22,7.5);
分DEAF:="MACD.DEA#MIN60"(10,22,7.5);
MACD分:2*(分DIFF-分DEAF),NODRAW;
DRAWBAND(分DIFF,RGB(255,157,255),分DEAF,RGB(21,138,255));
STICKLINE(MACD分>0,0,MACD分,0.01,0) ,COLOR0000FF;
STICKLINE(MACD分<0,0,MACD分,0.01,0) ,COLORFFF000;
GMB:IF(CROSS(分DIFF,分DEAF) AND 分DIFF>0,-0.02,DRAWNULL),CROSSDOT,LINETHICK3,COLOR0000FF;
GMC:IF(CROSS(分DIFF,分DEAF) AND 分DIFF<0,-0.02,DRAWNULL),CROSSDOT,LINETHICK3,COLOR208FFF;
0,COLORFFFF00,LINETHICK1;









也可下载下面的文件复制到“tdx_level2T0002pad”的文件夹中,这是做好的,公式是主图
公式源码:
QWX1:=HHV(CLOSE,30);
QWX2:=LLV(CLOSE,30);
QWX3:=CONST((QWX1+QWX2)/2);

DIFFEMA(CLOSE,10) - EMA(CLOSE,22))*60+QWX3,NODRAW;
DEA :EMA(DIFF,7.5),NODRAW;
MACD :2*(DIFF-DEA)+QWX3,NODRAW;
DRAWBAND(DIFF,RGB(255,157,255),DEA,RGB(21,138,255));
STICKLINE(MACD>0+QWX3,0+QWX3,MACD,0.2,0) ,COLOR0000FF;
STICKLINE(MACD<0+QWX3,0+QWX3,MACD,0.2,0) ,COLORFFF000;
趋势:=((5)*(SMA(((CLOSE-LLV(LOW,27))/(HHV(HIGH,27)-LLV(LOW,27)))*(100),5,1))-(3)*(SMA(SMA(((CLOSE-LLV(LOW,27))/(HHV(HIGH,27)-LLV(LOW,27)))*(100),5,1),3,1))-SMA(SMA(SMA(((CLOSE-LLV(LOW,27))/(HHV(HIGH,27)-LLV(LOW,27)))*(100),5,1),3,1),2,1))*60+QWX3;
STICKLINE(趋势<=5*60+QWX3,0+QWX3,MACD,0.2,0) ,COLOR00FFFF;
0+QWX3,COLORFFFF00,LINETHICK1;
DRAWICON(CROSS(DEA,DIFF) AND DIFF>0+QWX3,DEA,2);
DRAWICON(CROSS(DIFF,DEA) AND DIFF<0+QWX3,DEA,1);

笔者公众平台:k603000(李韩薇)

  • 鍏嶈垂鎸囨爣鍒嗕韩銆愮簿鍝佹寚鏍囥戞捣楸间箣閲戜紭鍖栫増鈥斺旂ǔ瀹氬彲闈犵殑
  • 鍏嶈垂鎸囨爣鍒嗕韩閫氳揪淇°愭父璧勯噾榫欑獊鐮淬戜富鍥炬寚鏍 锛屽姪浣犺偂
  • 鍏嶈垂鎸囨爣鍒嗕韩閫氳揪淇°愰緳鑸熸姄榫欍 鎵嬫満鐢佃剳閫氱敤鍓夋寚鏍
  • 鍏嶈垂鎸囨爣鍒嗕韩閫氳揪淇♀滄瀬闄愭礂鐩樷濆壇鍥炬寚鏍囬夎偂鍏紡--鍚姩
  • 鍏嶈垂鎸囨爣鍒嗕韩0729|鈥嬧嬧嬧嬮氳揪淇¢珮鑳滅巼銆愮珵浠疯繛鏉挎墦濡
  • 鍏嶈垂鎸囨爣鍒嗕韩鍛ㄦ湯绂忓埄閾佹爲寮鑺辫繘鍑荤増鎸囨爣婧愮爜涓诲浘闄勫浘閫