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

More Bad Ticks



PureBytes Links

Trading Reference Links

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. The standard deviation is most sensitive to bad ticks as it
involves the square of parameters.

input: BadTick(2.5), len(9), len1(9),Price(c);
var:  Ave(0), Ave1(0), K(0),K1(0), K2(0), J(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;
         Ave = K/len;  {average of h-l}
      end;	
        {omits h-l values larger than BadTick*Ave}
   If (h-l)<BadTick*Ave then begin
      for value1=len-2 downto 0 begin
         Av1[value1 +1] = Av1[value1];
         Pr[value1+1]=Pr[value1];
      end;
     {stores h-l values and Price}
         Av1[0] = (h-l);
         Pr[0]=Price;

       if Av1[len-1]<>0 then begin
          K1=0;
           K2=0;
      {sums h-l and Price values}
           for value1 =0 to len-1 begin
               K1 = Av1[value1] + K1;
              K2=Pr[value1]+K2;
           end;
     {average of h-l and Price values}
              Ave1 = K1/len;
              AvgP = K2/len;
       end;
   End;
END;	
{
the following calculates the standard deviation, SD, 
omitting any bad tick 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(StdDev(Price,LEN1), "StdDev");
plot2(SD, "SD");

Wayne Mathews