PureBytes Links
Trading Reference Links
|
In issue 741, Dec. 29, 1998 I posted coded to filter bad ticks from
being used in a system or indicator. It used arrays to store the good
ticks and then computed an average of these good ticks. Any tick or bar
is compared to this average and if it is to large it is rejected. Below
is code that accomplishs the same thing but does not use arrays.
This code first looks back len number of bars to compute an average,
Ave, of non-zero values of h-l. 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 past non-bad ticks or bars are used to
compute the second average, Ave1. Ave1 is used to exclude a bar or tick
from a calculation such as a swinghigh bar. Note that past bars are
compared to the average, Ave, computed for the current bar. Past bars
are not compared to the average, Ave, for that past bar. This is
different from the code using arrays.
I had one of EL odd features occur with this code. It would not plot on
the daily chart for CDNW until "LB1<len+30" was included in the second
"while loop". There was no trouble plotting on numerous other charts.
Can someone explain this? 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. See my previous post.
As I stated in my previous post, I consider this type of code to be sort
of modular and applicable in different calculations (indicators) . 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: LB(0),LB1(0),sumHL(0),sumhl1(0), cnt1(0), cnt(0), Ave(0), Ave1(0);
sumhl=0; LB=0; cnt=0;
IF currentbar>1 then begin
If h-l>0 then begin
While cnt<len begin
if (h-l)[LB]>0 then begin
sumhl=(h-l)[LB]+sumhl;
cnt=cnt+1;
end;
LB=LB+1;
End;
Ave=sumhl/len;
plot1(Ave,"Ave");
{.........................................................}
If Ave>0 then begin
sumhl1=0; LB1=0; cnt1=0;
While cnt1<len and LB1<len+30 begin
if (h-l)[LB1]<badtick*Ave and (h-l)[LB1]>0 then begin
sumhl1=(h-l)[LB1]+sumhl1;
cnt1=cnt1+1;
end;
LB1=LB1+1;
End;
Ave1=sumhl1/len;
End;
End;
END;
plot2(Ave1,"Ave1");
Reinventing the wheel again,
Wayne Mathews
|