P:=14;
TRR := SUM(MAX(MAX(HIGH-LOW,Abs(HIGH-REF(CLOSE,1))),ABS(LOW-REF(CLOSE,1))),P);
HD := HIGH-REF(HIGH,1);
LD := REF(LOW,1)-LOW;
DMP:= SUM(IF(HD>0 AND HD>LD,HD,0),P);
DMM:= SUM(IF(LD>0 AND LD>HD,LD,0),P);
pdi:=DMP*100/TRR,COLORGRAY;
mdi:=DMM*100/TRR;
M:=P*0.42;
ADX: MA((PDI-MDI)/(MDI+PDI)*100,M),COLORYELLOW,LINETHICK2;
ADXR:(ADX+REF(ADX,M))/2,COLORGREEN;
30,COLORRED,DOTLINE;
0,COLORCC66CC,LINETHICK2;
(-30),COLORRED,DOTLINE;
DIFF:=ADX-ADXR;
DEA:=EMA(DIFF,9);
ADXCD:2*DIFF-DEA,STICK,COLORGRAY;