你说的平掉三分之一,是指剩余的三分之一?还是什么?
1.先处理下分时均线
n1:=todaybar;
dm:=4-INTPART(LOG(C));
结算价:ROUNDS(IF(sum(vol,n1)=0,C,sum(C*vol,n1)/sum(vol,n1)),2+dm),colorred;
不过这个无法完全等效系统自带的分时均线,但大体上是贴近的。
2.上下穿用cross函数
3.分段平仓。多头为例。
if c-enterprice>=5 and holding>0 then begin
sell(holding>0,holding/3,market);
end
if c-enterprice>=10 and holding<0 then begin
sell(holding>0,holding/2,market);
end
if c-enterprice>=20 and holding<0 then begin
sell(holding>0,holding,market);
end
具体编写细节你可以先自行尝试下。
//分时线数据
n1:=todaybar;
dm:=4-INTPART(LOG(C));
结算价:ROUNDS(IF(sum(vol,n1)=0,C,sum(C*vol,n1)/sum(vol,n1)),2+dm),colorred;
KD:=CROSS( C,结算价 ); //开多条件
if c-enterprice>=5 and holding>0 then begin
sell(holding>0,holding/3,market);
end
if c-enterprice>=10 and holding<0 then begin
sell(holding>0,holding/2,market);
end
if c-enterprice>=20 and holding<0 then begin
sell(holding>0,holding,market);
end; //平多条件
KK:=CROSS( 结算价,C ); //开空条件
if c-enterprice>=-5 and holding>0 then begin
sell(holding>0,holding/3,market);
end
if c-enterprice=-10 and holding<0 then begin
sell(holding>0,holding/2,market);
end
if c-enterprice>=-20 and holding<0 then begin
sell(holding>0,holding,market);
end; //平空条件
PK:=CROSS( 结算价,C );
PD:=CROSS( C,结算价 );
平空:SELLSHORT(PK,9,THISCLOSE); //平空信号
开多:BUY(KD AND HOLDING=0,9,THISCLOSE); //开多信号
平多:SELL(PD,9,THISCLOSE); //平多信号
开空:BUYSHORT(KK AND HOLDING=0,9,THISCLOSE); //开空信号
帮我修改下,平仓都是一次性平仓的,改成分批平仓的
c-enterprice>=-20 你这个是要表达空头盈利20个点?
你改下吧。
enterprice-c>=20
然后就是你相应的语句请改成平空语句,sell是平多 sellshort是平空。
除去上面的问题外,就是你这个思路本身也有特殊情况,期货价格变化不是连续的。如果直接跳到20点以上,自然就会直接全平的了。
还有一个就是 当天收盘前清仓,不留仓过夜,当天持仓当天卖完 怎么加上去
加个这样的语句就行了。 if time=closetime(0) then sell(1,holding,market); 这是平多的。平空的也是一样的。