[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Eliminating Bad Ticks



PureBytes Links

Trading Reference Links

In responding to a posting by Gary Fritz on the omega-list, on Tue, 2
Mar 1999 11:03:58 -0700, I realized I made an error on one of my former
postings. Namely, "More Bad Ticks",  vol 99 issue 40 (3 Feb 1999). 

The error was in calculating the price before the second average (h-l)
was calculated. That way, bad ticks would influence the final results
and to exclude them, the calculation of price must be after the second
average (h-l) is found. The following corrects this error. I also have
formatted the code to utilize the badtick code as a user function, which
makes the indicator code appear less messy and formable. This treatment
is more applicable to real time than EOD as there are many more bad
ticks in real time.

When dealing with bars that have an O, H, L, C (all bars except 1 tick)
most bad ticks are a result of an extreme high or low with the open and
close more accurate. If the standard deviation (or any other function)
is calculated using the open or close then this Bad Ticks method is
problably not needed. If it is utilized with Price equal to O or C then
instead of (h-l) use (O-O[1]) or (C-C[1]) in the Bad Tick calculation.
Many stocks are thinly traded and their charts show bars where o=h=l=c.
For these use one of (h-h[1]) or (o-o[1]) or (o-c[1]), etc. Othewise,
you will get to the end of the chart before "len" values of (h-l) are
accumulated to do the calculation.

To use Bad Tick on 1 tick charts use either (h-h[1]) or (l-l[1]) or both
(there seems to be more bad ticks too low than too high). 

Maybe two different values of BadTic should be used in the user function
and the indicator but I leave that up to someone else to investigate.

The following code calculates standard deviation while omitting bad
ticks. It is an application of the code posted in vol 98, issues 741 and
742 in December, 1998. See those postings for a discussion of the first
half of this code which deals with eliminating bad ticks from a
calculation. 

input: BadTic(2.5), len(9), len1(9),Price(High);  {len must be <than
201}
var:  Ave1(0), Ave2(0), K(0),K1(0), K2(0), 
         avgP(0), SumSqr(0), sd(0);
Array: Av[200](0), Av1[200](0), Pr[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);  {Stores len number of non-zero values of h-l}
      If Av[len-1]<>0 then begin
           K=0;
        for value1 =0 to len-1 begin
           K = Av[value1] + K;  {Sums the stored h-l}
        end;
          Ave1 = K/len;  {FIRST average of h-l}
      End;  
    
    {The following omits h-l values larger than BadTic*Ave1}

   If (h-l)<BadTic*Ave1 then begin
      for value1=len-2 downto 0 begin
         Av1[value1 +1] = Av1[value1];
      end;     
         Av1[0] = (h-l); {stores h-l values }
      If Av1[len-1]<>0 then begin
             K1=0;
         for value1 =0 to len-1 begin
              K1 = Av1[value1] + K1;    {sums h-l }
         end;     
              Ave2 = K1/len;	 {SECOND average of h-l }
       End;
   End;
END;
{....Utilizing the BadTic calculation to omit Bad Prices.......}

If (h-l)<BadTic*Ave2 then begin
      for value1=len-2 downto 0 begin
          Pr[value1+1]=Pr[value1];
      end;     
          Pr[0]=Price;    {stores Price values }
       If Pr[len-1]<>0 then begin
            K2=0;      
          for value1 =0 to len-1 begin
            K2=Pr[value1]+K2; {sums Price values}
          end;                   
              AvgP = K2/len;   {average of Price values}
       End;
END;    
{the following calculates the standard deviation, SD, 
omitting any bad Price values}

If AvgP > 0 then begin
     SumSqr = 0;
   for value1 = 0 to Len - 1 begin
     SumSqr = SumSqr + (Pr[value1]-AvgP) * (Pr[value1]-AvgP);
   end;
   SD = SquareRoot(SumSqr / Len);
End;
plot1(SD, "SD");
plot2(StdDev(Price,Len1), "StdDev");  {for comparison}


{====================================}

{Function: AveRange	Check to see that you do not have 
another user function with this name}

input: BadTic(numeric), len(numeric);  
var:  Ave1(0), Ave2(0), K(0),K1(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);  {Stores len number of non-zero values of h-l}
      If Av[len-1]<>0 then begin
           K=0;
        for value1 =0 to len-1 begin
           K = Av[value1] + K;  {Sums the stored h-l}
        end;
          Ave1 = K/len;  {FIRST average of h-l}
      End;  
    
  {The following omits h-l values larger than BadTic*Ave}

   If (h-l)<BadTic*Ave1 then begin
      for value1=len-2 downto 0 begin
         Av1[value1 +1] = Av1[value1];
      end;     
         Av1[0] = (h-l);    {stores h-l values }
      If Av1[len-1]<>0 then begin
              K1=0;
         for value1 =0 to len-1 begin
              K1 = Av1[value1] + K1;    {sums h-l }
         end;     
              Ave2 = K1/len;	 {SECOND average of h-l }
           AveRange=Ave2;
       End;
   End;
END;

{..Utilizing the BadTick calculation to omit Bad Prices. This is all}
  that is needed for the indicator if the user funtion is utilized ..}

Indicator: SD   {len must be <than 201}

input: BadTic(2.5), len(9), Price(High), len1(9);
var: K2(0), AvgP(0), SumSqr(0), SD(0), W(0);
array: Pr[200](0);

W=AveRange(BadTic,len);

If (h-l)<BadTic*W then begin
      for value1=len-2 downto 0 begin
          Pr[value1+1]=Pr[value1];
      end;     
          Pr[0]=Price;    {stores Price values }
       If Pr[len-1]<>0 then begin
             K2=0;      
          for value1 =0 to len-1 begin
             K2=Pr[value1]+K2;     {sums Price values}
          end;                   
              AvgP = K2/len;   {average of Price values}
       End;
END;   
 
{calculating the standard deviation, SD, without bad Price values}

If AvgP > 0 then begin
     SumSqr = 0;
   for value1 = 0 to Len - 1 begin
     SumSqr = SumSqr + (Pr[value1]-AvgP) * (Pr[value1]-AvgP);
   end;
   SD = SquareRoot(SumSqr / Len);
End;
plot1(SD, "SD");
plot2(StdDev(Price,LEN1), "StdDev");  {for comparison}


Wayne Mathews