以图表程序化为例说明
variable:hh=0;//记录开仓到现在的最高价
pcj:=hh*0.98;
if hh/a>=1.01 and hh/a<1.02 and holding>0 then sell(1,1,lmt,trimprice(pcj));//a您给的开仓价
if hh/a>=1.02 and holding>0 then sell(1,1,lmt,trimprice(pcj));
if con1 and holding=0 then begin //con1为开仓条件
buy(1,1,mkt);
hh:=h
end
if holding>0 and h>=hh then hh:=h;//记录开仓后的最高价
我希望把开仓以来的最高价作为一个变量,每根k线都能用来判断一次,就写这一小段
给的就是你想要的,只是你只看了一句,没理解
if con1 and holding=0 then begin //con1为开仓条件
buy(1,1,mkt);
hh:=h
end
if holding>0 and h>=hh then hh:=h;//记录开仓后的最高价
请结合起来看,写出来的都是有必要的
if con1 then begin
kcj:=a;
buy(1,1,lmt,a);
hh:=h;
end
if holding>0 and h>=hh then hh:=h;
if hh/a>=1.01 and hh/a<1.02 and holding>0 then begin
pcj:=(hh+a)/2;
sell(1,1,lmt,pcj);
end
为什么写成这样回测的时候一次交易都没有,哪里有问题呢?