//当满足反手条件时,如果前面3次连续亏损,第4次开仓时将ss*2,
//之后当多开的部分的利润弥补了前3次的亏损时,平掉多开的部分。(实际持仓手数只剩2手)。
Input :lost(100, 1, 1000, 1) ; //止损的最小变动价位数目
Input : Profit(500, 1, 2000, 1) ;
资产 := ASSET, noaxis ;
VARIABLE : myEnterPrice = 0 ; //开仓的价格
VARIABLE : myExitPrice = 0 ; //平仓的价格
VARIABLE : myStopPrice = 0 ; //初始的止损价格
VARIABLE : _DEBUG = 1 ; //是否输出前台交易指令
VARIABLE : cc = 0 ; //持有仓位的状态
VARIABLE : pro =0;
variable:n=0;
variable:ks=0;
variable:ss=2;
variable:biaoji=0;
long:= o>ma(c,50)+1*MINDIFF ;
short:= o<ma(c,50)-1*MINDIFF ;
IF HOLDING=0 THEN BEGIN //若持仓为0
IF long and C>O THEN BEGIN //且TMP<=0
BUY(1,ss,LIMITR,CLOSE); //开多单
END
IF short THEN //且TMP>0
BUYSHORT(1,ss,LIMITR,CLOSE); //开空单
END
IF HOLDING>0 and biaoji=0 THEN BEGIN //若持有多单
IF short THEN BEGIN //且TMP>0
SELL(1,HOLDING,LIMITR,CLOSE); //平多单
if numprofit(1)>=0 then begin
ks:=0;
n:=0;
end
if numprofit(1)<0 then begin
ks:=ks+numprofit(1);
n:=n+1;
end
if n=3 then BUYSHORT(1,ss*2,LIMITR,CLOSE),COLORGREEN; //开空单
if n<>3 then buyshort(1,ss,limitr,close);
END
end
IF HOLDING<0 and biaoji=0 THEN BEGIN //若持有空单
IF long and C>O THEN BEGIN //且TMP<=0
SELLSHORT(1,HOLDING,LIMITR,CLOSE); //平空单
if numprofit(1)>=0 then begin
ks:=0;
n:=0;
end
if numprofit(1)<0 then begin
ks:=ks+numprofit(1);
n:=n+1;
end
if n=3 then BUY(1,ss*2,LIMITR,CLOSE),COLORRED; //开多单
if n<>3 then buy(1,ss,limitr,close);
END
end
if n=3 and ss=2 and biaoji=0 then begin
biaoji:=1;
end
if openprofit/2>=abs(ks) and n=3 and holding>0 and biaoji=1 then begin
sell(1,holding/2,market);
biaoji:=0;
n:=0;
end
if openprofit/2>=abs(ks) and n=3 and holding<0 and biaoji=1 then begin
sellshort(1,holding/2,market);
biaoji:=0;
n:=0;
end