# NEOTICKER DATA BEGIN
ScriptType=Indicator
Description=Distance Coefficient Ehlers Filter
Name=dcef
Language=VBScript
Links=1
MinBars=10
Plot_color=255
Plot_style=Line
Param_name_0=LookBack
Param_inuse_0=1
Param_type_0=integer.gt.0
Param_default_0=5
Param_name_1=Sum
Param_inuse_1=1
Param_type_1=integer.gt.0
Param_default_1=5
Param_inuse_2=0
Param_type_2=string
Param_inuse_3=0
Param_type_3=string
Explanation_Lines=0
# NEOTICKER DATA END

'NeoTicker Additional Indicator
'written by Kenneth Yuen, May 2001
'Copyright by TickQuest Inc.
'All right reserved

'Distance Coefficient Ehlers Filter
'Stock & Commodities Magazine. April, 2001

Function dcef()

dim CurCoefficient, CurAvgPrice
dim LastCoefficient, LastAvgPrice
dim i

if Param2.int >= Param1.int then

   if heap.size = 0 then
      heap.allocate(3)
      for i = 0 to 2
         heap.value(i) = 0
      next
   end if

   if Data1.BarsNum(0) >= Param1.int then

      if heap.value(2) >= Param2.int then
         LastCoefficeint = 0
         LastAvgPrice = (Data1.high(Param2.int) + Data1.low(Param2.int))/2

         for i = 1 to param1.int
            LastCoefficient = LastCoefficient + tq_power((LastAvgPrice - _
                             (Data1.high(Param2.int+i) + _
                             Data1.low(Param2.int+i))/2),2)
         next

         heap.value(0) = heap.value(0) - LastCoefficient
         heap.value(1) = heap.value(1) - LastAvgPrice*LastCoefficient
      end if

      CurCoefficient = 0
      CurAvgPrice = (Data1.high(0) + Data1.low(0))/2

      for i = 1 to param1.int
         CurCoefficient = CurCoefficient + tq_power((CurAvgPrice - _
                          (Data1.high(i) + Data1.low(i))/2),2)
      next

      heap.value(0) = heap.value(0) + CurCoefficient
      heap.value(1) = heap.value(1) + CurCoefficient*CurAvgPrice
      heap.value(2) = heap.value(2) + 1

      if heap.value(2) < Param2.int then
         itself.success = false
      else
         dcef = heap.value(1)/heap.value(0)
      end if

   end if

else
   itself.success = false
   report.addline "","Invalid Input Cofficient Sum must be larger that Lookback"
end if
End Function

