MACD的原理其实就是乖离
[GSCD-高山CD优化版]
DIF相当于5日线,DEA相当于10日线,0轴线相当于60日线;
经典MACD源码:
DIF:EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:EMA(DIF,9);
MACD:(DIF-DEA)*2,COLORSTICK;
使用5日线、10日线、60日线计算的相当于经典MACD的对比源码:
DIF:(EMA(C,5)-EMA(C,60))/EMA(C,60)*1000;
DEA:(EMA(C,10)-EMA(C,60))/EMA(C,60)*1000;
MACD:(DIF-DEA)*2,COLORSTICK;
大家有空可以对比二者的图形、会很相似。
{GSCD-------高山CD}
M:=10000;
N1:=2;
N2:=8;
N3:=21;
B:=5;
零轴线基准均线:=EMA(C,M);
X00:=C;
X01:=0.7522406533*X00+0.3609454219*REF(X00,1)-0.03309329629*REF(X00,2)-0.04241822779*REF(X00,3)-0.026737249*REF(X00,4)-0.007010041271*REF(X00,5)-0.002652859952*REF(X00,6)-0.0008415042966*REF(X00,7)-0.0002891931964*REF(X00,8)-0.0000956265934*REF(X00,9)-0.0000321286052*REF(X00,10)-0.0000106773454*REF(X00,11)-0.0000035457562*REF(X00,12)-0.0000011670713*REF(X00,13);
X02:=0.7522406533*X01+0.3609454219*REF(X01,1)-0.03309329629*REF(X01,2)-0.04241822779*REF(X01,3)-0.026737249*REF(X01,4)-0.007010041271*REF(X01,5)-0.002652859952*REF(X01,6)-0.0008415042966*REF(X01,7)-0.0002891931964*REF(X01,8)-0.0000956265934*REF(X01,9)-0.0000321286052*REF(X01,10)-0.0000106773454*REF(X01,11)-0.0000035457562*REF(X01,12)-0.0000011670713*REF(X01,13);
X03:=0.7522406533*X02+0.3609454219*REF(X02,1)-0.03309329629*REF(X02,2)-0.04241822779*REF(X02,3)-0.026737249*REF(X02,4)-0.007010041271*REF(X02,5)-0.002652859952*REF(X02,6)-0.0008415042966*REF(X02,7)-0.0002891931964*REF(X02,8)-0.0000956265934*REF(X02,9)-0.0000321286052*REF(X02,10)-0.0000106773454*REF(X02,11)-0.0000035457562*REF(X02,12)-0.0000011670713*REF(X02,13);
BB1:=(X01*5+X02*3+X03*1)/9;
DIF1:=(BB1-EMA(C,M))/EMA(C,M);
DEA11:=(EMA(C,N2)-EMA(C,M))/EMA(C,M);
DEA21:=(EMA(C,N3)-EMA(C,M))/EMA(C,M);
{以下为1分钟周期:}
A_DIF:=POW((DIF1+1),55)*1000;
A_DEA1:=POW((DEA11+1),55)*1000;
A_DEA2:=POW((DEA21+1),55)*1000;
{以下为5分钟周期:}
B_DIF:=POW((DIF1+1),29)*1000;
B_DEA1:=POW((DEA11+1),29)*1000;
B_DEA2:=POW((DEA21+1),29)*1000;
{以下为15分钟周期:}
D_DIF:=POW((DIF1+1),17)*1000;
D_DEA1:=POW((DEA11+1),17)*1000;
D_DEA2:=POW((DEA21+1),17)*1000;
{以下为30分钟周期:}
E_DIF:=POW((DIF1+1),9)*1000;
E_DEA1:=POW((DEA11+1),9)*1000;
E_DEA2:=POW((DEA21+1),9)*1000;
{以下为60分钟周期:}
F_DIF:=POW((DIF1+1),5)*1000;
F_DEA1:=POW((DEA11+1),5)*1000;
F_DEA2:=POW((DEA21+1),5)*1000;
{以下为日周期:}
G_DIF:=POW((DIF1+1),3)*1000;
G_DEA1:=POW((DEA11+1),3)*1000;
G_DEA2:=POW((DEA21+1),3)*1000;
DIF:IFF(PERIOD=0,A_DIF,IFF(PERIOD=1,B_DIF,IFF(PERIOD=2,D_DIF,IFF(PERIOD=3,E_DIF,IFF(PERIOD=4,F_DIF,IFF(PERIOD=5,G_DIF,DRAWNULL
)))))),COLORRED, LINETHICK1;
DEA1:IFF(PERIOD=0,A_DEA1,IFF(PERIOD=1,B_DEA1,IFF(PERIOD=2,D_DEA1,IFF(PERIOD=3,E_DEA1,IFF(PERIOD=4,F_DEA1,IFF(PERIOD=5,G_DEA1,DRAWNULL
)))))),COLORWHITE, LINETHICK1;
DEA2:IFF(PERIOD=0,A_DEA2,IFF(PERIOD=1,B_DEA2,IFF(PERIOD=2,D_DEA2,IFF(PERIOD=3,E_DEA2,IFF(PERIOD=4,F_DEA2,IFF(PERIOD=5,G_DEA2,DRAWNULL
)))))),COLORGREEN, LINETHICK1;
DIF0:=(EMA(EMA(EMA(C,N1),N1),N1)-EMA(C,M))/EMA(C,M);
MACD0:=POW((DIF0-DEA21),1)*B*1000;
MACD00:=MACD0;
{以下为1分钟周期:}
A_MACD:=POW((DIF0-DEA21),1)*B*21000;
A_MACD1:=A_MACD;
{以下为5分钟周期:}
B_MACD:=POW((DIF0-DEA21),1)*B*13000;
B_MACD1:=B_MACD;
{以下为15分钟周期:}
D_MACD:=POW((DIF0-DEA21),1)*B*8000;
D_MACD1:=D_MACD;
{以下为30分钟周期:}
E_MACD:=POW((DIF0-DEA21),1)*B*5000;
E_MACD1:=E_MACD;
{以下为60分钟周期:}
F_MACD:=POW((DIF0-DEA21),1)*B*3000;
F_MACD1:=F_MACD;
{以下为日周期:}
G_MACD:=POW((DIF0-DEA21),1)*B*2000;
G_MACD1:=G_MACD;
MACD:IFF(PERIOD=0,A_MACD,IFF(PERIOD=1,B_MACD,IFF(PERIOD=2,D_MACD,IFF(PERIOD=3,E_MACD,IFF(PERIOD=4,F_MACD,IFF(PERIOD=5,G_MACD,DRAWNULL
)))))),COLORSTICK;
MACD1:IFF(PERIOD=0,A_MACD1,IFF(PERIOD=1,B_MACD1,IFF(PERIOD=2,D_MACD1,IFF(PERIOD=3,E_MACD1,IFF(PERIOD=4,F_MACD1,IFF(PERIOD=5,G_MACD1,DRAWNULL
)))))),COLORWHITE;
高山CD 优化版 也同步在本网发布,大家可以找找,很容易的搜索到的
|