DD:=CONST(IF(ISLASTBAR=1,LLV(L,K),0));
KJ:=GD-DD;
A1:=REF(HIGH,3)=HHV(HIGH,2*3+1); B1:=FILTER(A1,3); C1:=BACKSET(B1,3+1); D1:=FILTER(C1,3);
A2:=REF(LOW,3)=LLV(LOW,2*3+1); B2:=FILTER(A2,3); C2:=BACKSET(B2,3+1); D2:=FILTER(C2,3);
E1:=(REF(LLV(LOW,2*3),1)+REF(HHV(HIGH,2*3),1))/2; E2:=(HIGH+LOW)/2;
H1:=(D1 AND NOT(D2 AND E1 =E2)) OR BARSTATUS=BARSCOUNT(2) OR BARSCOUNT(CLOSE)=1;
L1:=(D2 AND NOT(D1 AND E1 E2)); H2:=D1 AND NOT(D2 AND E1 =E2);
X1:=REF(BARSLAST(H1),1)+1; F1:=BACKSET(H1 AND COUNT(L1,X1) 0,LLVBARS(IF(L1,LOW,10000),X1));
G1:=F1 REF(F1,1); I1:=BACKSET(G1,2); LD:=I1 REF(I1,1);
L2:=LD OR BARSTATUS=BARSCOUNT(2) OR BARSCOUNT(CLOSE)=1;
X2:=REF(BARSLAST(L2),1)+1; F2:=BACKSET(L2 AND COUNT(H2,X2) 0,HHVBARS(IF(H2,HIGH,0),X2));
G2:=F2 REF(F2,1); I2:=BACKSET(G2,2); HD:=I2 REF(I2,1);
J1:=BACKSET(BARSTATUS=BARSCOUNT(2),MIN(BARSLAST(HD),BARSLAST(LD))+1); J2:=J1 REF(J1,1);
A3:=H REF(H,REF(BARSLAST(HD),1)+1);
B3:=REF(H,REF(BARSLAST(HD),1)+1) REF(H,REF(BARSLAST(HD),1)+2+REF(BARSLAST(HD),REF(BARSLAST(HD),1)+2));
D3:=A3 AND B3 AND HD; E3:=BACKSET(D3,REF(BARSLAST(HD),1)+2); HH:=E3 REF(E3,1);
A4:=L REF(L,REF(BARSLAST(LD),1)+1);
B4:=REF(L,REF(BARSLAST(LD),1)+1) REF(L,REF(BARSLAST(LD),1)+2+REF(BARSLAST(LD),REF(BARSLAST(LD),1)+2));
D4:=A4 AND B4 AND LD; E4:=BACKSET(D4,REF(BARSLAST(LD),1)+2); LL:=E4 REF(E4,1);
DRAWICON(HH,H,12); DRAWICON(LL,L,11 );
H3:=HH OR BARSTATUS=BARSCOUNT(HH) OR BARSCOUNT(C)=1;
X3:=REF(BARSLAST(H3),1)+1; F3:=BACKSET(H3 AND COUNT(LL,X3) 0,LLVBARS(IF(LL,L,POW(10,20)),X3));
G3:=F3 REF(F3,1); I3:=BACKSET(G3,2); LZ:=I3 REF(I3,1);
L4:=LZ OR BARSTATUS=BARSCOUNT(2) OR BARSCOUNT(C)=1;
X4:=REF(BARSLAST(L4),1)+1; F4:=BACKSET(L4 AND COUNT(HH,X4) 0,HHVBARS(IF(HH,H,-POW(10,20)),X4));
G4:=F4 REF(F4,1); I4:=BACKSET(G4,2); HZ:=I4 REF(I4,1);
K1:=BACKSET(BARSTATUS=BARSCOUNT(2),MIN(BARSLAST(HZ),BARSLAST(LZ))+1); K2:=K1 REF(K1,1);
UU:=BACKSET(BARSTATUS=BARSCOUNT(2),BARSLAST(LD)+1);
VV:=UU REF(UU,1);
WW:=BACKSET(VV,REF(BARSLAST(LD),1)+2);
XX:=WW REF(WW,1);
DRAWLINE(XX,L,VV,L,1),COLORMAGENTA,LINETHICK1;
UU2:=BACKSET(BARSTATUS=BARSCOUNT(2),BARSLAST(HD)+1);
VV2:=UU2 REF(UU2,1);
WW2:=BACKSET(VV2,REF(BARSLAST(HD),1)+2);
XX2:=WW2 REF(WW2,1);
DRAWLINE(XX2,H,VV2,H,1),COLORMAGENTA,LINETHICK1;
N:=1;XGG:=ZIG(H,L);
STICKLINE(HH,DD,GD,0,-1),COLORGREEN;
STICKLINE(CURRBARSCOUNT=N/2,GD,DD,0,-1),COLORGREEN;
STICKLINE(CURRBARSCOUNT=1 AND C O,GD,DD,0,-1),COLORGREEN;
STICKLINE(CURRBARSCOUNT=1 AND C O,GD,DD,0,-1),COLORRED;
STICKLINE(LL,GD,DD,0,-1),COLORRED;