請教我想達到:贏利超過1%,回吐到70%平倉的思路,如下程序卻總是第一次開倉、平倉是對的,之后每次開倉之后馬上就平倉,不知問題出在什么地方。
If enterbars=0 then
begin
HigherAfterEntry:=enterprice;
LowerAfterEntry:=enterprice;
end;
else If enterbars>=1 then
begin
HigherAfterEntry:=max(HigherAfterEntry,h_1);
LowerAfterEntry:=min(LowerAfterEntry,l_1);
end;
//開多單的平倉
if holding>0 and enterbars>0 then
begin
if enterbars>=1 and HigherAfterEntry>=enterprice*(1+1/100) //成交贏利超過1%,回吐到70%出場
then
begin
price:=EnterPrice+(HigherAfterEntry-EnterPrice)*70/100;
if low<=price then
begin
sell(1,holding,limitr,min(open,price)) ;
count2:=1;
end;
end;
//開空單的平倉
if holding<0 and enterbars>0 then
begin
if enterbars>=1 and lowerAfterEntry<=enterprice*(1-1/100) //成交贏利超過1%,回吐到70%贏利出場
then
begin
price:=EnterPrice - (EnterPrice-LowerAfterEntry)*70/100;
if high>=price then
begin
sellshort(1,holding,limitr,max(open,price)) ;
count2:=1;
end;
end;