TradingView
everget
18 apr 2018 08:32

Adaptive Laguerre Filter 

U.S. Dollar/Japanese YenFXCM

Descrizione

Adaptive Laguerre Filter indicator script.

The Adaptive Laguerre Filter was originally developed and described by John Ehlers in his paper `Time Warp – Without Space Travel`.

Thanks to @apozdnyakov for the sorting solution.

Note di rilascio

Correct sorting

Note di rilascio

Refactored

Note di rilascio

Refactored

Note di rilascio

  • Add coloring

Note di rilascio

  • Added an alert on color change
  • Refactored
Commenti
genealno
@everget Hey mate! any way to make an alert trigger when the line changes color? Cheers
everget
@NOVAK.aleksey, Hi. I did it 1 month ago. Sorry for the late response.
kiero
@everget @brobear
Quite new to trading and don't know coding, but did you think of adding a kind of BB (standard deviation) to this wonderful line? Think it would show reversals quite nicely.
Thank you!
brobear
Nice work! Thanks for sharing :)

After going through the code, I convinced myself of some changes... Can you verify?

1) Line 16: replace "length" with "medianLength"
2) Line 13: replace "i" with "(i-1)"
...if medianLength = 5, then ceil(medianLength/2) = 3. If line 13 iterates from 0 to 3, that's 4 iterations. Thus grabbing the 4th minimum value, not the 3rd (median of 5).


Here's my rendition of the adaptive part of the Laguerre filter:

length = 20
medianLength = 5
alpha = na
alf = na

error = abs(src - nz(alf[1]))
range = highest(error, length) - lowest(error, length)
perc = range != 0 ? (error - lowest(error, length))/range : nz(alpha[1])
alpha := percentile_nearest_rank(perc, medianLength, 50.0) // Get value in the set, where 50% of all values are <= this value
//alpha := percentile_linear_interpolation(perc, medianLength, 50.0) // A variation on Ehler's definition

// ... continue with Laguerre filter

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

Ironically, I like the behavior of your code, where the 4th value (instead of 3rd) is returned for alpha. This makes the filter more responsive, while still mitigating noise. In my code, if I set the percentile to 75.0 (instead of 50.0), I get the same results as your code.

Cheers
everget
@brobear, Hi, thanks for your comments. I agree with you)
levith
@brobear, @brobear, 1) Line 16: replace "length" with "medianLength"
2) Line 13: replace "i" with "(i-1)"
...if medianLength = 5, then ceil(medianLength/2) = 3. If line 13 iterates from 0 to 3, that's 4 iterations. Thus grabbing the 4th minimum value, not the 3rd (median of 5).
I can't find the corresponding code,can you post a complete script? thank you!
everget
@levith, look at the changelog - there were many updates. The current version is correct
levith
@everget, 0!thank you!
devanshmak007
Hello! @everget, thank you for putting out this awesome indicator.
Can you please verify my python code and help me find out the mistake. The output comes out slightly off than actual tradingview values.
It'd be a great help for me! Thank you!

'''ALF FILTER''' :

L0,L1,L2,L3,L4,alpha, length, median_length =0,0,0,0,0,0,0,0
def AL_filter(temp,length,median_length):
global L0, L1, L2, L3, L4, alpha
for i in range(length,len(temp)):

x= i-length

temp["diff"] = abs(temp['Close'] - temp['Filter'][i-1])
temp["High"] = temp["diff"][x:i].max()
temp["Low"] = temp["diff"][x:i].min()

#########################
if (temp["High"][i - median_length:i] - temp["Low"][i - median_length:i]).median() !=0:
alpha = ((temp["diff"][i - median_length:i]-temp["Low"][i - median_length:i])/(temp["High"][i - median_length:i] - temp["Low"][i - median_length:i])).median()
if alpha == np.isnan(alpha): alpha = 0
############################

alpha2 = (1-alpha)

L0 = alpha*temp['Close'] + alpha2 * (L0)
L1 = L0 + alpha2*(L1- L0)
L2 = L1 + alpha2*(L2 - L1)
L3 = L2 +alpha2*(L3 -L2)

temp['Filter'] = (L0 + 2*L1 + 2*L2 +L3)/6
if temp['Filter'] == np.isnan(temp['Filter']): temp['Filter'] = 0
ikunalsingh
Hi, is their any way to add Buy & Sell as alert in the current code instead of "ALF has changed its color!"
Altro