DDY修正
{DDY}
INPUT: P1(60,0,100),P2(3,0,100),P3(10,0,100);
REFLINE:0;
TODAY:=DYNAINFO(7)=CLOSE and DYNAINFO(10)=AMOUNT and (ORDER(1)=0 and ORDER(2)=0);
RDDY1:=IF(TODAY,"DDEDATA@BIGORDER"(1),bigorder(1));
RDDY2:=IF(TODAY,"DDEDATA@BIGORDER"(2),bigorder(2));
FDDY1:=IF(TODAY,"DDEDATA@ORDER"(1),ORDER(1));
FDDY2:=IF(TODAY,"DDEDATA@ORDER"(2),ORDER(2));
VAR0:=MIN(COUNT(ORDER(2),0),P1);
VAR1:=EMA((2 - BIGORDER(1) - BIGORDER(2)) * VOL/(ORDER(1) + ORDER(2)),P1);
VAR2:=(2*(2 - BIGORDER(1) - BIGORDER(2)) * VOL/(ORDER(1) + ORDER(2))+(p1-1)*ref(VAR1,1))/(p1+1);
VAR11:=if(TODAY,VAR2,VAR1);
DDY:if(TODAY,("DDEDATA@ORDER"(2) - "DDEDATA@ORDER"(1))/CAPITAL ,(ORDER(2) - ORDER(1))/CAPITAL) * VAR11 * 100,COLOR3D;
DDY1:EMA((FDDY2 - FDDY1)/CAPITAL * VAR11* 100,VAR0) * VAR0;
DDY2:MA(DDY1,P2);
DDY3:MA(DDY1,P3);
DRAWTEXTABS(0,0,'涨跌动因');
1,DOTLINE;
DDY中用了ema算法,但是理想数据是单个数据(只有当日数据,没有ema可言)。这就需要把ema解析后改写。
原公式:{lx-ddy}
INPUT: P1(60,0,100),P2(5,0,100),P3(10,0,100);
REFLINE:0;
TODAY:=DYNAINFO(7)=CLOSE and DYNAINFO(10)=AMOUNT and (ORDER(1)=0 and ORDER(2)=0);
{判断是否有理想数据}
RDDY1:=IF(TODAY,"DDEDATA@BIGORDER"(1),bigorder(1));
RDDY2:=IF(TODAY,"DDEDATA@BIGORDER"(2),bigorder(2));
FDDY1:=IF(TODAY,"DDEDATA@ORDER"(1),ORDER(1));
FDDY2:=IF(TODAY,"DDEDATA@ORDER"(2),ORDER(2));
VAR0:=MIN(COUNT(FDDY2,0),P1);
VAR1:=EMA((2 - RDDY1 - RDDY2) * VOL/(FDDY1 + FDDY2),p1);
DDY:(FDDY2 - FDDY1)/CAPITAL * VAR1 * 100,COLOR3D;
DDY1:EMA((FDDY2 - FDDY1)/CAPITAL * VAR1 * 100,VAR0) * VAR0;
DDY2:MA(DDY1,P2);
DDY3:MA(DDY1,P3);
DRAWTEXTABS(0,0,'涨跌动因');
1,DOTLINE;
注意这句:
VAR1:=EMA((2 - RDDY1 - RDDY2) * VOL/(FDDY1 + FDDY2),p1);
变成-----(用法:EMA(X,N),算法:若Y=EMA(X,N)则Y=[2*X+(N-1)*Y']/(N+1),其中Y'表示上一周期Y值):
VAR1:=EMA((2 - BIGORDER(1) - BIGORDER(2)) * VOL/(ORDER(1) + ORDER(2)),P1);
VAR2:=(2*(2 - BIGORDER(1) - BIGORDER(2)) * VOL/(ORDER(1) + ORDER(2))+(p1-1)*ref(VAR1,1))/(p1+1);
VAR11:=if(TODAY,VAR2,VAR1);
修正ema后的公式:
{DDY}
INPUT: P1(60,0,100),P2(3,0,100),P3(10,0,100);
REFLINE:0;
TODAY:=DYNAINFO(7)=CLOSE and DYNAINFO(10)=AMOUNT and (ORDER(1)=0 and ORDER(2)=0);
VAR0:=MIN(COUNT(ORDER(2),0),P1);
VAR1:=EMA((2 - BIGORDER(1) - BIGORDER(2)) * VOL/(ORDER(1) + ORDER(2)),P1);
VAR2:=(2*(2 - BIGORDER(1) - BIGORDER(2)) * VOL/(ORDER(1) + ORDER(2))+(p1-1)*ref(VAR1,1))/(p1+1);
VAR11:=if(TODAY,VAR2,VAR1);
DDY:if(TODAY,("DDEDATA@ORDER"(2) - "DDEDATA@ORDER"(1))/CAPITAL ,(ORDER(2) - ORDER(1))/CAPITAL) * VAR11 * 100,COLOR3D;
DDY1:EMA(DDY,VAR0) * VAR0;
DDY2:MA(DDY1,P2);
DDY3:MA(DDY1,P3);
DRAWTEXTABS(0,0,'涨跌动因');
1,DOTLINE;
数据的差异就是ema的算法造成的。举一反三,遇到这类问题,就这样处理就是了。
|