以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  请合并两个策略  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=51627)

--  作者:okmijn365
--  发布时间:2013/5/3 14:54:34
--  请合并两个策略

以下两个策略都能独立编译运行,但合并成一个后应用于同一标的会导致错误的提前卖出(本人能力达不到,主要是两个策略合并后买入卖出的数量、时间不能互相干扰),请高手帮忙合并一下,使其能形成单一策略顺利进行回测。谢谢。

 

//策略1.

if ref(c,1)>ref(c,2) then buy(1,100%,limitr,o);//当昨日收阳买入。

if holding>0 and enterbars>=1 and c>=enterprice then sell(1,100%,thisclose);//买入后赚钱就卖。

if holding>0 and enterbars=3 then sell(1,100%,thisclose);//3个bar不管输赢都卖掉。

 

 

//策略2

if ref(c,2)>ref(c,3) then buy(1,100%,limitr,o); //当前日收阳买入。(注意本买入条件将于于策略1买入的后一日成立)

if holding>0 and enterbars>=1 and c>=enterprice then sell(1,100%,thisclose);//买入后赚钱就卖。

if holding>0 and enterbars=2 then sell(1,100%,thisclose);//2个bars不管输赢卖掉。

 


图片点击可在新窗口打开查看此主题相关图片如下:未命名.jpg
图片点击可在新窗口打开查看
附件图片示意


--  作者:jinzhe
--  发布时间:2013/5/3 15:01:44
--  
策略合并,把合并后的策略思路说一下,简单的合并不一定有意义
--  作者:okmijn365
--  发布时间:2013/5/3 16:36:40
--  

就是上述分策略讲的。

合并缘由是本来只有策略1,后来我发现在策略1的买入bar的下一个bar还可以再次获取一次机会。因此有了策略2.

策略1和2只是买入相差一bar,卖出时限是一致的。策略1是最多3bar卖出,策略2于是就是最多2bar卖出.

 

要说里面的理论意义,就是赌策略1买日后的下一个bar的O和C之间存在大概率多头价差。


--  作者:klc
--  发布时间:2013/5/3 17:52:52
--  

globalvariant:hold1=0,hold2=0;

//策略1.

if holding>0 and hold1>0 and enterbars>=1 and c>=enterprice then

begin

  hold1:=hold1-1;

  sell(1,100%,thisclose);//买入后赚钱就卖。

end;

if holding>0 and hold1>0 and enterbars=3 then

begin

  hold1:=hold1-1;

  sell(1,100%,thisclose);//3个bar不管输赢都卖掉。

end; 

if ref(c,1)>ref(c,2) then

begin

  hold1:=hold1+1;

  buy(1,1,limitr,o);//当昨日收阳买入。

end;

 

策略2你用相同的原理改写,注意全局变量用hold2那个

 

另外,最好遵循先平后开原则,当然你要先开后平也行,只是容易弄不好


--  作者:okmijn365
--  发布时间:2013/5/3 19:55:31
--  

LS兄弟的不行。

问题出在:当策略1头一日买入后要次日+红盘两个条件才能卖出 即 enterbars>=1 and c>enterprice

而策略2的买入日就是策略1的次日。此时enterbars已经被刷新了。当日=策略2的买入日=本意策略1的卖出日其enterbars值已经不是1而是0了。

因此策略1的所有卖出都被推迟了一日。

 

不知道如何来替代enterbars 的作用

 

 


--  作者:klc
--  发布时间:2013/5/4 21:33:13
--  

哦,我明白你的意思了,我忽略了你用了这个条件,这种情况下无法用enterbars,因为他只表示最近信号的了,你还可以用我的办法,只是要继续用超全局变量了:

globalvariant:hold1=0,hold2=0,enterbars1=-1,enterbars2=-1,enterprice1=0,enterprice2=0;

//策略1.

enterbars1:=enterbars1+1;

if holding>0 and hold1>0 and enterbars1>=1 and c>=enterprice1 then

begin

  hold1:=hold1-1;

  enterbars1:=0;

  enterprice1:=c;

  sell(1,100%,thisclose);//买入后赚钱就卖。

end;

if holding>0 and hold1>0 and enterbars=3 then

begin

  hold1:=hold1-1;

  sell(1,100%,thisclose);//3个bar不管输赢都卖掉。

end; 

if ref(c,1)>ref(c,2) then

begin

  hold1:=hold1+1;

  buy(1,1,limitr,o);//当昨日收阳买入。

end;

 

策略2你用相同的原理改写,应该不用我写给你了


--  作者:klc
--  发布时间:2013/5/4 21:33:43
--  
对了,忘记说了,好像要勾上“仅刷最后一根K线”
--  作者:okmijn365
--  发布时间:2013/5/6 13:50:46
--  

多谢指点。

虽然上面你那个程序还是不行,但是我已经明白了。


--  作者:klc
--  发布时间:2013/5/6 23:05:33
--  

呵呵,最重要就是你明白,我写的也没测试,只是表示个意思,我刚才也看了,至少拼写就错了globalvariant,不好意思