斜率:=(H-ref(H,1))/ref(H1,1);
前N天的斜率形成一个长度为N的数组,比如按IF日线,就是0.0060, 0.0042, 0.0048, 0.0018, -0.0022, 0.0066
现在想遍历数组中每个值与其它值的差,然后找出差<0.002的次数最多的那个值。
比如0.0048,就和其中3个数的差都小于0.002,因此就选出0.0060, 0.0042, 0.0048, 0.0066这4个次数都为3的值,求得它们的平均数为当前斜率。
而0.0018, -0.0022因为骗离其它值太远,就被抛弃了。
现在有简单的函数或算法,来实现这个目标吗?
这样写 好象不行
斜率:=(H-ref(H,1))/ref(H1,1);
variable:ss=0,kk=0;
variable:A[5]=0;
hh:=斜率;
A[1]:=ref(hh,1);
A[2]:=ref(hh,2);
A[3]:=ref(hh,3);
A[4]:=ref(hh,4);
A[5]:=ref(hh,5);
斜率差:=0.002;
if count((hh-A)<=斜率差,6)>=4 then begin
ss:=ss+hh;
kk:=kk+1;
end
if count((A[1]-A)<=斜率差,6)>=4 then begin
ss:=ss+A[1];
kk:=kk+1;
end
if count((A[2]-A)<=斜率差,6)>=4 then begin
ss:=ss+A[2];
kk:=kk+1;
end
if count((A[3]-A)<=斜率差,6)>=4 then begin
ss:=ss+A[3];
kk:=kk+1;
end
if count((A[4]-A)<=斜率差,6)>=4 then begin
ss:=ss+A[4];
kk:=kk+1;
end
if count((A[5]-A)<=斜率差,6)>=4 then begin
ss:=ss+A[5];
kk:=kk+1;
end
当前斜率:ss/kk,colorgreen;
看看
我记得我写的时候是没用数组的,你自己加的?
对。你没有用数组。
但你的写法不对,你是找出哪一个值距离其他值都在0.002之内。
而实际情况是很多时候没有一个值符合要求。只能找出最接近要求的那一个数值,才行……
对于这种情况,已经超过你给的定义了,所以不能再往后写了,
你发帖到高级区问问
对于这种情况,已经超过你给的定义了,所以不能再往后写了,
你发帖到高级区问问
倒是没超过我给的定义 一直就这么说的……
无敌了,验证了好几遍都是对的,用户看看有没有不对的地方
ss:=0;kk:=1;tt:=0;
hh:(H-ref(H,1))/ref(H,1);
h1:ref(hh,1);
h2:ref(hh,2);
h3:ref(hh,3);
h4:ref(hh,4);
x1: ((hh-h1)<=0.002) + ((hh-h2)<=0.002) + ((hh-h3)<=0.002) + ((hh-h4)<=0.002) ;
x2: ((h1-hh)<=0.002) + ((h1-h2)<=0.002) + ((h1-h3)<=0.002) + ((h1-h4)<=0.002) ;
x3: ((h2-h1)<=0.002) + ((h2-hh)<=0.002) + ((h2-h3)<=0.002) + ((h2-h4)<=0.002) ;
x4: ((h3-h1)<=0.002) + ((h3-h2)<=0.002) + ((h3-hh)<=0.002) + ((h3-h4)<=0.002) ;
x5: ((h4-h1)<=0.002) + ((h4-h2)<=0.002) + ((h4-h3)<=0.002) + ((h4-hh)<=0.002) ;
if x1<>ss then begin
ss:=x1;
tt:=hh;
end
if x2=ss and x2<>0 then begin
tt:=tt+h1;
kk:=kk+1;
end
if x2>ss then begin
ss:=x2;
tt:=h1;
kk:=1;
end
if x3=ss and x3<>0 then begin
tt:=tt+h2;
kk:=kk+1;
end
if x3>ss then begin
ss:=x3;
tt:=h2;
kk:=1;
end
if x4=ss and x4<>0 then begin
tt:=tt+h3;
kk:=kk+1;
end
if x4>ss then begin
ss:=x4;
tt:=h3;
kk:=1;
end
if x5=ss and x5<>0 then begin
tt:=tt+h4;
kk:=kk+1;
end
if x5>ss then begin
ss:=x5;
tt:=h4;
kk:=1;
end
if ss=0 then drawtext(islastbar,close,'没有符合的项');
if ss<>0 then avg:tt/kk;