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

Ehlers "Detrend" Function



PureBytes Links

Trading Reference Links

I sent this earlier but it got caught by the "size" filter so I will try splitting it into two posts.

----------

Andy pointed out the Ehlers "Detrend" function code from "Optimal Detrending", by John F. Ehlers in the July, 2000 issue of TASC.

I noticed that it used uninitialized variables and required about 25 times the lookback period to initialize. That was about 1000 bars in the example Andy posted!

So I figured out how to initialize it and thought I would post the revised code to the group. I did two versions, both are in the attached ELA file and in the text below.

The first version adds an input for the lookback period as Andy did and makes the price an input for more generality.

The second adds a T3Average pre-filter on the price to take out some of the noise in the detrended result.

Both look as if they should be useful.

(ELA file to follow.)

Bob Fulks

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

   Indicator     :    Ehlers.Detrend
   
   Last Edit     :    7/1/2000

   Provided By   :    Bob Fulks

   Description   :    Plots the Ehlers.Detrend function.
   
   Inputs:

      Price:  Price series to be detrended. (Default = MedianPrice)

      Lbck:   Lookback interval (Default = 6), which was the value in 
                 the article.

********************************************************************}

Input: Price(MedianPrice), Lbck(6);

Plot1(Ehlers.Detrend(Price, Lbck), "Detrend");

Plot4(0, "Zero");



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

   Function      : Ehlers.Detrend
   
   Last Edit     : 7/1/2000

   Provided By   : Bob Fulks

   Description   : 
   
      This function is a revised version of the code from "Optimal 
      Detrending", by John F. Ehlers in the July, 2000 issue of TASC. 
      This version replaces the calculated median price with a 
      "Price" input and makes the lookback period an input parameter 
      for more generality.
      
      It also creates declared variables instead of using Value1 and 
      Value2 in order that they can be properly initialized. These 
      are then initialized to the proper values to eliminate the long 
      initialization time of the original code in the article. 

   Inputs:

      Price - Price series to be detrended. (Default = MedianPrice)

      Lbck - Lookback interval (Default = 6), which was the value in 
             the article.

********************************************************************}
Inputs: Price(NumericSeries), Lbck(Numeric);
   
Vars: Var1(1.09649123 * Price), Var2(0);

Var1 = Price + 0.088 * Var1[Lbck];
Var2 = Var1 - Var1[Lbck] + 1.2 * Var2[Lbck] - 0.7 * Var2[2 * Lbck];
Ehlers.Detrend = Var2[2 * Lbck] - 2 * Var2[Lbck] + Var2;


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

   Indicator     :    Ehlers.Detrend.A
   
   Last Edit     :    7/1/2000

   Provided By   :    Bob Fulks

   Description   :    Plots the Ehlers.Detrend.A function.
   
   Inputs:

      Price:    Price series to be detrended. (Default = MedianPrice)

      Lbck:     Lookback interval (Default = 6), which was the value in 
                    the article.

      Periods:  Periods input to T3 Average (Default = 3) 

********************************************************************}
Input: Price(MedianPrice), Lbck(6), Periods(3);

Plot1(Ehlers.Detrend.A(Price, Lbck, Periods), "Detrend.A");

Plot4(0, "Zero");


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

   Function      : Ehlers.Detrend.A
   
   Last Edit     : 7/1/2000

   Provided By   : Bob Fulks

   Description   : 
   
      This function is a revised version of the code from "Optimal 
      Detrending", by John F. Ehlers in the July, 2000 issue of TASC. 
      This version replaces the calculated median price with a 
      "Price" input, makes the lookback period an input parameter 
      for more generality, and filters the price series with the 
      T3 average before processing it.
      
      It also creates declared variables instead of using Value1 and 
      Value2 in order that they can be properly initialized. These 
      are then initialized to the proper values to eliminate the long 
      initialization time of the original code in the article. 

   Inputs:

      Price   - Price series to be detrended. (Default = MedianPrice)

      Lbck    - Lookback interval (Default = 6), which was the value in 
                the article.

      Periods - Periods for use by the T3 Average 
                (Default = 1 [no filtering])

********************************************************************}
Inputs: Price(NumericSeries), Lbck(Numeric), Periods(Numeric);
   
Vars: Var1(1.09649123 * Price), Var2(0);

Var1 = T3Average.series(Price, Periods) + 0.088 * Var1[Lbck];
Var2 = Var1 - Var1[Lbck] + 1.2 * Var2[Lbck] - 0.7 * Var2[2 * Lbck];
Ehlers.Detrend.A = Var2[2 * Lbck] - 2 * Var2[Lbck] + Var2;

-------------------------------------