N1:=55;N2:=20;
LC:=REF(CLOSE,1);
WTR:=MAX((HIGH - LOW),MAX((HIGH - LC),(LC - LOW)));
ATR:=SMA(WTR,20,1);
AA:=(HHV(HIGH,N1) - (2 * ATR));
BB:=CROSS(CLOSE,REF(HHV(HIGH,55),1));
SSS:=CROSS(MIN(MA(CLOSE,13),AA),CLOSE);
BBB:=BARSLAST(BB);
SSSB:=BARSLAST(SSS);
B1:=((BBB = 0) AND (REF(SSSB,1) < REF(BBB,1)));
B1B:=BARSLAST(B1);
B2:=((((BB = 1) AND (B1B < SSSB)) AND (B1B > 0)) AND (COUNT(BB,SSSB) < 3));
B2B:=BARSLAST(B2);
B3:=((((BB = 1) AND (B2B < B1B)) AND (COUNT(BB,SSSB) < 4)) AND (COUNT(BB,SSSB) > 2));
B3B:=BARSLAST(B3);
SS:=CROSS(MAX(AA,MA(CLOSE,13)),CLOSE);
SS1:=(((SS AND ((B3B < B2B) OR (B2B < B1B))) AND (SSSB > B1B)) AND (COUNT(SS,B2B) < 2));
SS1B:=BARSLAST(SS1);
SS2:=((((SS AND (SS1B < SSSB)) AND (B3B < B2B)) AND (SS1B > 0)) AND (COUNT(SS,B2B) < 3));
SSSS:=(SSS AND (REF(SSSB,1) > REF(B1B,1)));
DRAWICON((B1 = 1),(LOW - 0.1),1);
DRAWTEXT((B1 = 1),(LOW - 0.25),'买入');
DRAWICON((B2 = 1),(LOW - 0.1),1);
DRAWTEXT((B2 = 1),(LOW - 0.25),'加仓');
DRAWICON((B3 = 1),(LOW - 0.1),1);
DRAWTEXT((B3 = 1),(LOW - 0.25),'续加');
DRAWICON((SS1 = 1),(HIGH + 0.1),2);
DRAWTEXT((SS1 = 1),(HIGH + 0.25),'减仓1');
DRAWICON((SS2 = 1),(HIGH + 0.1),2);
DRAWTEXT((SS2 = 1),(HIGH + 0.25),'减仓2');
DRAWICON((SSSS = 1),(HIGH + 0.1),2);
DRAWTEXT((SSSS = 1),(HIGH + 0.25),'快卖');