Ehlers Truncated BandPass Filter [CC]

Hot off the presses! The Truncated BandPass Filter was created by John Ehlers (Stocks & Commodities July 2020) and this is a much more reactive version of his original bandpass filter. When the indicator rises above 0 then it is an uptrend and when it falls below 0 then it is in a downtrend. Buy when the indicator line is red and sell when it is green.

Let me know if there are other scripts you would like to see me publish or if you want something custom done!
Release Notes: The FM Demodulator Indicator was created by John Ehlers (Stocks and Commodities May 2021 pg 14) and this is a very good complementary indicator to the new AM Detector that I just published. It uses his super smoother filter for smoothing but you can try other combos for smoothing. This indicator does a very good job tracking price swings as you can see it follows the major swings pretty well. Buy when the line turns green and sell when it turns red.

Let me know if there are any other indicators you would like to see me publish!
Release Notes: Ignore the previous release notes. Now that tv uses arrays I have fixed the indicator to work as originally intended
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


how is it better than original?
cheatcountry greyghost7
@greyghost7, there is a technical error right now with pinescript which isn't allowing me to correct the code. I will update this script as soon as they fix the bug
Here must be ...(1 + s1) * nz(trunc(1))... instead of ...(1 + s1) * nz(trunc(2)).... If you make such correction you get IIR Bandpass Filter not a truncated version.
cheatcountry harkalada31
@harkalada31, This was done on purpose because there is a technical issue with tv that prevents me from showing the correct code
harkalada31 cheatcountry
@cheatcountry, your code is incorrect. The idea of FIR filters, and truncated version of Bandpass Filter is a FIR filter, that you have to use coefficients with every element of the filter. In example with EMA in article this is demonstrated very well. There are only one element of previous values in EMA and that is why you use only one set of coefficients. In bandpass filter there are two such elements BP(1) and BP(2). To get FIR filter from IIR you have to use two set of coefficients. For that purpose Mr Ehlers uses arrays for calculation of truncated version of Bandpass Filter, one for BP(1) and another for BP(2).
Comparing your code with the traders' tips codes isn't the loop part missing ?
cheatcountry sal157011
@sal157011, he uses the loop to populate an array which isn't needed with pinescript
Hem Aktie-screener Forex-screener Krypto-screener Ekonomisk kalender Om Diagramfunktioner Priser Tipsa en vän Ordningsregler Hjälpcenter Webbsidor och mäklarlösningar Widgets Diagramlösningar Lightweight Charting Library Blogg och nyheter Twitter