版主,我做了一个没有亏单的程序,但回试时发现了好多亏单,帮我看一下
if 开仓价<C+30 then begin //当平仓价格大于开仓价30个点 才能平仓
if holding>0 and 平多标记 then sell(1,1,thisclose); //平多
end
IF holding=0 and 开多标记 THEN BEGIN
多开:BUY(1=1,ORDVOL,MARKET); // 开多
开仓价:=ENTERPRICE; //将开仓价保存
END
ma1:ma(c,5);
ma2:ma(c,10);
开标:=cross(ma1,ma2);
平标:=cross(ma2,ma1);
//--------------------------共用变量
VARIABLE:Z3B1:=1; {赚3保1开关,一个点保本的才能适用}
VARIABLE:仓内订单:=1; //持仓
VARIABLE:开仓价:=1; // 第一手单 开仓价格
ORDVOL:=1; {开仓手数}
//---------------------------------------
平多标记:=平标;//开标;
平空标记:=0;
开多标记:=开标;// and t1;
开空标记:=0;// and t1;
//-------------------------- 平多 止盈 止损处理
if 开仓价<C+30 then begin
// 策略2;
if holding>0 and 平多标记 then sell(1,1,thisclose); //平多
end
IF holding=0 and 开多标记 THEN BEGIN //BUY1
多开:BUY(1=1,ORDVOL,MARKET); // 现价平仓 能提前3秒下单?
开仓价:=ENTERPRICE; //将开仓价保存到最高价
END
//--------------------------开空
//ma5:=ma(c,5);
//ma10:=ma(c,10);
//input:tq(5,3,60,1);
//abb:=(time0-timetot0(dynainfo(207))<=tq) or not(islastbar);
//if abb then begin
// if holding>0 and 平多标记 then sell(1,1,thisclose); //平多
if holding<0 and 平空标记 then sellshort(1,1,thisclose);//平空
// if holding=0 and 开多标记 then buy(1,1,thisclose);//开多
if holding=0 and 开空标记 then buyshort(1,1,thisclose);//开多
//end
当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;
开仓价<C+30
这个不能保证不亏损。比如开仓价是2000,close是1980,在其他条件满足的情况,平仓是会亏的
那要怎么样保证不亏损呢,我要大于30 个点才平,小于是不平的
开仓价能记录得准吗,如果记录得准,那平仓价,我就在达到条件后,写死30 个点上方,只要回来就可以平了,那么最差的单也就是30 个点的利润
开仓价是2000,close是1980,这能算达到平仓条件?
这样写不是当时价格为2030才达到条件吗
开仓价<=C-30