var: flag(0);
if positiondir=0 then
if flag<>1 then InstallTakeProfit(INTICK, 1000, "TP"); endif;
if flag=1 then InstallTakeProfit(INTICK, 500, "TP2"); endif;
if w then
Enterlong(nextbar, atopen);
flag=flag+1;
endif;
if b then
Entershort(nextbar, atopen);
flag=flag+1;
endif;
endif;
if positiondir=1 and B then
Exitlong(nextbar, atopen);
flag=0;
endif;
if positiondir=-1 and w then
Exitshort(nextbar, atopen);
flag=0;
endif;