PureBytes Links
Trading Reference Links
|
In Nov. (2,18,20,23) there was discussion about filtering out bad ticks
or bars. Some code was given to identify bad ticks and compute an
average of the range (H-L). But it appeared to only exclude, from the
average range, bad ticks on the current bar not those on past bars that
are used to compute the average. I have been using an average that does
exclude past bad ticks. This average is then used to eliminate bad ticks
from calculations such as swinghigh/low points.
This code first computes an average, Ave, of non-zero values of h-l by
storing them in the array, Av. It then uses that average to compare
against a (h-l) value and decide if it is a bad tick or bar. If it is,
the bad tick is rejected and only non-bad ticks or bars are used to
compute a second average, Ave1. Ave1 is used to exclude a bar or tick
from a calculation such as a swinghigh bar. Note that h-l for any bar is
compared to the average, Ave, computed for that same bar. Each bar or
tick is compared to the average calculated up to that bar or tick. It
will take twice len+1 bars to make Ave1. On minute charts for thinly
traded stocks there can be lots of zero values of h-l and, plotting 3 or
more days may be needed in order to have enough non-zero h-l values.
The value of BadTick will need to be adjusted to a specific application.
Values from 2.5 to 3.5 seem about right. The arrays in EL are not
dynamic. I.e., the number of elements can not be changed from the chart
via an input. But the element number called can be changed as an input.
The lookback length here can be changed up to 200 bars. If len is set
less than 200 the upper array elements are just not used.
Obviously, this code will not plot on 1 tick charts as h-l is undefined
but if something such as AbsValue(h-h[1]) is substituted for h-l it will
plot. Of course, then AbsValue(l-l[1]) is needed. It is not clear to me
which parameter set, h-l, o-c, o-c[1], h-h[1], etc. is best to use. I
use both h-l and h-h[1] + l-l[1] together as h-l will miss the bad tick
where o=h=l=c, which occurs frequently on minute charts of thinly trade
stocks. On the other hand, h-h[1] will call a gap up a bad tick whereas
h-l does not.
I consider this code to be sort of modular and applicable in different
calculations (something along the lines of "IC Op-Amp Cookbook" by
Walter Jung (see amazon.com)). Maybe code of this sort can be collected
from the list and made available from one place, instead of getting lost
in the bowels of the list.
input: BadTick(2.5), len(11);
var: Ave(0), Ave1(0), K(0), K1(0), J(0), cnt(0);
Array: Av[200](0), Av1[200](0);
IF (h-l)>0 then begin
for value1=len-2 downto 0 begin
Av[value1 +1] = Av[value1];
end;
Av[0] = h-l;
If Av[len-1]<>0 then begin
K=0;
for value1 =0 to len-1 begin
K = Av[value1] + K;
end;
Ave = K/len;
End;
plot1(Ave,"Ave");
{................................................................}
If (h-l)<BadTick*Ave then begin
for value1=len-2 downto 0 begin
Av1[value1 +1] = Av1[value1];
end;
Av1[0] = h-l;
If Av1[len-1]<>0 then begin
K1=0;
for value1 =0 to len-1 begin
K1 = Av1[value1] + K1;
end;
Ave1 = K1/len;
End;
End;
END;
plot2(Ave1,"Ave1");
Reinventing the wheel again,
Wayne
|