以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  求教一个均线表达  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=142970)

--  作者:987654jj
--  发布时间:2016/11/18 15:06:23
--  求教一个均线表达
求教老师 
如果用均线系统作为开平仓依据 初始假定10日线上做多 线下做空,
但是如果碰到连续上涨或下跌行情,比如日k线连续涨5天,则改成5日线上做多 线下做空(此时可能5日和10日方向相反,但以5日为准),直到5日和10日方向相同后,继续以10日线作为多空依据。
这个模型怎么用公式表达

--  作者:jinzhe
--  发布时间:2016/11/18 15:16:55
--  

variable:bj=0;

if bj=0 and c>ma(c,10) then buy(holding=0,1,market);

if bj=0 and c<ma(c,10) then buyshort(holding=0,1,market);

 

if bj=1 and c>ma(c,5) then buy(holding=0,1,market);

if bj=1 and c<ma(c,5) then buyshort(holding=0,1,market);

 

if cross(all(c>ref(c,1),5),0.5) then bj:=1;

if bj=1 and ((ma(c,5)>ref(ma(c,5),1) and ma(c,10)>ref(ma(c,10),1)) or (ma(c,5)<ref(ma(c,5),1) and ma(c,10)<ref(ma(c,10),1))) then bj:=0;