inputs: lots(1),blenpre(20),blenvol(7),dropstart(10),dropk(4);
vars : minpoint(0),myoffset(0),prehp(0),prelp(0),highafterentry(0),loafterentry(0),bopenlong(False),bopenshort(False),mavol(0),dropstartflag(False),atr(0),dropline(0);
minpoint = MinMove*PriceScale;
prehp = highest(low,blenpre);
prelp = lowest(high,blenpre);
mavol = average(v,blenvol);
bopenlong = low[1]>=prehp[1] and low[2]>=prelp[2] and high>=high[1]and mavol[1]>=mavol[2];
bopenshort = high[1]<=prelp[1] and high[2]<=prehp[2] and low<=low[1] and mavol[1]>=mavol[2];
atr = AvgTrueRange(14);
//kai cang
if(bopenlong and marketposition=0) then buy("BPK") next bar at maxlist(open,high[1]) limit;
if(bopenshort and marketposition=0) then sellshort("SPK") next bar at minlist(open,low[1]) limit;
//diao deng zhi sun
if (marketposition<>0 and barssinceentry>=1) then
begin
if (barssinceentry>1) then begin
highafterentry= maxlist(high[1],highafterentry[1]);
loafterentry= minlist(low[1],loafterentry[1]);
end else begin
highafterentry= maxlist(close[1],entryprice);
loafterentry= minlist(close[1],entryprice);
end;
end;
dropstartflag = (highafterentry>=entryprice*(1+dropstart*0.001) or loafterentry<=entryprice*(1-dropstart*0.001));
//zhi sun tiao jian
if (marketposition<>0 and barssinceentry>=1) then
begin
if (marketposition=1) then dropline= highafterentry-dropk*atr[1];
if(low<=dropline and dropstartflag=True) then sell("SP1") next bar at minlist(open,dropline) limit;
if (marketposition=-1) then dropline = loafterentry+dropk*atr[1];
if(high>=dropline and dropstartflag=True) then buytocover("BP1") next bar at maxlist(open,dropline) limit;
end;