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

Re: Exponential moving average



PureBytes Links

Trading Reference Links

At 3:02 PM -0700 9/30/00, Bob Perry wrote:

>When using my "BP-LRVdyn" I notice that if I have a long trend
>develop, the math gets very intensive because of the number of bars
>from the last pivot. And, although, I like the statistically correct
>behavior of the plot (it's cycle independant), it gets too far away
>from the price during these long trends.

The LinearRegValue function from Omega is ridiculously slow. The
attached version is an order of magnitude faster an gives the same
values. (ELA and text attached).


{ *******************************************************************

   Study         : LinearReg
  
   Last Edit     : 5/17/97

   Provided By   : Bob Fulks

   Description   : Calculates the value today of a linear regression
      line drawn through the last <Length> price points. Equivalent
      to Omega's LinearRegValue function with a TargetBar of zero
      but much faster.

      Uses the algorithm described in TASC 10/95 pg 21 & TASC 2/96 pg 12
      and in Chuck Kaucher's email of 5/8/97
                 
********************************************************************}
Inputs :  Price(NumericSeries), Length(NumericSimple);
Vars   :  Sum(0), Counter(0), CSum(0), Factor(0), Offset(0);

Sum       = 0;
CSum      = 0;
Offset    = -(Length + 1) / 3;

for Counter = 0 to Length - 1 begin
   Factor   = Length  + Offset - Counter;
   Sum      = Sum + Price[Counter] * Factor;
   CSum     = CSum + Factor;
end;
if CSum > 0 then
   LinearReg = Sum / CSum
else
   LinearReg = 0;
Attachment Converted: "c:\program files\qualcomm\eudora\attach\LINEARRE.ELA"