飞啊飞 发表于 2010-3-12 08:16

macd顶底背离交易系统(有未来函数,不喜欢的不要用),仅供参考

input:s(12,1,100),p(26,1,100),m(9,1,100);
DIFF:=EMA(CLOSE,s)-EMA(CLOSE,p);
DEA:=EMA(DIFF,m);
MACD:=2*(DIFF-DEA);
A1:=BARSLAST(CROSS(DEA,DIFF));
A2:=llvbars(diff,A1);
A3:=barslast(A2=1);
A4:=ref(A3,1)+2;
llA1:=min(min(l,ref(l,1)),ref(l,2));
llA2:=min(min(ref(l,A4-1),ref(l,A4)),ref(l,A4+1));
diffA1:=min(min(diff,ref(diff,1)),ref(diff,2));
diffA2:=min(min(ref(diff,A4-1),ref(diff,A4)),ref(diff,A4+1));
背离A:=llA1<llA2 and diffA1>diffA2 and count(cross(dea,diff),A4)=1;
S1:=BARSLAST(CROSS(DIFF ,DEA));
S2:=hhvbars(diff,S1);
S3:=barslast(S2=1);
S4:=ref(S3,1)+2;
HHS1:=MAX(MAX(H,ref(H,1)),ref(H,2));
HHS2:=MAX(MAX(ref(H,S4-1),ref(H,S4)),ref(H,S4+1));
diffS1:=MAX(MAX(diff,ref(diff,1)),ref(diff,2));
diffS2:=MAX(MAX(ref(diff,S4-1),ref(diff,S4)),ref(diff,S4+1));
背离S:=HHS1>HHS2 and diffS1<diffS2 and count(cross(diff, dea),S4)=1;
B1:=BARSLAST(CROSS(DEA,DIFF));
B2:=llvbars(macd,B1);
B3:=barslast(B2=1);
B4:=ref(B3,1)+2;
llB1:=min(min(l,ref(l,1)),ref(l,2));
llB2:=min(min(ref(l,B4-1),ref(l,B4)),ref(l,B4+1));
macdB1:=min(min(macd,ref(macd,1)),ref(macd,2));
macdB2:=min(min(ref(macd,B4-1),ref(macd,B4)),ref(macd,B4+1));
BB:=llB1<llB2 and macdB1>macdB2 and count(cross(dea,diff),B4)=1;
D1:=BARSLAST(CROSS(DIFF, DEA));
D2:=hhvbars(macd,D1);
D3:=barslast(D2=1);
D4:=ref(D3,1)+2;
hhD1:=max(max(h,ref(h,1)),ref(h,2));
hhD2:=max(max(ref(h,D4-1),ref(h,D4)),ref(h,D4+1));
macdD1:=max(max(macd,ref(macd,1)),ref(macd,2));
macdD2:=max(max(ref(macd,D4-1),ref(macd,D4)),ref(macd,D4+1));
DD:=hhD1>hhD2 and macdD1<macdD2 and count(cross(diff,dea),D4)=1;
AA1:=TROUGHBARS(c,5,1)=1;
SS1:=PEAKBARS(c,5,1)=1;
bB1:=TROUGHBARS(c,5,1)=1;
bB2:=barslast(cross(diff,dea))-barslast(cross(dea,diff))<=13 and barslast(cross(diff,dea))-barslast(cross(dea,diff))>0;
bB3:=macd>ref(macd,1) and ref(macd,2)>ref(macd,1);
dD1:=PEAKBARS(c,5,1)=1;
dD2:=barslast(cross(dea,diff))-barslast(cross(diff,dea))<=13 and barslast(cross(dea,diff))-barslast(cross(diff,dea))>0;
dD3:=macd<ref(macd,1) and ref(macd,2)<ref(macd,1);
ENTERLONG:((AA1 or a2=1)and 背离A)or ((B2=1 OR AA1) AND BB) OR (BB1 AND BB2 AND BB3);{多头买入}
EXITLONG:((SS1 or s2=1) and 背离S)or ((D2=1 OR SS1) AND DD) OR (DD1 AND DD2 AND DD3);{多头卖出}
//ENTERSHORT: ,TFILTER; 卖出开仓/空头开仓
//EXITSHORT: ,TFILTER; 买入平仓/空头平仓

股迷开心果 发表于 2010-3-12 08:41

学习学习。

职业骑手 发表于 2010-3-12 08:53

学习学习.谢谢分享.

莫老爷 发表于 2010-3-12 10:15

:handshake:handshake

莫老爷 发表于 2010-3-12 10:24

DIFF:=EMA(CLOSE,s)-EMA(CLOSE,p);
DEA:=EMA(DIFF,m);
MACD:=2*(DIFF-DEA);
A1:=BARSLAST(CROSS(DEA,DIFF));
A2:=llvbars(diff,A1);
A3:=barslast(A2=1);
A4:=ref(A3,1)+2;
llA1:=min(min(l,ref(l,1)),ref(l,2));
llA2:=min(min(ref(l,A4-1),ref(l,A4)),ref(l,A4+1));
diffA1:=min(min(diff,ref(diff,1)),ref(diff,2));
diffA2:=min(min(ref(diff,A4-1),ref(diff,A4)),ref(diff,A4+1));
背离A:=llA1<llA2 and diffA1>diffA2 and count(cross(dea,diff),A4)=1;


S1:=BARSLAST(CROSS(DIFF ,DEA));
S2:=hhvbars(diff,S1);
S3:=barslast(S2=1);
S4:=ref(S3,1)+2;
HHS1:=MAX(MAX(H,ref(H,1)),ref(H,2));
HHS2:=MAX(MAX(ref(H,S4-1),ref(H,S4)),ref(H,S4+1));
diffS1:=MAX(MAX(diff,ref(diff,1)),ref(diff,2));
diffS2:=MAX(MAX(ref(diff,S4-1),ref(diff,S4)),ref(diff,S4+1));
背离S:=HHS1>HHS2 and diffS1<diffS2 and count(cross(diff, dea),S4)=1;


B1:=BARSLAST(CROSS(DEA,DIFF));
B2:=llvbars(macd,B1);
B3:=barslast(B2=1);
B4:=ref(B3,1)+2;
llB1:=min(min(l,ref(l,1)),ref(l,2));
llB2:=min(min(ref(l,B4-1),ref(l,B4)),ref(l,B4+1));
macdB1:=min(min(macd,ref(macd,1)),ref(macd,2));
macdB2:=min(min(ref(macd,B4-1),ref(macd,B4)),ref(macd,B4+1));
BB:=llB1<llB2 and macdB1>macdB2 and count(cross(dea,diff),B4)=1;


D1:=BARSLAST(CROSS(DIFF, DEA));
D2:=hhvbars(macd,D1);
D3:=barslast(D2=1);
D4:=ref(D3,1)+2;
hhD1:=max(max(h,ref(h,1)),ref(h,2));
hhD2:=max(max(ref(h,D4-1),ref(h,D4)),ref(h,D4+1));
macdD1:=max(max(macd,ref(macd,1)),ref(macd,2));
macdD2:=max(max(ref(macd,D4-1),ref(macd,D4)),ref(macd,D4+1));
DD:=hhD1>hhD2 and macdD1<macdD2 and count(cross(diff,dea),D4)=1;

AA1:=TROUGHBARS(c,5,1)=1;
SS1:=PEAKBARS(c,5,1)=1;

bB1:=TROUGHBARS(c,5,1)=1;
bB2:=barslast(cross(diff,dea))-barslast(cross(dea,diff))<=13 and barslast(cross(diff,dea))-barslast(cross(dea,diff))>0;
bB3:=macd>ref(macd,1) and ref(macd,2)>ref(macd,1);
dD1:=PEAKBARS(c,5,1)=1;
dD2:=barslast(cross(dea,diff))-barslast(cross(diff,dea))<=13 and barslast(cross(dea,diff))-barslast(cross(diff,dea))>0;
dD3:=macd<ref(macd,1) and ref(macd,2)<ref(macd,1);




ENTERLONG:(AA1 or a2=1)and 背离A)or ((B2=1 OR AA1) AND BB) OR (BB1 AND BB2 AND BB3);{多头买入}
EXITLONG:(SS1 or s2=1) and 背离S)or ((D2=1 OR SS1) AND DD) OR (DD1 AND DD2 AND DD3);{多头卖出}
//ENTERSHORT: ,TFILTER; 卖出开仓/空头开仓
//EXITSHORT: ,TFILTER; 买入平仓/空头平仓

翟江 发表于 2010-3-15 00:40

谢谢......当前公式 : MACD背离 (指标画线公式)
错误句 : INPUT:S(12,1,100),P(26,1,100),M(9,1,100)
详细信息 : 您在括号前写的不是函数、公式等,
且缺少必要的运算符!
错误起始位置 : 0 ; 长度: 0

追求理想 发表于 2011-11-15 09:56

谢谢分享学习了

腾飞的龙 发表于 2012-6-23 11:09

DIFF:EMA(CLOSE,12) - EMA(CLOSE,26);
DEA:EMA(DIFF,9);
MACD:2*(DIFF-DEA),COLORSTICK;
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
B1:=REF(C,A1+1)>C AND REF(DIFF,A1+1)<DIFF AND CROSS(DIFF,DEA);
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));
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));
C1:=BARSLAST(REF(CROSS(DEA,DIFF),1));
D1:=REF(C,C1+1)<C AND REF(DIFF,C1+1)>DIFF AND CROSS(DEA,DIFF);
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));
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));
MACD底背:IF(B1>0,-0.1,0),COLORRED,POINTDOT;
KDJ底背:IF(B2>0,-0.1,0),COLORFF00FF,POINTDOT;
RSI底背:IF(B3>0,-0.1,0),COLORYELLOW,POINTDOT;
MACD顶背:IF(D1>0,0.1,0),COLOR00FF00,POINTDOT;
KDJ顶背:IF(D2>0,0.1,0),COLORFFCC66,POINTDOT;
RSI顶背:IF(D3>0,0.1,0),COLORWHITE,POINTDOT;
STICKLINE(B1>0,-0.1,0,2,0),COLORRED;
STICKLINE(B2>0,-0.1,0,2,0),COLORFF00FF;
STICKLINE(B3>0,-0.1,0,2,0),COLORYELLOW;
STICKLINE(D1>0,0.1,0,2,0),COLOR00FF00;
STICKLINE(D2>0,0.1,0,2,0),COLORFFCC66;
STICKLINE(D3>0,0.1,0,2,0),COLORWHITE;

学习一下啦 发表于 2014-3-15 16:32

:)学习一下啦:)

速战快乐赚钱 发表于 2018-11-20 12:13

进退有据,速战急归,一柱一线,快乐赚钱

恒强 发表于 2019-2-13 13:52

股迷开心果 发表于 2010-3-12 08:41
学习学习。

进退有据,速战急归,一柱一线,快乐赚钱
页: [1]
查看完整版本: macd顶底背离交易系统(有未来函数,不喜欢的不要用),仅供参考