均线交叉模型(K线走完模型):
runmode:0;
ma5:=ma(c,5);
ma20:=ma(c,20);
entertime:=time>091600 and time<151400;
if holding>0 and ma5<ma20 then sell(1,1,limitr,o);
if holding<0 and ma5>ma20 then sellshort(1,1,limitr,o);
if holding=0 and ma5>ma20 and entertime then buy(1,1,limitr,o);
if holding=0 and ma5<ma20 and entertime then buyshort(1,1,limitr,o);
if time>=151400 then begin
sell(1,1,market);
sellshort(1,1,market);
end
在这个例子中除了收盘平仓用市价以外,其他的开平都使用的是信号产生的那根K线的开盘价,这在测试的时候是能通过的,但实际交易中
K线走完以后,显然你不可能立即回到过去以该K线的开盘价成交。
现在的问题是,我希望在K线走完信号确定以后,以产生信号的那根K线的开盘价下单,挂单交易,比如股指,产生买入信号的那根K线开盘价是2100,收盘价是2102,
现在K线走完,信号确定了,我下一个2100的限价单,这个单有可能要等个三五分钟成交,也有可能成交不了(为了简化问题,这个暂不考虑)
那么这个程序测试应该怎么写?实盘又该怎么写?
我也看过阿火秘籍中的K线走完改轮询的例子,但我说的这个和他那个问题还不一样,我这个问题的关键是挂单交易
没有触发价格?下单日志看看
你说的是要以信号产生的开盘价限价交易,然后实际情况限价不对是吧?
发下单日志
runmode:0;
ma5:=ma(c,5);
ma20:=ma(c,20);
entertime:=time>091600 and time<151400;
o1:valuewhen(holding=0 and ma5>ma20 and entertime,open);
o2:valuewhen(holding=0 and ma5<ma20 and entertime,open);
if holding>0 and ma5<ma20 then sell(1,1,limitr,o);
if holding<0 and ma5>ma20 then sellshort(1,1,limitr,o);
if holding=0 and ma5>ma20 and entertime then buy(1,1,limitr,o1),IGNORECHECKPRICE;
if holding=0 and ma5<ma20 and entertime then buyshort(1,1,limitr,o2),IGNORECHECKPRICE;
if time>=151400 then begin
sell(1,1,market);
sellshort(1,1,market);
end
看看这个记录的O1和O2效果怎么样
runmode:0;
ma5:=ma(c,5);
ma20:=ma(c,20);
entertime:=time>091600 and time<151400;
o1:=valuewhen(holding=0 and ma5>ma20 and entertime,open);
o2:=valuewhen(holding=0 and ma5<ma20 and entertime,open);
nn1:=barslast(holding=0 and ma5>ma20 and entertime);
nn2:=barslast(holding=0 and ma5<ma20 and entertime);
drawicon(holding=0 and ma5>ma20 and entertime,close,4);
drawicon(holding=0 and ma5<ma20 and entertime,close,5);
//if holding>0 and ma5<ma20 then sell(1,1,limitr,o);
//if holding<0 and ma5>ma20 then sellshort(1,1,limitr,o);
if h>=o1 and l<=o1 and nn1>1 then buy(holding=0,1,limitr,o1),IGNORECHECKPRICE;
if h>=o2 and l<=o2 and nn2>1 then buyshort(holding=0,1,limitr,o2),IGNORECHECKPRICE;
if time>=151400 then begin
sell(1,1,market);
sellshort(1,1,market);
end
取消掉了常规平仓免得看不清信号,看看现在的效果