以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  策略编写求助区  (http://weistock.com/bbs/list.asp?boardid=11)
----  [求助][讨论]股指日内交易  (http://weistock.com/bbs/dispbbs.asp?boardid=11&id=9904)

--  作者:人生如棋
--  发布时间:2012/2/10 17:06:21
--  [求助][讨论]股指日内交易

请大侠们我编个程序

股指日内交易

条件以下

 

1.开仓条件:大于等于开盘价10个点就做多,小于等于10个点就做空;这是开仓条件

2.止损:20个点止损

3.止赢:按时间止赢,15:10分

4.一天就做一次

5.不按k线走完模型,就是最高最低价碰到就开仓,平仓也是同理


--  作者:人生如棋
--  发布时间:2012/2/10 18:57:36
--  
想了下好像写出来了,我自己把模型发出来。但最后一条,

//5.不按k线走完模型,就是最高最低价碰到就开仓,平仓也是同理

请高手解决下。//

variable:次数=1;
Dayopen:valuewhen(date<>ref(date,1),o);
上规线:Dayopen+10;
下规线:Dayopen-10;
多开:=h>上规线;
空开:=l<下规线;
//交易时间区间
交易时间:=if(time>091500 and time<=151300,1,0);
//交易开始加仓
if 交易时间>0  and 次数=1 then
begin
buy(holding=0 and 多开,1,thisclose);
buyshort(holding=0 and 空开,1,thisclose);
end

//正常交易过程
if 交易时间>0 then
begin
if l<下规线 then
begin
sell(holding>0,0,thisclose);
次数:=0;
end
if h>上规线 then
begin
sellshort(holding<0,0,thisclose);
次数:=0;
end
end

//收盘前清仓
if time>=151000 then
begin
sellshort(holding<0,0,thisclose);
sell(holding>0,0,thisclose);
次数:=1;
end


持仓:holding,colorwhite,linethick0;
交易总数:totaltrade,colorwhite,linethick0;
盈亏:asset-1000000,noaxis,colorred,linethick1;

 


--  作者:zg611029
--  发布时间:2012/2/11 22:59:27
--  

我给过你类似的模型,结果不好。再有为什么要限制交易次数?这在策略设计时是没有道理的。

variable:a1=0;

r1:=barslast(day-ref(day,1)<>0);

r2:ref(o,r1);

r3:r2+10;

r4:r2-10;

r5:=time>091500 and time<151000;

if cross(h,r2) and r5 and holding=0 and a1=0 then

     begin

     buy(1,1,limitr,r3)

     end

if cross(r4,l) and r5 and holding=0 and a1=0 then

     begin

     buyshort(1,1,limitr,r4);

     end

if holding>0 and cross(r4,l) and r5 then

     begin

     sell(1,0,limitr,r4);

     a1:=1;

     end

if holding<0 and cross(h,r3) and r5 then

     begin

     sellshort(1,0,limitr,r3);

     a1:=1;

     end

if time>=151000 and holding<>0 then

     begin

     sell(holding>0,0,thisclose);

     sellshort(holding<0,0,thisclose);

     a1:=1;

     end

以上的代码用于测试,实际交易时用如下代码:

variable:a1=0;

r1:=barslast(day-ref(day,1)<>0);

r2:ref(o,r1);

r3:r2+10;

r4:r2-10;

r5:=time>091500 and time<151000;

if cross(c,r2) and r5 and holding=0 and a1=0 then

begin

buy(1,1,limitr,r3)

end

if cross(r4,c) and r5 and holding=0 and a1=0 then

begin

buyshort(1,1,limitr,r4);

end

if holding>0 and cross(r4,c) and r5 then

begin

sell(1,0,limitr,r4);

a1:=1;

end

if holding<0 and cross(c,r3) and r5 then

begin

sellshort(1,0,limitr,r3);

a1:=1;

end

if time>=151000 and holding<>0 then

begin

sell(holding>0,0,thisclose);

sellshort(holding<0,0,thisclose);

a1:=1;

end

以上代码没有测试,估计不会有大问题,


--  作者:zg611029
--  发布时间:2012/2/11 23:11:02
--  

我理解你限制明天只交易一次,是为了抓单边市。如果这样你用SAR的思路可能更好。试试看吧

 


--  作者:zg611029
--  发布时间:2012/2/12 14:57:40
--  

把你的思路改了一下,下面的代码可以实用,长期使用肯定亏不了钱,但也赚不了大钱。建议用5分钟周期

 

 

 

//股指期货自动交易程序
//编制:zg611029 qq:2313936161

input:n(13,5,30,1);

//交易手数:
tn:=1;

r1:=barslast(day-ref(day,1)<>0);

r5:ref(o,r1);
r6:r5+n;
r7:r5-n;

if cross(h,r6)  then
 begin
 buy(holding=0,tn,limitr,r6);
 end
if cross(r7,l) then
 begin
 buyshort(holding=0,tn,limitr,r7);
 end
if holding>0 and cross(r5,l) then
 begin
 sell(1,0,limitr,r5);
 end
if holding<0 and cross(h,r5) then
 begin
 sellshort(1,0,limitr,r5);
 end
  
//收盘前清仓
if time>=151400 then
 begin
 sellshort(holding<0,0,thisclose);
 sell(holding>0,0,thisclose);
 end
 
持仓:holding,colorwhite,linethick0;
交易总数:totaltrade,colorwhite,linethick0;
盈亏:asset-1000000,noaxis,colorred,linethick1;


 


--  作者:朱饭饭
--  发布时间:2012/2/15 10:55:10
--  
图片点击可在新窗口打开查看,随便来看看有没有能带走的
--  作者:rushtaotao
--  发布时间:2012/2/16 11:00:22
--  答复

您可以通过每隔几秒钟去检测,是否满足条件,来完成此操作,弊端就是,比如一旦在一根K线中,检测到10次满足,信号会出现10次,但是只有在第一次信号的时候开仓,但是后面9次都不开,除非就是下一根K线的时候再有信号再开了


--  作者:rushtaotao
--  发布时间:2012/2/16 14:00:37
--  
或者您可以用启用交易时自带的一个“走完一根K线”或者“固定间隔时间”