N:=20;
P:=3;
M:=8;
DIR1:=Abs(CLOSE-REF(CLOSE,N));
VIR1:=SUM(ABS(CLOSE-REF(CLOSE,1)),N);
ER1:=DIR1/VIR1;
CS1:=ER1*(0.8-2/8)+2/8;
CQ1:=CS1*CS1;
AMA1:=DMA(CLOSE,CQ1),COLORWHITE;
{CLMA}
SG:=SUM(TR, N);
RE1:=ABS(C-REF(C,N));
RE2:=HHV(H,N)-LLV(L,N);
RE:=RE2/SG;
A:=(RE/SUM(TR, N));
AMA_CL:=A*C+(1-A)*REF(AMA1,1);
CLMA:EMA(AMA_CL,P),COLORRED;
MA8:MA(C,M),COLORYELLOW;
MAcr:=IF(CROSS(C,MA8) OR CROSS(C,CLMA), 1, 0);
LONG:=IF(C>REF(C,10) AND MACR=1 AND CLMA>REF(CLMA,1) AND MA8>REF(MA8,1), 1, 0);
LONG0:BUY(LONG=1, L*0.98);
DRAWKLINE(H,O,L,C);