网友求助:
求100日内涨幅最大的前50个交易日涨幅总和,这个公式怎么编写?
解答如下:
input:n(100,1,9999);
wx:=barslast(barpos=0);
nn:=wx;
if datacount<n then begin
nn:=datacount-1;
end else begin
nn:=n;
end;
ZF:=(c/ref(c,1)-1)*100;
dt:=datacount;
tmp:=sort(ZF,0, dt-nn+1,dt);
ZFv:=(c/ref(c,1)-1)*100;
sp:=c*0;
for i=dt downto dt-nn+1 do begin
for j=dt downto dt-nn+1 do begin
if ZFv[j]=ZF[i] then
sp[j]:=i;
end;
end;
ZFp:=if(sp-(dt-nn)>=50,ZFv,0);
涨幅总和:sum(ZFp,0);