老是有人希望提前N秒下单
在此提供一种自己编写的方法
适用于各个周期,注意:选用固定时间间隔模式
2011-12-26 做了更新,给出了不规律周期的K线结束时间
//这里以股指期货为例,商品原理类似:关键是找出K线结束的时间规律。
ma5:=ma(c,5);
ma10:=ma(c,10);
zq:=2;//周期类型,2分钟就填2,3分钟就填3 ,5分钟就填5
tq:=5;//提前的秒数,最多提前60秒
lastopentm:=if(date<>ref(date,1),0,ref(openminutes(time),1));//上一根K线的开盘分钟数
ticktm:=dynainfo(207);
abb:=(mod(ticktm,100)>=60-tq and (openminutes(ticktm)-lastopentm=zq-1 or (ticktm>=112900 and ticktm<=113000) or (ticktm>=151400 and ticktm<=151500))) or not(islastbar);
if abb then begin
if holding>0 and ma5<ma10 then sell(1,1,thisclose);
if holding<0 and ma5>ma10 then sellshort(1,1,thisclose);
if holding=0 and ma5>ma10 then buy(1,1,thisclose);
if holding=0 and ma5<ma10 then buyshort(1,1,thisclose);
end
大家注意了
2.80版本以上,time这个函数有所变化,直接可以直接获得K线结束的时间。提前下单更加方便了
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 ma5<ma10 then sell(1,1,thisclose);
if holding<0 and ma5>ma10 then sellshort(1,1,thisclose);
if holding=0 and ma5>ma10 then buy(1,1,thisclose);
if holding=0 and ma5<ma10 then buyshort(1,1,thisclose);
end
time=113000 or time=151500 ,不同的品种收盘时间,这里自己要改一改。
还有商品在101500有休盘,这里的K线结束时间,也根据自己的周期相应修改
原理也很简单:就是找出每根K线结束的时间点,然后用currenttime或者dynainfo(207)去控制下单时机
这就是你模型问题了。
一般下单只会在 holding变化时才下单,比如:由holding=0变化为holding=1 开多单
其它不规则的周期可能比较麻烦,但5分钟周期很有规律,不会有问题的
请问火哥,能用于六十分钟周期的吗?
对于商品,60分钟K线结束的位置是以下几个 10:00 11:00 14:00 15:00
用一下即可:
ma5:=ma(c,5);
ma10:=ma(c,10);
abb:=(mod(dynainfo(207),100)>55 and islastbar and (time=100000 or time=110000 or time=140000 or time=150000)) or not(islastbar);
if holding>0 and ma5<ma10 and abb then sell(1,1,thisclose);
if holding<0 and ma5>ma10 and abb then sellshort(1,1,thisclose);
if holding=0 and ma5>ma10 and abb then buy(1,1,thisclose);
if holding=0 and ma5<ma10 and abb then buyshort(1,1,thisclose);