以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  求救,策略源码始终没有多单信号  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=13773)

--  作者:lcgs005
--  发布时间:2012/8/19 18:49:47
--  求救,策略源码始终没有多单信号

//求救啊,始终没有多单信号,不知原因

//策略原理:先求出macd与diff大于0的最高值,和小于0的最低值,在高值处开空仓,低值处开多仓,在运行过程中若有盈利,止盈,否则运行完整个macd高值--diff低值后再平仓

//基础线
DIFF:=EMA(CLOSE,12) - EMA(CLOSE,26),coloryellow;
DEA:=EMA(DIFF,9),colorwhite;
MACD:=2*(DIFF-DEA);
//macd高值合并计算部份
a1:=cross(macd,0);
a11:=sumbars(a1,1);
//a12:=hhvbars(macd,a11);
a13:=macd=hhv(macd,a11);
a14:=backset(a13 ,a11);
a15:=a14=0 and ref(a14,1);
a16:=sumbars(a15,1);
a17:=sumbars(a15,2);
a2:=cross(0,macd);
a21:=sumbars(a2,1);
//a22:=llvbars(macd,a21);
a23:=macd=llv(macd,a21);
a24:=backset(a23 ,a21);
a25:=a24=0 and ref(a24,1);
a26:=sumbars(a25,1);
a27:=sumbars(a25,2);
mhbzt:=a16>a26;
//diff高值合并计算部份
c1:=cross(diff,0);
c11:=sumbars(c1,1);
c12:=hhvbars(diff,c11);
c13:=diff=hhv(diff,c11);
c14:=backset(c13 ,c11);
c15:=c14=0 and ref(c14,1);
c16:=sumbars(c15,1);
c17:=sumbars(c15,2);
c2:=cross(0,diff);
c21:=sumbars(c2,1);
c22:=llvbars(diff,c21);
c23:=diff=llv(diff,c21);
c24:=backset(c23 ,c21);
c25:=c24=0 and ref(c24,1);
c26:=sumbars(c25,1);
c27:=sumbars(c25,2);
dhbzt:=c16>c26;
//当mhbzt下穿0轴时若已盈利,则平仓,否则走完dhbzt后再平仓
ms:=cross(mhbzt,0.5);
mx:=cross(0.5,mhbzt);
ds:=cross(dhbzt,0.5);
dx:=cross(0.5,dhbzt);
//开多单
buy(ms,1,market);
//中间若有盈利则在mx时止盈
sell(mx and holding>0 and openprofit>0,0,market);
//运行到dx无论盈亏平掉多单

sell(dx,1,market);
//开空单
buyshort(mx,1,market);
//当ms时若空单有盈利则空单止盈
sellshort(ms and holding<0 and openprofit>0,0,market);
//运行到ds时无论盈亏平掉空单
sellshort(ds,0,market);


--  作者:guotx2010
--  发布时间:2012/8/19 22:49:01
--  

if holding>0 then begin
 if dx then sell(1,1,market);
 if mx and openprofit>0 then sell(1,1,market);
end

if holding<0 then begin
 if ds then sellshort(1,1,market);
 if ms and openprofit>0 then sellshort(1,1,market);
end

if holding=0 then begin
 if ms then buy(1,1,market);
 if mx then buyshort(1,1,market);
end

这是开平仓部分的代码

 


--  作者:lcgs005
--  发布时间:2012/8/19 22:55:39
--  
以下是引用guotx2010在2012-8-19 22:49:01的发言:

if holding>0 then begin
 if dx then sell(1,1,market);
 if mx and openprofit>0 then sell(1,1,market);
end

if holding<0 then begin
 if ds then sellshort(1,1,market);
 if ms and openprofit>0 then sellshort(1,1,market);
end

if holding=0 then begin
 if ms then buy(1,1,market);
 if mx then buyshort(1,1,market);
end

这是开平仓部分的代码

 

谢谢,不过仍有部份信号出来不了,仔细看了下图,当空单信号未出来前,多单信号发不出来,但当平空信号出来后,开多信号已经过去了,所以发不出信号,不知有无其它解决办法


--  作者:admin
--  发布时间:2012/8/20 11:18:38
--  

建议初学用户一定要仔细的阅读并研究金字塔的调试技巧,你说的这个问题即便是我们帮你也是要通过这些技巧来完成

 

http://www.weistock.com/bbs/dispbbs.asp?boardid=4&Id=332 问题4