以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  请问如下条件如何编写?  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=149477)

--  作者:jjjfk
--  发布时间:2017/3/22 8:59:39
--  请问如下条件如何编写?

请问如下的第二次及第n次开仓条件的语句如何编写?

tr1 : max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));

atr : ma(tr1,20);                               //atr公式

 

ma20:ma(close,20);                               //20日均线

 

a1:=0.01*valuewhen(barpos=1,asset);              //初始资金的1%

 

a2:=floor(a1/(2*atr));                         //开仓手数

 

a3:=ref(hhv(high,20),1);                       //20日高点

 

if holding=0 and close>a3 and close>ma20

then begin

buy(1,a2,marketr);

end                                   //第一次开仓

 

a4:=enterprice-2*ref(atr,enterbars=1);

if holding=1 and low<=a4

then begin

sell(1,0,limitr,a4);

end                                 //第一次开仓离场

 

//第二次及第n次开仓条件:如果随后的收盘 > 上一次(即第 n-1 次)开仓的(enterprice+2*atr),则开仓(即第 n 次);


--  作者:jinzhe
--  发布时间:2017/3/22 9:04:59
--  

variable:bj=0;

tr1 : max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));

atr : ma(tr1,20);                               //atr公式


ma20:ma(close,20);                               //20日均线


a1:=0.01*valuewhen(barpos=1,asset);              //初始资金的1%


a2:=floor(a1/(2*atr));                         //开仓手数


a3:=ref(hhv(high,20),1);                       //20日高点


if holding=0 and close>a3 and close>ma20 and bj=0

then begin

buy(1,a2,marketr);

bj:=1;

end                                   //第一次开仓

if holidng=0 and close>enterprice+2*atr and bj=1 

then begin

buy(1,a2,marketr);

end

a4:=enterprice-2*ref(atr,enterbars=1);

if holding=1 and low<=a4

then begin

sell(1,0,limitr,a4);

end              


--  作者:jjjfk
--  发布时间:2017/3/22 9:34:08
--  
明白了,谢谢!
--  作者:jjjfk
--  发布时间:2017/3/22 9:46:12
--  
你好,我看到你这行代码:
if holding=0 and close>a3 and close>ma20 and bj=0
then begin
buy(1,a2,marketr);
bj:=1;
end                                   //第一次开仓

if holding=0 and close>enterprice+2*atr and bj=1 
then begin
buy(1,a2,marketr);
end

第二处的“if holding=0 and close>enterprice+2*atr and bj=1 ”,这里有没有写错?还是“if holding=0”吗?不是“if holding>0