以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  VIP论坛区发帖失败?  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=144883)

--  作者:ywf8231757
--  发布时间:2016/12/17 18:16:37
--  VIP论坛区发帖失败?
老师您好
     下面是我编写的代码,我希望实现的功能是:
     最基础的均线策略,金叉做多,死叉做空,并将收益曲线存储到数组变量x[]中。编译之后运行发现没有得到我想要的结果,请教老师问题出在哪里
variable:x[]=0;//定义数组变量
input:m(20,10,50,10),n(200,10,200,10);//初始化参数
ma1:ma(c,m);
ma2:ma(c,n);

in:=c-ref(c,1);//定义正向现金流
out:=ref(c,1)-c;//定义反向现金流
setubound(x,datacount);//扩充数组上限

dd:=(ma1>=ma2 and ref(ma1,1)>=ref(ma2,1)) or (ma1<ma2 and ref(ma1,1)>=ref(ma2,1));//多头持仓状态或者当根K线出现死叉,得到正向现金流
kk:=(ma1<ma2 and ref(ma1,1)<ref(ma2,1)) or (ma1>=ma2 and ref(ma1,1)<ref(ma2,1));//空头持仓状态或者当根K线出现金叉,得到反向现金流

//将每一笔现金流的数值存入X[]中
if dd then
x[barpos]=x[barpos-1]+in;
if kk then
x[barpos]=x[barpos-1]+out;

aa:x,noaxis;//输出数组x所代表的收益曲线

--  作者:jinzhe
--  发布时间:2016/12/19 8:58:37
--  
if dd then
x[barpos]=x[barpos-1]+in;
if kk then
x[barpos]=x[barpos-1]+out;

改成

 

if dd then
x[barpos]:=x[barpos-1]+in;
if kk then
x[barpos]:=x[barpos-1]+out;
 
赋值少冒号,就是一个判断,没有赋值的效果