是的,开仓这根K操作,一开仓,当根K获利100点就平仓
if 下单条件 then begin
tbuy(tholding=0,1,mkt);
extgbdataset('time',time);
end
//开仓后,当根K获利100点就平仓怎么写
if islastbar and time=EXTGBDATA('time') and c-TENTERPRICE>=100*mindiff then tsell(1,1,mkt);
//如没有获利100点,当根K收盘就平仓
if islastbar and time=extgbdata('time') and c-enterprice<100*mindiff and extgbdata('time')-dynainfo(207)>0 and extgbdata('time')-dynainfo(207)<=2 then
tsell(1,1,mkt);
//这个是想到的思路,需要等明天开盘后进行验证
RUNMODE:1;
cond:=c>o;
cond1:=islastbar and time=EXTGBDATA('time') and c-TENTERPRICE>=100*mindiff;
cond2:=islastbar and time=extgbdata('time') and c-tenterprice<5*mindiff and TIMETOT0(extgbdata('time'))-timetot0(dynainfo(207))>0 and timetot0(extgbdata('time'))-timetot0(dynainfo(207))<=2;
if cond and ISLASTBAR then begin
tbuy(tholding=0,1,mkt);
extgbdataset('time',time);
end
//开仓后,当根K获利100点就平仓怎么写
if cond1 then tsell(1,1,mkt);
//如没有获利100点,当根K收盘就平仓
if cond2 then tsell(1,1,mkt);
DEBUGFILE('d:\test.txt','下单条件是否成立 是 %.0f',cond);
DEBUGFILE('d:\test.txt','平仓条件1是否成立 是 %.0f', cond1);
DEBUGFILE('d:\test.txt','平仓条件2是否成立 是 %.0f',cond2 );
//DEBUGFILE('d:\test.txt','当前k线时间是 是 %.0f',extgbdata('time'));
DEBUGFILE('d:\test.txt','当前k线秒数时间是 是 %.0f',TIMETOT0(extgbdata('time')));
DEBUGFILE('d:\test.txt','当前秒数是 是 %.0f',timetot0(dynainfo(207)));
DEBUGFILE('d:\test.txt','k线走完所剩秒数 是 %.0f',TIMETOT0(extgbdata('time'))-timetot0(dynainfo(207)));
DEBUGFILE('d:\test.txt','开仓价 是 %.0f',tenterprice);
DEBUGFILE('d:\test.txt','最新价 是 %.0f',c);
DEBUGFILE('d:\test.txt','价差 是 %.1f',tenterprice-c);
这个是经过修改测试之后的代码,条件不成立k线结束前平仓已经没有问题,当根k线获利100点这个条件很难成立,所以没有检测到
策略最后的调试代码非常重要,测试条件是否成立。