todaybarcount:=TODAYBAR;
a1:=0;
v1:=0;
for pos=barpos-todaybarcount downto barpos-todaybarcount-59 do begin
if pos<1 or (pos>=1 and date[pos]!=date[barpos-todaybarcount]) then begin
break;
end
else begin
a1:=a1+amount[pos];
v1:=v1+vol[pos];
end
end
last1jsj:=a1/v1/multiplier;
last1jsj:=INTPART(last1jsj/MINDIFF);
last1jsj:=last1jsj*MINDIFF;
请问这段代码有什么问题存在吗?为什么一架载就会导致程序崩溃提示内存不足
我是写成一个指标, 其他的地方会调用这个指标并传入1M周期
for pos=barpos-todaybarcount downto barpos-todaybarcount-59 do begin
你在这句话上进入死循环了,建议你使用单步跟踪模式调试一下你的代码
这个循环哪里有死循环,请麻烦分析
我这段代码如果不写成指标,直接放到策略代码里加载到1M的图表上是没有问题的,结算价也是对的,我都检验过了
就是不能写成指标
我是这样调用这个指标的,图表1M周期
if tradedate != Date then BEGIN
last1jsj:=STKINDI(STKLABEL,'getlastjsj.getlastjsj',0,1,0);
end
这样调用指标就会导致程序崩溃
但如果直接按下面这种方式直接写在策略里面就没有问题
if tradedate != Date then BEGIN
todaybarcount:=TODAYBAR;
a1:=0;
v1:=0;
for pos=barpos-todaybarcount downto barpos-todaybarcount-59 do begin
if pos<1 or (pos>=1 and date[pos]!=date[barpos-todaybarcount]) then begin
break;
end
else begin
a1:=a1+amount[pos];
v1:=v1+vol[pos];
end
end
last1jsj:=a1/v1/multiplier;
last1jsj:=INTPART(last1jsj/MINDIFF);
last1jsj:=last1jsj*MINDIFF;
end