龙听期货论坛's Archiver

C
+
+


 微信: QQ:

龙听 发表于 2014-2-16 23:41

MACD背离模型

[b][size=2][color=#666666]**** Hidden Message *****[/color][/size][/b]
[attach]1017[/attach][/p]

朵朵爸 发表于 2015-9-7 23:10

请问有完整的公式吗?

龙听 发表于 2016-6-15 15:09

通达信源码:
[code]DIFF:EMA(CLOSE,12)-EMA(CLOSE,27);
DEA:EMA(DIFF,9);
MACD:=2*(DIFF-DEA);
STICKLINE(MACD>=0,MACD,0,2,1),COLORF00FF0;
STICKLINE(MACD<0,MACD,0,2,1),COLORWHITE;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00AAFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00BBFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00CCFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00DDFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00EEFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00FFFF;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0000AA;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0011BB;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0022CC;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0033DD;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0044EE;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0055FF;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORAA00BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORBB11BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORCC22BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORDD33BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLOREE44BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFF55BB;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFAA00;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFBB11;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFCC22;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFDD33;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFEE44;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFFF55;
IF(DIFF<0,DIFF,0),COLORRED,LINETHICK1;
IF(DIFF<0,0,DIFF),COLORYELLOW,LINETHICK1;
IF(DIFF<DEA,DIFF,DEA),COLOR00FF00,LINETHICK1;
IF(DIFF>DEA,DEA,DEA),COLORWHITE,LINETHICK1;
低位金叉:=CROSS(DIFF,DEA) AND DIFF<-0.1;
STICKLINE(低位金叉,0,-0.18,2,0),COLORYELLOW;
DRAWTEXT(低位金叉,-0.1,' 低位金叉'),COLORYELLOW;
JCCOUNT:=COUNT(CROSS(DIFF,DEA),BARSLAST(DEA>=0));
二次金叉:=CROSS(DIFF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1;
STICKLINE(二次金叉,0,-0.18,2,0),COLORFF00FF;
DRAWICON(二次金叉,DEA*1.04,13) ;
DRAWTEXT(二次金叉,-0.1,' 二次金叉'),COLORFF00FF;
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.13,2,0),COLOR00FF00;
DRAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,LINETHICK2;
DRAWTEXT(底背离,0.1,' 底背离'),COLOR00FF00;
A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIFF,A2+1)>DIFF AND CROSS(DEA,DIFF);
DRAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,LINETHICK2;
[/code]

龙听 发表于 2016-6-15 15:13

优化后的MACD背离形态,注意这里是通达信软件上面的指标,不是程序化交易:
[code]
DIFF:EMA(CLOSE,12)-EMA(CLOSE,27);
DEA:EMA(DIFF,9);
MACD:=2*(DIFF-DEA);
STICKLINE(MACD>=0,MACD,0,2,1),COLORF00FF0;
STICKLINE(MACD<0,MACD,0,2,1),COLORWHITE;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00AAFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00BBFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00CCFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00DDFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00EEFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00FFFF;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0000AA;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0011BB;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0022CC;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0033DD;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0044EE;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0055FF;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORAA00BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORBB11BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORCC22BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORDD33BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLOREE44BB;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFF55BB;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFAA00;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFBB11;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFCC22;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFDD33;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFEE44;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFFF55;
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.13,2,0),COLOR00FF00;
DRAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,LINETHICK2;
DRAWTEXT(底背离,0.5*DEA,' 底背离'),COLOR00FF00;
A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIFF,A2+1)>DIFF AND CROSS(DEA,DIFF);
STICKLINE(顶背离,0,0.13,2,0),COLOR00FF00;
DRAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,LINETHICK2;
DRAWTEXT(顶背离,0.5*DEA,'顶背离'),COLOR00FF00;[/code]

龙听 发表于 2016-6-15 16:35

博易大师上面的源码:
[code]
DIFF:EMA(CLOSE,12)- EMA(CLOSE,27);
DEA:EMA(DIFF,9);
MACD:= 2*(DIFF-DEA);
STICKLINE(MACD>=0,MACD,0,2,1),COLORF00FF0;
STICKLINE(MACD<0,MACD,0,2,1),COLORWHITE;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,5,0 ),COLOR00AAFF;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,5,0 ),COLOR00BBFF;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,5,0 ),COLOR0000AA;
STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,5,0 ),COLOR0011BB;
STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,5,0 ),COLORAA00BB;
STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,5,0 ),COLORFFAA00;
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
底背离:=REF(CLOSE,A1+1) > CLOSE AND REF(DIFF,A1+1) < DIFF AND CROSS(DIFF,DEA);
STICKLINE(底背离,0,13,2,0),COLOR00FF00;
DRAWTEXT(底背离,DEA+20,' 底背离'),COLOR00FF00;
A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
顶背离:=REF(CLOSE,A2+1) < CLOSE AND REF(DIFF,A2+1) > DIFF AND CROSS(DEA,DIFF);
STICKLINE(顶背离,0,-13,2,0),COLOR00FF00;
DRAWTEXT(顶背离,DEA-20,' 顶背离'),COLOR00FF00;
[/code]


这里面有一个问题,就是画线的问题,博易大师上面能找到两个金叉的位置同时提醒说是顶背离或底背离了,但是不能在两个金叉或死叉之间画线。这个通达信功能上面是有的,所以我感觉博易大师是史移植了通达信的部分功能,再就是跟周期功能博易大师也实现不了,总之博易大师你就只能当做一个看行情的软件好了,别想多了就好。

龙听 发表于 2016-6-15 17:10

文华财经:[code]
DIFF:EMA(CLOSE,12)-EMA(CLOSE,27);
DEA:EMA(DIFF,9);
MACD:=2*(DIFF-DEA);
STICKLINE(MACD>=0,MACD,0,2,1),COLORF00FF0;
STICKLINE(MACD<0,MACD,0,2,1),COLORWHITE;
STICKLINE(MACD<REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR00AAFF;
STICKLINE(MACD<REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR00BBFF;
STICKLINE(MACD<REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR00CCFF;
STICKLINE(MACD<REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR00DDFF;
STICKLINE(MACD<REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR00EEFF;
STICKLINE(MACD<REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR00FFFF;
STICKLINE(MACD>=REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR0000AA;
STICKLINE(MACD>=REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR0011BB;
STICKLINE(MACD>=REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR0022CC;
STICKLINE(MACD>=REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR0033DD;
STICKLINE(MACD>=REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR0044EE;
STICKLINE(MACD>=REF(MACD,1) AND MACD>0,0,MACD,2,0 ),COLOR0055FF;
STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORAA00BB;
STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORBB11BB;
STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORCC22BB;
STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORDD33BB;
STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLOREE44BB;
STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORFF55BB;
STICKLINE(MACD<=REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORFFAA00;
STICKLINE(MACD<=REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORFFBB11;
STICKLINE(MACD<=REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORFFCC22;
STICKLINE(MACD<=REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORFFDD33;
STICKLINE(MACD<=REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORFFEE44;
STICKLINE(MACD<=REF(MACD,1) AND MACD<0,0,MACD,2,0 ),COLORFFFF55;
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.5*DEA,2,1),COLORRED;
DRAWTEXT(底背离,0.5*DIFF,' 底背离'),COLORRED;
A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIFF,A2+1)>DIFF AND CROSS(DEA,DIFF);
STICKLINE(顶背离,0,0.5*DEA,2,1),COLORGREEN;
DRAWTEXT(顶背离,0.5*DEA,'顶背离'),COLORGREEN;

//上面是MACD背离源码

//下面是MACD共振源码[/code]

龙听 发表于 2016-6-15 17:11

[attach]1138[/attach]

妙妙强 发表于 2021-6-9 14:23

谢谢分享

坦克 发表于 2021-6-14 10:08

谢谢楼主的无私奉献

周军 发表于 2021-6-16 14:55

dddd

言程序 发表于 2021-7-9 11:24

学学

枫叶潇潇 发表于 2021-9-16 23:07

我wwwwwwwwwwwwwww

页: [1]