PureBytes Links
Trading Reference Links
|
"Shraga(Feivi-Philip)" <shraga@xxxxxxxxxxxx> writes
>I think the code snippet below will find the 3rd highest
>maxlist value(Max3) for you. I haven't test it yet.
>
>Vars: max1(0), max2(0), max3(0), i(0);
>Arrays: Num[25](0)
>
>{initialize everything}
>If currentbar = 1 then begin
> Max1=1;
> Max2=Max1/2;
> Max3=Max2/2;
> end;
>
>For i = 0 to 24 begin
> If Num[i] > Max1 then begin
> Max3=Max2;
> Max2=Max1;
> Max1=Num[1];
> end;
>
Unfortunately this code fails if the initial
values of the array are
9, 4, 2, 1, 1, 1, 6, 1, 1, 1
The code only inserts a new item into the
"top three" if it's bigger than the biggest.
So it's only guaranteed to get the right answer
for Max1. In the example above, the "6"
is not bigger than the biggest-so-far ("9"),
so "6" isn't inserted into the "top three"
and consequently at the end of the loop,
Max1=9, Max2=1, Max3=0.50
which is the wrong answer.
(If you use the same code but process the list
from right to left instead of left to right,
you get a different but still wrong answer:
Max1=9, Max2=6, Max3=1)
|