我参照别人的程序写了个简单股指期货日内交易程序,但是还是有问题,请老师帮忙指导,检查改正下错误,谢谢。
策略:9:15分钟股指期货开盘,以1分钟为K线,到9:30分钟,判断这前15分钟的最高价与最低价,9:30分01秒起,若当前价高于最高价则开盘,若低于最低价则开空,止损8点(40个价位),止赢20点(100个价位),每天只开仓一次,也就是开盘了就不再开空,反之也是。15:00钟,如还有持仓,则平,如无持仓,也结束一切交易(也就是如果前面没有达到开仓条件也不再开仓)。
下面是参照别人的改的,请老师指正,谢谢。
input:n(2,1,100);
variable:n1=0;//计算次数
M:=BARSLAST(DATE<>REF(DATE,1))+1;
zuigao:valuewhen(time<=093000,hhv(h,M));//前15分钟最高价
zuidi:valuewhen(time<=093000,llv(l,M));//前15分钟最高价
if h>zuigao and M>15 and n1=0 and time<151500 then begin
buy(holding=0,1,market);
n1:=1;
end
if l<zuidi and M>15 and n1=0 and time<151500 then begin
buyshort(holding=0,1,market);
n1:=1;
end
if c-enterprice>=8 and holding<0 then sellshort(holding<0,0,market);
if enterprice-c>=8 and holding>0 then sell(holding>0,0,market);//止损
if c-enterprice>=20 and holding>0 then sell(holding>0,0,market);
if enterprice-c>=20 and holding<0 then sellshort(holding<0,0,market);//止盈
if time>=150000 then begin
sell(holding>0,0,market);
sellshort(holding<0,0,market);
n1:=0;
end
if datatype<>1 then exit;
我重新改动了一下,感觉基本可以用了。但测试当日时,不知为何赢利可达7220元(我是止赢20个点,6000元),亏抽也是3440元(我是止损8个点,2400元),不知为何有这样大的相差。改动如下,请老师指正,谢谢:
input:ss(1,1,100,1);//交易手数
variable:n1=0;//计算次数
N:=BARSLAST(DATE<>REF(DATE,1))+1;
HH:valuewhen(time<=093000,hhv(h,N));//前15分钟最高价
LL:valuewhen(time<=093000,llv(l,N));//前15分钟最高价
if h>HH and time>093000 and n1=0 and time<150000 then begin
buy(holding=0,ss,market);
n1:=1;
end
if l<LL and time>093000 and n1=0 and time<150000 then begin
buyshort(holding=0,ss,market);
n1:=1;
end
if c-enterprice>=8 and holding<0 then sellshort(holding<0,0,market);
if enterprice-c>=8 and holding>0 then sell(holding>0,0,market);//止损
if c-enterprice>=20 and holding>0 then sell(holding>0,0,market);
if enterprice-c>=20 and holding<0 then sellshort(holding<0,0,market);//止盈
if time>=150000 then begin
sell(holding>0,0,market);
sellshort(holding<0,0,market);
n1:=0;
end
if datatype<>1 then exit;
这种图表交易用的是K线中的价格,不会那么精确的。
如果你需要尽可能的精确的数据,那么就因该使用更小的周期进行测试