SH:=12;LO:=24;MI:=9;
FIRST:=IF(PERIOD=3,1/6,1/4);
DIF0:=EMA(CLOSE,SH*FIRST)-EMA(CLOSE,LO*FIRST);
DEA0:=EMA(DIF0,MI*FIRST);
macd0:=(DIF0-DEA0)*2;
DIF1:=EMA(CLOSE,SH)-EMA(CLOSE,LO);
DEA1:=EMA(DIF1,MI);
MacD1:=(DIF1-DEA1)*2;
STRONGER:=MACD1>0 AND MACD1-REF(MACD1,1)>REF((MACD1-REF(MACD1,1)),1);
WEAKER:=MACD1<=0 AND Abs(MACD1)-REF(ABS(MACD1),1)[
MID:=IF(PERIOD=1,3,4);]
DIF2:=EMA(CLOSE,SH*MID)-EMA(CLOSE,LO*MID);
DEA2:=EMA(DIF2,MI*MID);
MACD2:=(DIF2-DEA2)*2;
LONG:=IF(PERIOD=6,24,IF(PERIOD=5,20,IF(PERIOD=4 OR PERIOD=3 OR PERIOD=2,16,IF(PERIOD=1,12,DRAWNULL))));
DIF3:=EMA(CLOSE,SH*LONG)-EMA(CLOSE,LO*LONG);
DEA3:=EMA(DIF3,MI*LONG);
MACD3:=(DIF3-DEA3)*2;
UP1:=REF(HHV(DEA1,MI*LONG),1);
DN1:=REF(LLV(DEA1,MI*LONG),1);
ZZ1:=(UP1+DN1)/2;
DRAWBAND(UP1,RGB(80,80,80),ZZ1,0);
DRAWBAND(ZZ1,RGB(45,45,45),DN1,0);
UP0:=REF(HHV(DEA0,IF(PERIOD=3,MI*MID/3*2,MI*MID)),1);
DN0:=REF(LLV(DEA0,IF(PERIOD=3,MI*MID/3*2,MI*MID)),1);
ZZ0:=(UP0+DN0)/2;
DRAWBAND(UP0,RGB(30,30,30),ZZ0,0);
DRAWBAND(ZZ0,RGB(15,15,15),DN0,0);
STICKLINE(1,0,0,0.5,0),COLORF580F5;
STICKLINE(UP0>=UP1,UP1,UP1,1,0),COLOR808080;
STICKLINE(DN0<=DN1,DN1,DN1,1,0),COLOR808080;
STICKLINE(UP0>=UP1,UP0,UP0,1,0),COLORAAAAAA;
STICKLINE(DN0<=DN1,DN0,DN0,1,0),COLORAAAAAA;
DRAWBAND(DEA0,RGB(100,100,100),DEA0,0);
STICKLINE(MACD1>0,DIF1,DEA1,3,1),COLORF580F5;
STICKLINE(MACD1<0,DIF1,DEA1,3,1),COLORCCDD33;
STICKLINE(MACD1>0 AND MACD1>REF(MACD1,1),DIF1,DEA1,1,0),COLORF580F5;
STICKLINE(MACD1<=0 AND MACD1<=REF(MACD1,1),DIF1,DEA1,1,0),COLORCCDD33;
STICKLINE(DIF1>0 AND MACD1>0 AND MACD1>REF(MACD1,1),DIF1,DEA1,1,0),COLORMAGENTA;
STICKLINE(DIF1<=0 AND MACD1<=0 AND MACD1<=REF(MACD1,1),DIF1,DEA1,1,0),COLORBLUE;
DRAWTEXT(REF(MACD1,1)>0 AND MACD1>REF(MACD1,1) AND STRONGER,DEA1,'^^'),COLORRED;
DRAWTEXT(REF(MACD1,1)<=0 AND MACD1<=REF(MACD1,1) AND WEAKER,DIF1,'^^'),COLORGREEN;
{ _通达信指标公式}
STICKLINE(DIF2>DEA2,DIF2,DEA2,2.5,-1),COLORRED;
STICKLINE(DIF2<=DEA2,DIF2,DEA2,2.5,-1),COLORGREEN;
STICKLINE(DIF2-DEA2>REF(DIF2-DEA2,1) AND DIF2>DEA2,DIF2,DEA2,2.5,1),COLORRED;
STICKLINE(DIF2-DEA2<=REF(DIF2-DEA2,1) AND DIF2<=DEA2,DIF2,DEA2,2.5,1),COLORGREEN;
STICKLINE(MACD1>0 AND MACD1>REF(MACD1,1) AND MACD2>0 AND MACD2>=REF(MACD2,1),DIF2,DEA2,0.5,1),COLORRED;
STICKLINE(MACD1<=0 AND MACD1<=REF(MACD1,1) AND MACD2<=0 AND MACD2<=REF(MACD2,1),DIF2,DEA2,0.5,1),COLORGREEN;
STICKLINE(DIF3>DEA3,DIF3,DEA3,1.5,-1),COLORRED;
STICKLINE(DIF3<=DEA3,DIF3,DEA3,1.5,-1),COLORGREEN;
STICKLINE(DIF3-DEA3>REF(DIF3-DEA3,1) AND DIF3>DEA3,DIF3,DEA3,1.5,0),COLORRED;
STICKLINE(DIF3-DEA3<=REF(DIF3-DEA3,1) AND DIF3<=DEA3,DIF3,DEA3,1.5,0),COLORGREEN;
DRAWTEXT(ISLASTBAR AND PERIOD=2,(DIF1+DEA1)/2,'←15M'),COLORWHITE;
DRAWTEXT(ISLASTBAR AND PERIOD=2,(DIF2+DEA2)/2,'←60M'),COLORYELLOW;
DRAWTEXT(ISLASTBAR AND PERIOD=2,(DIF3+DEA3)/2,'←DAY'),COLORMAGENTA;
DRAWTEXT(ISLASTBAR AND PERIOD=3,DEA0,'←5M'),COLORWHITE;
DRAWTEXT(ISLASTBAR AND PERIOD=3,(DIF1+DEA1)/2,'←30M'),COLORWHITE;
DRAWTEXT(ISLASTBAR AND PERIOD=3,(DIF2+DEA2)/2,'←2HOUR'),COLORYELLOW;
DRAWTEXT(ISLASTBAR AND PERIOD=3,(DIF3+DEA3)/2,'←2DAY'),COLORMAGENTA;
DRAWTEXT(ISLASTBAR AND PERIOD=4,DEA0,'←15M'),COLORRED;
DRAWTEXT(ISLASTBAR AND PERIOD=4,(DIF1+DEA1)/2,'←60M'),COLORWHITE;
DRAWTEXT(ISLASTBAR AND PERIOD=4,(DIF2+DEA2)/2,'←DAY'),COLORYELLOW;
DRAWTEXT(ISLASTBAR AND PERIOD=4,(DIF3+DEA3)/2,'←WEEK'),COLORMAGENTA;
DRAWTEXT(ISLASTBAR AND PERIOD=5,DEA0,'←60M'),COLORRED;
DRAWTEXT(ISLASTBAR AND PERIOD=5,(DIF1+DEA1)/2,'←DAY'),COLORWHITE;
DRAWTEXT(ISLASTBAR AND PERIOD=5,(DIF2+DEA2)/2,'←WEEK'),COLORYELLOW;
DRAWTEXT(ISLASTBAR AND PERIOD=5,(DIF3+DEA3)/2,'←MONTH'),COLORMAGENTA;
DRAWTEXT(ISLASTBAR AND PERIOD=6,DEA0,'←DAY'),COLORRED;
DRAWTEXT(ISLASTBAR AND PERIOD=6,(DIF1+DEA1)/2,'←WEEK'),COLORWHITE;
DRAWTEXT(ISLASTBAR AND PERIOD=6,(DIF2+DEA2)/2,'←MONTH'),COLORYELLOW;
DRAWTEXT(ISLASTBAR AND PERIOD=6,(DIF3+DEA3)/2,'←HALF_YEAR'),COLORMAGENTA;