以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://222.73.7.161/bbs/index.asp)
--  策略编写求助区  (http://222.73.7.161/bbs/list.asp?boardid=11)
----  求编写一策略  (http://222.73.7.161/bbs/dispbbs.asp?boardid=11&id=8005)

--  作者:pepsi
--  发布时间:2011/9/14 8:58:40
--  求编写一策略
用到指标:boll
开多条件:
最新价格向上穿越前一根K线的boll上轨;
平多条件:
1.最新价格向下穿越前一根K线的boll中轨;
2.从开仓的那根K线开始算起,所到过最高点往下跌幅超过N1(将N1设置为一个变量)。
3.当浮动盈利点数最大达到N3个点,启动保本止损策略,价格回到开仓成本价既平仓。
开空条件:
最新价格向下穿越前一根K线的boll下轨;
平空条件:
1.最新价格向上穿越前一根K线的boll中轨;
2.从开仓的那根K线开始算起,所到过最低点往上涨幅超过N2(将N2设置为一个变量)。
3.当浮动盈利点数最大达到N3个点,启动保本止损策略,价格回到开仓成本价既平仓。

--  作者:26327756l
--  发布时间:2011/9/14 9:09:47
--  

问题正在解决中


--  作者:26327756l
--  发布时间:2011/9/14 9:59:43
--  


程序中有失误的地方请见谅。

 

input:N1(1,1,100,1),N2(1,1,100,1),N3(1,1,100,1);
variable:kcp=DRAWNULL,kcprice=DRAWNULL,kz=0;
upp:="boll.UPPER";
mid:="boll.mid";
lower:="boll.lower";
if kcp=DRAWNULL then kcprice:=DRAWNULL; else kcprice:=ENTERPRICE;
//开多最新价格向上穿越前一根K线的boll上轨;

if c>ref(upp,1) then
begin
sellshort(holding<0,holding,market);
buy(holding=0,1,market);
kcp:=BARPOS;
end

//平多条件:
//1,最新价格向下穿越前一根K线的boll中轨;
if c<ref(mid,1) then
begin
sell(holding>0,holding,market);
kcp:=DRAWNULL;
end
//2.从开仓的那根K线开始算起,所到过最高点往下跌幅超过N1(将N1设置为一个变量)。
if hhv(c,BARPOS-kcp)-c>N1 then
begin
sell(holding>0,holding,market);
kcp:=DRAWNULL;
end
//3.当浮动盈利点数最大达到N3个点,启动保本止损策略,价格回到开仓成本价既平仓。
if OPENPROFIT/MINDIFF=N3 then kz:=1;
if kz=1 and c=kcprice then
begin
sell(holding>0,holding,market);
kcp:=DRAWNULL;
kz:=0;
end

//开空条件:
//最新价格向下穿越前一根K线的boll下轨;

if c<ref(lower,1) then
begin
SELL(holding>0 ,holding ,market );
buyshort(holding=0,1,market);
kcp:=BARPOS;
end

 

//平空条件:
//1.最新价格向上穿越前一根K线的boll中轨;
if c>ref(mid,1) then
begin
sellshort(holding<0,holding,market);

end
//2.从开仓的那根K线开始算起,所到过最低点往上涨幅超过N2(将N2设置为一个变量)。
if c-llv(c,BARPOS-kcp)>N2 then
begin
sellshort(holding<0,holding,market);
kcp:=DRAWNULL;
end
//3.当浮动盈利点数最大达到N3个点,启动保本止损策略,价格回到开仓成本价既平仓。
if OPENPROFIT/MINDIFF=N3 then kz:=1;
if kz=1 and c=kcprice then
begin
sellshort(holding<0,holding,market);
kcp:=DRAWNULL;
kz:=0;
end


--  作者:pepsi
--  发布时间:2011/9/14 10:22:48
--  

非常感谢您的及时回复。

但是此策略在测试的时候不正常,所有开仓单,在开仓以后马上平仓了,结果是永远亏了手续费。

我认为您在这一点写的不对:

//2.从开仓的那根K线开始算起,所到过最高点往下跌幅超过N1(将N1设置为一个变量)。
if hhv(c,BARPOS-kcp)-c>N1 then
begin
sell(holding>0,holding,market);
kcp:=DRAWNULL;
end
“BARPOS”是指在从有K线数据以来到当前K线的周期数,而我们要的是从开仓的那根K线算起,到当前K线的周期数。

我认为该这么写:

exl1=:(hhv(h,enterbars)-enterprice)>n1;  //从开仓的那根K线开始算起,所到过最高点往下跌幅超过N1(将N1设置为一个变量)。


--  作者:fly
--  发布时间:2011/9/14 10:25:51
--  
恩,直接用系统自带函数enterbars和enterprice即可.
--  作者:pepsi
--  发布时间:2011/9/14 11:14:12
--  
恩。
[此贴子已经被作者于2011-9-14 11:14:24编辑过]

--  作者:pepsi
--  发布时间:2011/9/14 11:35:39
--  

我自己也写了个,未达到效果,帮忙看看啊,谢谢!

 

input:m(26,5,200,1),n(2,0.1,10,0.1),n1(50,0,100,1);
MID :=MA(CLOSE,M);
UPPER:=MID + N*STD(CLOSE,M);
LOWER:=MID - N*STD(CLOSE,M);
enlong:=cross(c,ref(upper,1));
//开多条件,最新价上穿前一根K线的BOLL上轨
exlong1:=cross(ref(mid,1),c);
//平多条件1,最新价下穿前一根K线的BOLL中轨
enshort:=cross(ref(lower,1),c);
//开空条件,最新价下穿前一根K线的boll下轨
exshort:=cross(c,ref(mid,1));
//平空条件1,最新价上穿前一根K线的BOLL中轨
exlong2:=(hhv(h,enterbars)-enterprice)>n1 and cross(enterprice,c);
//平多条件2,最大浮动盈利达N1点,并且价格回到开仓价位
exshort2:=(enterprice-llv(l,enterbars))>n1 and cross(c,enterprice);
//平空条件2,最大浮动盈利达N1点,并且价格回到开仓价位
exl2:(hhv(h,enterbars)-enterprice)>n1 and cross(enterprice,c),linethick0;
exs2:(enterprice-llv(l,enterbars))>n1 and cross(c,enterprice),linethick0;
if exlong1 or exlong2 then
sell(holding=1,0,market);

if exshort or exshort2 then
sellshort(holding=-1,0,market);

if enlong then
buy(holding=0,1,market);

if enshort then
buyshort(holding=0,1,market);

[此贴子已经被作者于2011-9-14 11:38:38编辑过]

--  作者:pepsi
--  发布时间:2011/9/14 12:16:39
--  

图片点击可在新窗口打开查看

从图中可以看出,十字光标所在的位置是将空单平仓的操作,实际上此处并不满足我们的平仓条件,从左上角看出是exs2的值为1。

不理解在此位置exs2的条件怎么会成立呢?求解

 


--  作者:fly
--  发布时间:2011/9/14 15:32:14
--  

把你的exs2再进一步分解,看看条件--肯定是满足的.

exs2:(enterprice-llv(l,enterbars))>n1 and cross(c,enterprice),linethick0;

 

调试技巧参考这里方法1http://www.weistock.com/bbs/dispbbs.asp?boardid=4&id=1246&page=1&star=1


 


--  作者:pepsi
--  发布时间:2011/9/16 10:58:02
--  

exs2:(enterprice-llv(l,enterbars))>n1 and cross(c,enterprice),linethick0;

是两个条件语句用and连接起来的,要两个条件同时满足exs2的返回值才是一,所以,exs2是不是不能再分解了。

我认为and连接的不能分解,OR连接的可以分解,对吗