N:=5;
K:=3;
p:=13;
DIRECTION:=ABS(CLOSE-REF(CLOSE,N));
VOLATILITY:=SUM(ABS(CLOSE-REF(CLOSE,1)),N);
ER:=DIRECTION/VOLATILITY;
FSC:=2/(2+1);
SSC:=2/(30+1);
SC:=ER*(FSC-SSC)+SSC;
SCSQ:=SC*SC;
KMA:=DMA(CLOSE,SCSQ),colorblue;
THRESHOLD:=STD(KMA-REF(KMA,1),20)*K/10;
A:=CLOSE-REF(CLOSE,P);
MI:=SMA(A,P,1);