求把大智慧的MACD公式改成通达信的,非常感谢。

2024-12-17 03:46:36
推荐回答(1个)
回答1:

{通达信测试通过!}
DIFF : EMA(CLOSE,12) - EMA(CLOSE,26),COLORWHITE;
DEA : EMA(DIFF,9),COLORYELLOW;
MACD : 2*(DIFF-DEA),COLORSTICK;

{======================================================}
COND1:=LONGCROSS(DEA,DIFF,3);
COND2:=LONGCROSS(DIFF,DEA,3);

VAR1:=BARSLAST(COND1);
VAR2:=REF(VAR1,VAR1+1)+1;

VAR3:=BARSLAST(COND2);
VAR4:=REF(VAR3,VAR3+1)+1;

VAR5:=REF(VAR3,VAR1)+1;
MACDTOP1:=REF(HHV(DIFF,VAR5),VAR1);
TOP1:=REF(HHV(HIGH,VAR5),VAR1);

VAR6:=REF(VAR3,VAR1+VAR2)+1;
MACDTOP2:=REF(HHV(DIFF,VAR6),VAR1+VAR2);
TOP2:=REF(HHV(HIGH,VAR6),VAR1+VAR2);

顶背离0:=TOP1>TOP2 AND MACDTOP1顶背离:=顶背离0>REF(顶背离0,1);

VAR7:=REF(VAR1,VAR3)+1;
MACDBASE1:=REF(LLV(DIFF,VAR7),VAR3);
BASE1:=REF(LLV(LOW,VAR7),VAR3);

VAR8:=REF(VAR1,VAR3+VAR4)+1;
MACDBASE2:=REF(LLV(DIFF,VAR8),VAR3+VAR4);
BASE2:=REF(LLV(LOW,VAR8),VAR3+VAR4);

底背离0:=BASE1MACDBASE2;
底背离:=底背离0>REF(底背离0,1);

VAR9:=BARSLAST(顶背离);
VAR10:=REF(HHVBARS(DIFF,REF(VAR3,VAR9)),VAR9);
DLTOP1:=FILTER(BACKSET(顶背离,VAR10+1),VAR10);

VAR11:=REF(VAR1,VAR9+1)+1;
VAR12:=REF(HHVBARS(DIFF,REF(VAR3,VAR9+VAR11))+1,VAR9+VAR11);
DLTOP2:=FILTER(BACKSET(顶背离,VAR9+VAR11+VAR12),VAR9+VAR11+VAR12);

DRAWLINE(DLTOP2,DIFF,DLTOP1,DIFF,0),COLORRED;
DRAWICON(顶背离,DIFF,2),COLORGREEN{,ALIGN1,VALIGN2};

VAR13:=BARSLAST(底背离);
VAR14:=REF(LLVBARS(DIFF,VAR7),VAR13);
DLBASE1:=FILTER(BACKSET(底背离,VAR14+1),VAR14+3);

VAR15:=REF(VAR3,VAR13+1)+1;
VAR16:=REF(LLVBARS(DIFF,REF(VAR1,VAR13+VAR15))+1,VAR13+VAR15);
DLBASE2:=FILTER(BACKSET(底背离,VAR13+VAR15+VAR16),VAR13+VAR15+VAR16);

DRAWLINE(DLBASE2,DIFF,DLBASE1,DIFF,0),COLORGREEN;
DRAWICON(底背离,DIFF,1);