TradingView
cheatcountry
١١ تموز يوليو ٢٠٢٠ ١٧:٠٩

Ehlers 2 Pole Butterworth Filter V2 [CC] 

Apple Inc.NASDAQ

الوصف

The 2 Pole Butterworth Filter was created by John Ehlers (Cycle Analytics For Traders pg 32) and this is an updated version of his original 2 pole Butterworth Filter script that seems to follow the price even closer. Buy when the indicator line turns green and sell when it turns red.

Let me know if there are other scripts you would like to see me publish or if you want something custom done!
التعليقات
AndreiFX
Hi Cheatcountry, thanks for your work. Can i ask you?
In Ehlers' "Cycle Analytics ..." I read:
Output = c1 * Input - c2 * Output [1] - c3 * Output [2]
Minus!
In your code:
bf: = (c1 * src) + (c2 * nz (bf [1])) + (c3 * nz (bf [2]))
A plus! Why?
Or am I missing something?
cheatcountry
@AndreiFX, That was one of many errors in the book. If you use a minus sign instead then you would get a negative infinite number at some point which is obviously incorrect
AndreiFX
@cheatcountry, Thanks for the quick response )
cheatcountry
@AndreiFX, np let me know if you have any other questions
pleasantCardin94082
Interesting. Thank you for this. The sole change in the script as far as I can see is that you are now multiplying the square root of 2 (truncated) by 1.25. Just curious as to how you chose this- sqrt of 1.57?
cheatcountry
@pleasantCardin94082, np. There are quite a few changes actually. Different input for one thing and different methods to calculate the coefficient values. It was Ehlers idea to multiply the square root by 1.25 and this eliminates some of the noise
Chakku
Hey CheatCountry, you continue to amaze me ... This is what I have done with your code
cheatcountry
@Chakku, looks great. I would love to see the script behind this chart
Chakku
Hi Cheatcountry, Sure it is an honour.

//@version=4
// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
// Ehlers 2 Pole Butterworth Filter V2 [CC] script may be freely distributed under the MIT license.
study("Ehlers 2 Pole Butterworth Filter V2 [CC]", overlay=true)

inp = input(title="Source", type=input.source, defval=close)
res = input(title="Resolution", type=input.resolution, defval="")
rep = input(title="Allow Repainting?", type=input.bool, defval=false)
bar = input(title="Allow Bar Color Change?", type=input.bool, defval=false)
src = security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length1 = input(title="Length", type=input.integer, defval=10, minval=1)
length2 = input(title="Length", type=input.integer, defval=15, minval=1)
length3 = input(title="Length", type=input.integer, defval=45, minval=1)
length4 = input(title="Length", type=input.integer, defval=50, minval=1)

pi = 2 * asin(1)

a1 = exp(-1.414 * pi / length1)
a2 = exp(-1.414 * pi / length2)
a3 = exp(-1.414 * pi / length3)
a4 = exp(-1.414 * pi / length4)

b1 = 2 * a1 * cos(1.414 * 1.25 * pi / length1)
b2 = 2 * a2 * cos(1.414 * 1.25 * pi / length2)
b3 = 2 * a3 * cos(1.414 * 1.25 * pi / length3)
b4 = 2 * a4 * cos(1.414 * 1.25 * pi / length4)

cx1 = b1
cx2 = b2
cx3 = b3
cx4 = b4

cy1 = -a1 * a1
cy2 = -a2 * a2
cy3 = -a3 * a3
cy4 = -a4 * a4

c1 = 1 - cx1 - cy1
c2 = 1 - cx2 - cy2
c3 = 1 - cx3 - cy3
c4 = 1 - cx4 - cy4

bf1 = 0.0
bf2 = 0.0
bf3 = 0.0
bf4 = 0.0

bf1 := (c1 * src) + (cx1 * nz(bf1[1])) + (cy1 * nz(bf1[2]))
bf2 := (c2 * src) + (cx2 * nz(bf2[1])) + (cy2 * nz(bf2[2]))
bf3 := (c3 * src) + (cx3 * nz(bf3[1])) + (cy3 * nz(bf3[2]))
bf4 := (c4 * src) + (cx4 * nz(bf4[1])) + (cy4 * nz(bf4[2]))

//sig1 = src > bf1 ? 1 : src < bf1 ? -1 : 0

RED = #fd1206
BLUE = #0a1cf9

//bfColor1 = sig1 > 0 ? BLUE : sig1 < 0 ? RED : color.black
bfColor1 = bf1 > bf1[1] ? BLUE :bf1 < bf1[1] ? RED : color.black
bfColor2 = bf2 > bf2[1] ? BLUE :bf2 < bf2[1] ? RED : color.black
bfColor3 = bf3 > bf3[1] ? BLUE :bf3 < bf3[1] ? RED : color.black
bfColor4 = bf4 > bf4[1] ? BLUE :bf4 < bf4[1] ? RED : color.black

//alertcondition(crossover(sig, 0), "Buy Signal", "Bullish Change Detected")
//alertcondition(crossunder(sig, 0), "Sell Signal", "Bearish Change Detected")
//barcolor(bar ? bfColor1 : na)
plot(bf1, title="2PBF-1", color=bfColor1, linewidth=2)
plot(bf2, title="2PBF-2", color=bfColor2, linewidth=2)
plot(bf3, title="2PBF-3", color=bfColor3, linewidth=2)
plot(bf4, title="2PBF-4", color=bfColor4, linewidth=2)
cheatcountry
@Chakku, great job on this script!
المزيد