盘立方软件macd量化多空顶底背离麦语言指标公式源码:
DIFF:=EMA(CLOSE,12) – EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD:=2*(DIFF-DEA),COLORSTICK;
JC:=CROSS(DIFF,DEA);
SC:=CROSSDOWN(DIFF,DEA);
N1:=BARSLAST(JC)+1;
N2:=BARSLAST(SC)+1;
HH:=VALUEWHEN(CROSSDOWN(DIFF,DEA),HHV(H,N1));//上次MACD红柱期间合约最大值
HH2:=VALUEWHEN(CROSSDOWN(DIFF,DEA),REF(HH,1));//上上次MACD红柱期间合约最大值
MHD:=VALUEWHEN(CROSSDOWN(DIFF,DEA),HHV(MACD,N1));//上次MACD红柱期间MACD最大值
MHD2:=VALUEWHEN(CROSSDOWN(DIFF,DEA),REF(MHD,1));//上上次MACD红柱期间MACD最大值
LL:=VALUEWHEN(CROSS(DIFF,DEA),LLV(L,N2));//上次MACD绿柱期间合约最小值
LL2:=VALUEWHEN(CROSS(DIFF,DEA),REF(LL,1));//上上次MACD绿柱期间合约最小值
MLD:=VALUEWHEN(CROSS(DIFF,DEA),LLV(MACD,N2));//上次MACD绿柱期间MACD最小值
MLD2:=VALUEWHEN(CROSS(DIFF,DEA),REF(MLD,1));//上上次MACD绿柱期间MACD最小值
A:=CROSSDOWN(DIFF,DEA)&&HH>HH2&&MHD<MHD2;//顶背离
B:=CROSS(DIFF,DEA)&&LL<LL2&&MLD>MLD2;//底背离
DRAWTEXT(A,H,’▼’),COLORWHITE,FONTSIZE30;
DRAWTEXT(B,L,’▲’),COLORWHITE,FONTSIZE30,VALIGN0;
HHH:=VALUEWHEN(CROSSDOWN(DIFF,DEA),HHV(C,N1));//上次MACD红柱期间合约最大值
HHH2:=VALUEWHEN(CROSSDOWN(DIFF,DEA),REF(HH,1));//上上次MACD红柱期间合约最大值
LLL:=VALUEWHEN(CROSS(DIFF,DEA),LLV(C,N2));//上次MACD绿柱期间合约最小值
LLL2:=VALUEWHEN(CROSS(DIFF,DEA),REF(LL,1));//上上次MACD绿柱期间合约最小值
DRAWTEXT(CROSS(H,REF(HHH,BARSLAST(SC))) AND COUNT(CROSS(H,REF(HHH,BARSLAST(SC))),BARSLAST(B)+1)=1 AND MACD>0 AND BARSLAST(B)<BARSLAST(SC),L,’●’),COLORRED,FONTSIZE35,VALIGN0;
DRAWTEXT(CROSSDOWN(L,REF(LLL,BARSLAST(JC))) AND COUNT(CROSSDOWN(L,REF(LLL,BARSLAST(JC))),BARSLAST(SC)+1)=1 AND MACD<0 AND BARSLAST(A)<BARSLAST(JC),H,’●’),COLORGREEN,FONTSIZE35,VALIGN2;
DRAWTEXT(A&&REF(VALUEWHEN(SC,A),1),H,’▼’),COLORCYAN,FONTSIZE30;
DRAWTEXT(B&&REF(VALUEWHEN(JC,B),1),L,’▲’),COLORRED,FONTSIZE30,VALIGN0;
DRAWSL(REF(B,SUMBARS(JC,2)-1)&&JC&&LL>LL2,LL,0,-N2+1,0,COLORRED);
DRAWSL(REF(A,SUMBARS(SC,2)-1)&&SC&&HH<HH2,HH,0,-N1+1,0,COLORCYAN);
DRAWTEXT(REF(B,SUMBARS(JC,2)-1)&&JC&&LL>LL2,LL,’A’),COLORRED,VALIGN0,FONTSIZE18,ALIGN0;
DRAWTEXT(REF(A,SUMBARS(SC,2)-1)&&SC&&HH<HH2,HH,’A’),COLORCYAN,FONTSIZE18,ALIGN0;
COND1:REF(B,SUMBARS(JC,2)-1)&&JC&&LL>LL2;
COND2:REF(A,SUMBARS(SC,2)-1)&&SC&&HH<HH2;
DRAWSL(REF(COND1,SUMBARS(JC,2)-1) && REF(B,SUMBARS(JC,3)-1)&&JC&&LL>=LL2,LL,0,-N2+1,0,COLORRED);
DRAWSL(REF(COND2,SUMBARS(SC,2)-1) && REF(A,SUMBARS(SC,3)-1)&&SC&&HH<=HH2,HH,0,-N1+1,0,COLORCYAN);
DRAWTEXT(REF(COND1,SUMBARS(JC,2)-1) && REF(B,SUMBARS(JC,3)-1)&&JC&&LL>=LL2,LL,’B’),VALIGN0,FONTSIZE18,COLORRED,ALIGN0;
DRAWTEXT(REF(COND2,SUMBARS(SC,2)-1) && REF(A,SUMBARS(SC,3)-1)&&SC&&HH<=HH2,HH,’B’),FONTSIZE18,COLORCYAN,ALIGN0;