holding 源代码有问题,开多 开空的第一根k线holding不一致,导致程序无法按设计运行。
开空的所在k线上holding是 -1
开多的所在k线上holding是0 次一根k线才是1
这样就导致程序编写开多开空不一致无法达到设计。版主holding源代码出问题啦。
holding的问题出现在空翻多和多翻空上面,多翻空正常,平多时达到开空条件即能当根就开空。空翻多就有问题了,当根达到开多条件不仅不能马上开多,只能在次周期之后达到条件才能开多,且开仓一根上多和空holding显示不一样。
多翻空,和空翻多
下单指令写的有问题,
以下为MARKET价反手的简单示例,LIMIT的类似
//5日均线上穿10日均线,平空开多
long:=CROSS(ma5,ma15
if long then
begin
sellshort(holding<0,1,market);
buy(holding=0,1,market);
end
//5日均线下破10日均线,平多开空
short:=CROSS(ma15,ma5);
if short then
begin
sell(holding>0,1,market);
buyshort(holding=0,1,market);
end
didian:=llv(l,2);
gaodian:=hhv(h,2);
Kcj3:=ref(hhv(h,enterbars+1),1);
if h>=gaodian and holding=0 then buy(1,1,thisclose);
If holding>0 and ref(h>=gaodian,enterbars)=1 and ENTERBARS>=2 then zy:kcj3-5;
if holding>0 and ref(h>=gaodian,enterbars)=1 and enterbars>=2 and l-zy<-0.1
then sell(1,0,thisclose);
kKcj3:=ref(llv(l,enterbars+1),1);
if l<=didian and holding=0 then buyshort(1,1,thisclose);
If holding<0 and ref(l<=didian,enterbars)=1 and ENTERBARS>=2 then kzy:kkcj3+5;
if holding<0 and ref(l<=didian,enterbars)=1 and enterbars>=2 and h-kzy>0.1
then sellshort(1,0,thisclose);
同样是这样一堆代码就能检测出问题,双向都达到条件时,同根k线只能多翻空,而不能空翻多,因为holding多空持仓前后标准不一样。
代码次序问题,请注意先平后开原则
改为以下既可
didian:=llv(l,2);
gaodian:=hhv(h,2);
Kcj3:=ref(hhv(h,enterbars+1),1);
kKcj3:=ref(llv(l,enterbars+1),1);
If holding<0 and ref(l<=didian,enterbars)=1 and ENTERBARS>=2 then kzy:kkcj3+5;
if holding<0 and ref(l<=didian,enterbars)=1 and enterbars>=2 and h-kzy>0.1
then sellshort(1,0,thisclose);
if h>=gaodian and holding=0 then buy(1,1,thisclose);
If holding>0 and ref(h>=gaodian,enterbars)=1 and ENTERBARS>=2 then zy:kcj3-5;
if holding>0 and ref(h>=gaodian,enterbars)=1 and enterbars>=2 and l-zy<-0.1
then sell(1,0,thisclose);
if l<=didian and holding=0 then buyshort(1,1,thisclose);