dist:=sumbars(holding=0 ,1) or sumbars(holding = 0 ,-1);
oo:=ref(open,dist)
这里面的sumbars(holding = 0 ,-1) 表示的意思是向前累加到持有一首空单的周期数吗?
你是想求得,空仓到当前位置的周期数把?
可以直接使用BARSLAST(holding = 0);
大神,我用barslast(holding = 0)为什么 在图标上显示在一根k线反复开平仓呢?
INPUT:grid(50,1,11111,1);
variable:level=0;
n : =5;
dist:=barslast(holding=0 );
oo:=ref(open,dist);
kaishi:=3000;
shang:=kaishi+n*grid*mindiff;
xia:=kaishi -n*grid*mindiff;
oo:=ref(open,dist);
kaishi:=3000;
shang:=kaishi+n*grid*mindiff;
xia:=kaishi -n*grid*mindiff;
if l < xia or h >shang then begin
if holding=0 then begin
dnprice:=oo-grid*mindiff;
if low<=dnprice then begin
buy(1,1,limitr,dnprice);
level:=-1;
end
end
if holding=0 then begin
upprice:=oo+grid*mindiff;
if high>=upprice then begin
buyshort(1,1,limitr,upprice);
level:=1;
end
end
if holding>0 then begin
upprice:=oo+(level+1)*grid*mindiff;
dnprice:=oo+(level-1)*grid*mindiff;
if high>=upprice then begin
sell(1,1,limitr,upprice);
level:=level+1;
end
if low<=dnprice then begin
buy(1,1,limitr,dnprice);
level:=level-1;
end
end
if holding<0 then begin
upprice:=oo+(level+1)*grid*mindiff;
dnprice:=oo+(level-1)*grid*mindiff;
if low<=dnprice then begin
sellshort(1,1,limitr,dnprice);
level:=level-1;
end
if high>=upprice then begin
buyshort(1,1,limitr,upprice);
level:=level+1;
end
end
if holding>0 then BEGIN
if low < oo-n*grid*mindiff then begin
sell(1,holding,limitr,close);
end
end
if holding < 0 then begin
if h > oo+n*grid*mindiff then begin
sellshort(1,holding,limitr,close);
end
end
end
1楼写法不对,
用sumbras(开空条件,1)就是上次开空到当前的周期,
用sumbas(开空条件,2)是上上次开空到当前的周期,
例子:
ma1:ma(c,10);
ma2:ma(c,20);
jc:cross(ma1,ma2);
sc:cross(ma2,ma1);
a1:sumbars(jc and holding=0,1);//上次开空举例当前周期数
a2:sumbars(jc and holding=0,2);//上上次开空举例当前周期数
BUYSHORT(jc and holding=0,1,marketr);
sellshort(sc and holding<0,1,marketr);
[此贴子已经被作者于2017/5/22 14:32:23编辑过]