//建立多头的进场条件
long:=h>a and ref(c,1)>line ;
if long then
begin
//tsellshort(holding<0,0,mkt);
sellshort(holding<0,0,marketr);
//tbuy(holding=0,p,mkt)
buy(holding=0,p, limitr ,a);
end
//建立空头的进场条件
short:=l<b and ref(c,1)<line ;
if short then
begin
//tsell(holding>0,0,mkt);
sell(holding>0,0,marketr);
//tbuyshort(holding=0,p,mkt);
buyshort(holding=0,p,limitr,b);
end
//盈亏计算
if enterbars>0 then begin
win1:=(c-enterprice)/enterprice*10000;
if win1>maxprofit then
maxprofit:=win1;
win2:=(maxprofit-win1)/maxprofit*10000;
end
//多头初始浮亏 p1% 止损
if win1<-p1 then
begin
//tsell(1,holding,mkt);
sell(1,holding,marketr);
end
//多头利润大于 p2% 止盈
if win1>p2 then
begin
//tsell(1,holding,mkt);
sell(1,holding,marketr);
end
//多头获利后回撤 p3%止盈
if win2>p3 and openprofit>0 then
begin
//tsell(1,holding,mkt);
sell(1,holding,marketr);
end
//盈亏计算
if enterbars>0 then begin
win1:=(enterprice-c)/enterprice*100;
if win1>maxprofit then
maxprofit:=win1;
win2:=(maxprofit-win1)/maxprofit*10000;
end
//空头初始浮亏超过 p1% 止损
if win1<-p1 then
begin
//tsellshort(1,holding,mkt);
sellshort(1,holding,marketr);
end
//空头利润大于 p2%止盈
if win1>p2 then
begin
//tsellshort(1,holding,mkt);
sellshort(1,holding,marketr);
end
//空头回撤 p3% 止盈
if win2>p3 and openprofit>0 then
begin
//tsellshort(1,holding,mkt);
sellshort(1,holding,marketr);
end
持仓:holding,linethick0;
资产:asset,noaxis;
可用现金:cash(0),linethick0;