-- 作者:阿火
-- 发布时间:2012/2/23 8:23:32
--
Input:m(5,1,10,1); Variable: maxprofit=0; Variable: sellnum=1; Variable: buynum=1; ma5:=ma(c,5); ma10:=ma(c,10); Longcond: = cross(ma5,ma10); Shortcond: = cross(ma10,ma5);
if holding>0 then begin if Shortcond and c>enterprice then begin sell(1,holding,thisclose); sellnum:=1; buynum:=1; end if Shortcond and c<enterprice then begin sell(1,holding,thisclose); if sellnum<m then sellnum:=sellnum+1; end end
if holding<0 then begin if Longcond and c<enterprice then begin sellshort(1,holding,thisclose); buynum:=1; sellnum:=1; end if Longcond and c>enterprice then begin sellshort(1,holding,thisclose); if buynum<m then buynum:=buynum+1; end end
if holding=0 then begin if Longcond then begin buy(1,buynum,thisclose); maxprofit:=0; end if Shortcond then begin buyshort(1,sellnum,thisclose); maxprofit:=0; end end
win:=0; win2:=0;
//多头止盈 if holding > 0 and enterbars > 2 then begin win:=(c-enterprice)/enterprice*100; if win > maxprofit then maxprofit:=win; //记录最大盈利 win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度 end
//空头止盈 if holding < 0 and enterbars > 2 then begin win:=(enterprice-c)/enterprice*100; if win > maxprofit then maxprofit:=win; //记录最大盈利 win2:=(maxprofit-win)/maxprofit*100;//最大盈利后的回调幅度 end
//出现浮动亏损比如2%平仓 if holding>0 and win<-2 then begin // and numprofit(1)<0 多止损: sell(1,holding,thisclose); buynum:=1; sellnum:=1; end
if holding<0 and win<-2 then begin 空止损: sellshort(1,holding,thisclose); buynum:=1; sellnum:=1; end
//出现最高盈利后,回落到盈利的60%平仓出场 if holding>0 and win2>=60 and openprofit>0 then begin 多止盈: sell(1,holding,thisclose); buynum:=1; sellnum:=1; end
if holding<0 and win2>=60 and openprofit>0 then begin 空止盈: sellshort(1,holding,thisclose); buynum:=1; sellnum:=1; end
|