以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://222.73.7.161/bbs/index.asp)
--  策略编写求助区  (http://222.73.7.161/bbs/list.asp?boardid=11)
----  [求助]2金币求助一个图表交易系统下的策略编写  (http://222.73.7.161/bbs/dispbbs.asp?boardid=11&id=30719)

--  作者:yuhang
--  发布时间:2012/11/18 20:01:56
--  [求助]请老师帮忙转换模型语言
 周期为15分钟线,看多情况下,当连续2个k线为阳线,且满足:
1.两个K线的开盘值都大于boll指标的mid值;
2.每个K线的收盘值都大于开盘值15个单位以上。
则买入开仓。

采用移动止损方式,买入开仓后

当最大值<(开仓值+60个单位),则止损位=最大值-60个单位;
当(开仓值*1.02)>=最大值>=(开仓值+60个单位),则止损位=开仓值+1个单位;
当最大值>(开仓值*1.02),则止损位=最大值*0.98;
当日内14:45分时,若现值<(开仓值*1.03),则现价平仓;
若现值>(开仓值*1.03),则继续持仓;

日内若止损平仓,则此策略继续循环。

恳请告知,谢谢!

--  作者:jinzhe
--  发布时间:2012/11/19 9:58:17
--  
你好,请耐心等候
--  作者:jinzhe
--  发布时间:2012/11/19 16:26:18
--  

variable:hh=0,cishu=0;
kcond:= c>o and ref(c,1)>ref(o,1) ;
mid_boll:=stkindi(\'\',\'boll.mid\',0,3);
mid_boll2:= stkindi(\'\',\'boll,min\',0,3,-1);
bollcond:= o>mid_boll and ref(o,1)>mid_boll2;
opencond:= c>o+15*mindiff and ref(c,1)>ref(o,1)+15*mindiff;

if kcond and bollcond and opencond and cishu=0 then begin
 buy(holding=0,1,market);
 hh:=h;
 cishu:=1;
 end

if h>hh then hh:=h;

if hh<enterprice+60*mindiff and c<=enterprice*1.03 then begin
 sell(holding>0,0,limitr,hh-60*mindiff);//当最大值<(开仓值+60个单位),则止损位=最大值-60个单位;
 hh:=0;
 cishu:=0;
end

if enterprice*1.02>=hh and hh>=o+60*mindiff and c<=enterprice*1.03 then begin//当(开仓值*1.02)>=最大值>=(开仓值+60个单位),则止损位=开仓值+1个单位;
 sell(holding>0,0,limitr,ENTERPRICE+mindiff);
 hh:=0;
 cishu:=0;
end

if hh>ENTERPRICE*1.02  and c<=enterprice*1.03 then begin//当最大值>(开仓值*1.02),则止损位=最大值*0.98;
 sell(holding>0,0,limitr,hh*0.98);
 hh:=0;
 cishu:=0;
end
if time>144500 and c<enterprice*1.03 then begin //当日内14:45分时,若现值<(开仓值*1.03),则现价平仓;
 sell(holding>0,0,limitr,c);
 hh:=0;
 cishu:=0;
end


--  作者:yuhang
--  发布时间:2012/11/19 16:53:56
--  
非常感谢"jinzhe", 待测试到周五无误后奉送金币!

再次表示感谢!

--  作者:yuhang
--  发布时间:2012/11/19 18:46:35
--  
貌似不行,2012.11.1的9:30和9:45出现两个在mid值以上且符合规则的K线图。但用上述语句却没有指出买入信号,而且用上述语句通过“公式测评”---从股指开通以来至今,竟然没有一个买入信号。(请看附件);

恳请告知具体原因,谢谢!
图片点击可在新窗口打开查看此主题相关图片如下:1.jpg
图片点击可在新窗口打开查看

--  作者:jinzhe
--  发布时间:2012/11/20 9:07:20
--  
你的开多条件有3个,可不光是mid满足就行的
--  作者:yuhang
--  发布时间:2012/11/20 9:43:51
--  
对呀,必须同时满足这些条件才能开仓,如图中方框内的两个连续K线, 均在mid(白线)上方,且每个K线的收盘价均高于开盘价15个单位的,
但用您帮忙编写的策略却查找不到该信号。
而且从2010.5.1~至今,没有显示一个开仓信号。

盼复,谢谢!

--  作者:yh_tl
--  发布时间:2012/11/20 11:53:19
--  

免责声明:本人也是初学者,因为对楼主的止损策略感了兴趣,所以试着写了这个策略,有不对的地方请大家指正。

 

经测试,楼主的第四行止损策略好像有问题?红框处。但总体还可以

 

 

 


图片点击可在新窗口打开查看此主题相关图片如下:1121.png
图片点击可在新窗口打开查看

--  作者:yh_tl
--  发布时间:2012/11/20 11:57:44
--  

源码,我用的K线走完模式:

INPUT:M(26,5,500,30);
INPUT:M(2,0.1,10,1);
INPUT:M(0.2,0.2,10,0.2);

MID :  MA(CLOSE,M);
UPPER: MID + N*STD(CLOSE,M);
LOWER: MID - N*STD(CLOSE,M);

多:=ALL(C>O+15*X,2) AND ALL(O>MID,2);
空:=ALL(C<O-15*X,2) AND ALL(O<MID,2);


if 多 then begin
 sellshort(holding<0, 0, thisclose);
 buy(holding=0 , 1, thisclose);
 end

HH:=HHV(H,BARSLAST(HOLDING<=0));
多止损1:HH<Enterprice+60*X AND C<=HH-60*X ,LINETHICK0;
多止损2:Enterprice*1.02>=HH AND HH>=Enterprice+60*X AND C<Enterprice+2*X ,LINETHICK0;
多止损3:HH>Enterprice*1.02 AND C<HH*0.98 ,LINETHICK0;
多止损4:TIME>144000 AND C<Enterprice*1.03 ,LINETHICK0;

if 多止损1 OR 多止损2 OR 多止损3 OR 多止损4 then sell(holding>0, 0, thisclose);


if 空 then begin
 sell(holding>0, 0, thisclose);
 buyshort(holding=0 , 1, thisclose);
 end

LL:=LLV(L,BARSLAST(HOLDING>=0));
空止损1:LL>Enterprice-60*X AND C>=LL+60*X ,LINETHICK0;
空止损2:Enterprice<=LL*1.02 AND LL<=Enterprice-60*X AND C>Enterprice-2*X ,LINETHICK0;
空止损3:LL*1.02<Enterprice AND C*0.98>LL ,LINETHICK0;
空止损4:TIME>144000 AND C*1.03>Enterprice ,LINETHICK0;

if 空止损1 OR 空止损2 OR 空止损3 OR 空止损4 then sellshort(holding<0, 0, thisclose);


--  作者:yh_tl
--  发布时间:2012/11/20 12:41:45
--  

上面参数错了,更正

INPUT:M(26,5,500,30);
INPUT:N(2,0.1,10,1);
INPUT:X(0.2,0.2,10,0.2);

MID :  MA(CLOSE,M);
UPPER: MID + N*STD(CLOSE,M);
LOWER: MID - N*STD(CLOSE,M);

多:=ALL(C>O+15*X,2) AND ALL(O>MID,2);
空:=ALL(C<O-15*X,2) AND ALL(O<MID,2);


if 多 then begin
 sellshort(holding<0, 0, thisclose);
 buy(holding=0 {AND TIME<144000}, 1, thisclose);
 end

HH:=HHV(H,BARSLAST(HOLDING<=0));
多止损1:HH<Enterprice+60*X AND C<=HH-60*X ,LINETHICK0;
多止损2:Enterprice*1.02>=HH AND HH>=Enterprice+60*X AND C<Enterprice+2*X ,LINETHICK0;
多止损3:HH>Enterprice*1.02 AND C<HH*0.98 ,LINETHICK0;
多止损4:TIME>144000 AND C<Enterprice*1.03 ,LINETHICK0;

if 多止损1 OR 多止损2 OR 多止损3 OR 多止损4 then sell(holding>0, 0, thisclose);


if 空 then begin
 sell(holding>0, 0, thisclose);
 buyshort(holding=0 {AND TIME<144000}, 1, thisclose);
 end

LL:=LLV(L,BARSLAST(HOLDING>=0));
空止损1:LL>Enterprice-60*X AND C>=LL+60*X ,LINETHICK0;
空止损2:Enterprice<=LL*1.02 AND LL<=Enterprice-60*X AND C>Enterprice-2*X ,LINETHICK0;
空止损3:LL*1.02<Enterprice AND C*0.98>LL ,LINETHICK0;
空止损4:TIME>144000 AND C*1.03>Enterprice ,LINETHICK0;

if 空止损1 OR 空止损2 OR 空止损3 OR 空止损4 then sellshort(holding<0, 0, thisclose);