以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  请教:交易系统中IF语句的问题  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=1177)

--  作者:drzwz168
--  发布时间:2010/3/21 16:37:00
--  请教:交易系统中IF语句的问题

数据:上证指数

日期         收盘         8日均线
2010.3.8  3053.23  3059.772  

2010.3.9  3069.14  3060.837   (收盘上穿均线)
2010.3.10 3048.93  3060.461  (收盘下穿均线)

公式1:

ma1:ma(c,8);
if holding=0 and cross(c,ma1) then buy(1,100,thisclose);
else if holding>0 and cross(ma1,c) then sell(1,holding,thisclose);

 

问题:为什么2010.3.9 出现"开多"信号,3.10无"平多"信号,若把上面的公式1改为下面的公式2或公式3,则3.10会出现“平多”信号。

 

公式2:

ma1:ma(c,8);
if holding>0 and cross(ma1,c) then sell(1,holding,thisclose);
else if holding=0 and cross(c,ma1) then buy(1,100,thisclose);

 

公式3:

ma1:ma(c,8);
buy(holding=0 and cross(c,ma1),100,thisclose);
sell(holding>0 and cross(ma1,c),holding,thisclose);

 

 

 

 

PS:在大智慧下,上述公式1和公式2的结果是一样的:3.10出现平多信号.

 

DZH公式1:

ma1:ma(c,8);
if holding=0 and cross(c,ma1) then buy(100,thisclose);
else if holding>0 and cross(ma1,c) then sell(holding,thisclose);

 

DZH公式2:

ma1:ma(c,8);
if holding>0 and cross(ma1,c) then sell(holding,thisclose);
else if holding=0 and cross(c,ma1) then buy(100,thisclose);

 

 

 

先谢谢啊!

[此贴子已经被作者于2010-3-21 16:39:01编辑过]

--  作者:轮回
--  发布时间:2010/3/21 22:23:43
--  

if holding=0 and cross(c,ma1) then buy(1,100,thisclose);
else if holding>0 and cross(ma1,c) then sell(1,holding,thisclose);

这里开多和平多应该是并列关系,因为是多条件,并非唯一的非此即彼的选择关系,试试下面的.

if holding=0 and cross(c,ma1) then buy(1,100,thisclose);
if holding>0 and cross(ma1,c) then sell(1,holding,thisclose);


--  作者:drzwz168
--  发布时间:2010/3/21 23:19:37
--  

谢谢轮回大侠。你的公式能解决我上面的问题。这个问题实际上是我简化了的,我本来想要的是下面这种非此即彼的选择关系:

if A then

B

else if C then

D

即,如果条件A成立,则执行B,不再检查条件C是否成立;否则,若条件C成立,则执行D。

可是jzt似乎不是这么执行的。

 

[此贴子已经被作者于2010-3-21 23:20:59编辑过]

--  作者:轮回
--  发布时间:2010/3/21 23:41:34
--  

如果你是楼上这样的想法,那你楼上的写法应该没问题,如果你觉得金字塔似乎不是这么执行的,请贴出你验证的实例出来我们共同分析.


--  作者:admin
--  发布时间:2010/3/21 23:49:16
--  

金字塔目前是不提供

if A then

B

else if C then

D

 

这种判断模式,只有

if A then

B

else

D


--  作者:drzwz168
--  发布时间:2010/3/22 0:02:38
--  

明白了,我的实例包括了N个if ... then ... else if ... then ...  晕, 我自己再改一改,再次谢谢轮回和admin!