SHORT:=12;LONG:=26;MID:=9;
DIF:=100*(EMA(CLOSE,SHORT)-EMA(CLOSE,LONG));
DEA:=EMA(DIF,MID);
MACD:=(DIF-DEA)*2;
{底部结构预警}
死叉:=CROSS(DEA,DIF);
N1:=BARSLAST(死叉);{最近一次死叉的位置}
N2:=REF(BARSLAST(死叉),N1+1);{倒数第二次死叉与倒数第一次死叉的区间}
N3:=REF(BARSLAST(死叉),N2+N1+2);{倒数第三次死叉与倒数第二次死叉的区间}
CL1:=LLV(C,N1+1);{最近一次死叉后,最低收盘价}
DIFL1:=LLV(DIF,N1+1);{www.9m8.cn 九毛八公式指标网}
CL2:=REF(CL1,N1+1);{倒数第二次死叉与倒数第一次死叉之间的最低收盘价}
DIFL2:=REF(DIFL1,N1+1);
CL3:=REF(CL2,N1+1);{倒数第三次死叉与倒数第二次死叉之间的最低收盘价}
DIFL3:=REF(DIFL2,N1+1);
PDIFL2:=IF(DIFL2 0,INTPART(LOG(DIFL2))-1,INTPART(LOG(-DIFL2))-1);
MDIFL2:=INTPART(DIFL2/POW(10,PDIFL2));
PDIFL3:=IF(DIFL3 0,INTPART(LOG(DIFL3))-1,INTPART(LOG(-DIFL3))-1);
MDIFL3:=INTPART(DIFL3/POW(10,PDIFL3));
MDIFB2:=INTPART(DIF/POW(10,PDIFL2));
MDIFB3:=INTPART(DIF/POW(10,PDIFL3));
直接底背离:=(CL1 CL2 ) AND (MDIFB2 MDIFL2) AND (MACD 0 AND REF(MACD,1) 0) AND MDIFB2 =REF(MDIFB2,1);
隔峰底背离:=(CL1 CL3 AND CL3 CL2 ) AND (MDIFB3 MDIFL3) AND (MACD 0 AND REF(MACD,1) 0) AND MDIFB3 =REF(MDIFB3,1);
B:=直接底背离 OR 隔峰底背离;
BG:=((MDIFB2 REF(MDIFB2,1))*REF(直接底背离,1)) OR ((MDIFB3 REF(MDIFB3,1))*REF(隔峰底背离,1));
TFILTER(BG,MACD 0,1)&&BARSLAST(B);