以文本方式查看主题

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

--  作者:jjjfk
--  发布时间:2017/3/23 9:02:41
--  请问这个策略哪里编写有问题?

源代码:

 

variable:bj=0;                                    //全局变量

 

//做多部分

 

tr1 : max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));

atr : ma(tr1,20);                               //atr公式

 

ma20:ma(close,20);                               //20日均线

 

a1:=0.01*valuewhen(barpos=1,asset);              //初始资金的1%

 

a2:=floor(a1/(2*atr));                         //开仓手数

 

a3:=ref(hhv(high,20),1);                       //20日高点

 

if holding=0 and close>a3 and close>ma20 and bj=0

then begin

buy(1,a2,marketr);

bj:=1;

end                                   //第一次开仓

 

a4:=enterprice+2*atr;

if holding>0 and close>a4 and bj=1

then begin

buy(1,a2,marketr);

end                                  //第n次开仓

 

a5:=enterprice-2*ref(atr,enterbars=1);

if holding=1 and low<=a5

then begin

sell(1,0,limitr,a4);

end                                   //第一次开仓的离场  

 

 

e1:=ref(enterprice,enterbars);

e2:=ref(e1,enterbars);

e3:=(e1+e2)/2;

if holding>1 and close<e3

then begin

sell(1,0,marketr);

end                                     //第n次开仓离场,即:收盘<("holding=n"与“holding=n-1”)/2的位置        

 

 

 

//做空部分

 

a1:=0.01*valuewhen(barpos=1,asset);              //初始资金的1%

 

a2:=floor(a1/(2*atr));                         //开仓手数

 

a6:=ref(llv(low,20),1);                       //20日低点

 

if holding=0 and close<a6 and close<ma20 and bj=0

then begin

buyshort(1,a2,marketr);

bj:=1;

end                                   //第一次开仓

 

a7:=enterprice-2*atr;

if holding<0 and close<a7 and bj=1

then begin

buyshort(1,a2,marketr);

end                                  //第n次开仓

 

a8:=enterprice+2*ref(atr,enterbars=1);

if holding=1 and high>=a8

then begin

sellshort(1,0,limitr,a8);

end                                   //第一次开仓的离场  

 

 

e1:=ref(enterprice,enterbars);

e2:=ref(e1,enterbars);

e3:=(e1+e2)/2;

if holding<-1 and close>e3

then begin

sellshort(1,0,marketr);

end                                     //第n次开仓离场,即:收盘>"holding=n"与“holding=n-1”)/2的位置

 

测试结果:


此主题相关图片如下:图片1.jpg
按此在新窗口浏览图片

此主题相关图片如下:图片2.png
按此在新窗口浏览图片

问题:

1.从2009年测试至今,为什么只交易了一次,其他条件都没成立?

2.第二次开仓与第一次开仓点位相差根本不多,为什么开仓手数相差了一倍?

3.随后的平仓都还没有到达平仓条件怎么就被平掉了?


--  作者:yukizzc
--  发布时间:2017/3/23 9:08:41
--  

1、自己在图上输出下交易条件,然后进行下分析。很多问题不要一看到问题自己不做调试,图标的调试非常容易的比如cond1:c>0;这种就是一个条件了

2、自己在图上输出下手数看是数字几,然后分析下,为何两次的数值差那么多