数据:上证指数
日期 收盘 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);
先谢谢啊!
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);
谢谢轮回大侠。你的公式能解决我上面的问题。这个问题实际上是我简化了的,我本来想要的是下面这种非此即彼的选择关系:
if A then
B
else if C then
D
即,如果条件A成立,则执行B,不再检查条件C是否成立;否则,若条件C成立,则执行D。
可是jzt似乎不是这么执行的。
如果你是楼上这样的想法,那你楼上的写法应该没问题,如果你觉得金字塔似乎不是这么执行的,请贴出你验证的实例出来我们共同分析.
金字塔目前是不提供
if A then
B
else if C then
D
这种判断模式,只有
if A then
B
else
D
明白了,我的实例包括了N个if ... then ... else if ... then ... 晕, 我自己再改一改,再次谢谢轮回和admin!