[DSPrated] Modified EMD for swing tradeModified Ehlers Empirical Mode Decomposition indicator for swing trade based on Butterworth 2nd order IIR filter
Description
This script is inspired by John Ehlers' TECHNICAL PAPERS - Truncating Indicators and Empirical Mode Decomposition. But instead of detecting trend it applies to finding swing regions.
Also here is suggested canonical DSP approach for designing coefficients for Butterworth 2nd order IIR filters - bandpass and lowpass.
Besides, truncated IIR filter with configurable length parameter is used. It worth mentioning, that although truncated filter is more robust than original IIR, it losses specified properties (bandpass) the more, the less is length parameter.
Butterworth Bandpass Infinite Impulse Response (IIR) Filter
This is the 2nd order Butterworth Bandpass Infinite Impulse Response (IIR) Filter based on the transform from the 1st order lowpass
Based on the example 8.8 on p476 from book Digital Signal Processing: A Practical Approach 2nd Edition by Emmanuel C. Ifeachor (Author), Barrie W. Jervis (Author)
It differs from Ehlers BandPass Filter only in the way you initialize input parameters. Here you can define cutoff periods of region of interest. For example on a timeframe, where one bar equals 1 hour you can define periods 18 and 22, which mean you'll see the swing intensity of price movement components within specified range.
Parameters
Source
Period 1 - cutoff period of bandpass begining
Period 2 - cutoff period of the end of bandpass
length - IIR truncation length
Concept of usage
Within specified bandpass this indicator eliminates the Trend line according to Ehlers EMD. The bandpass periods is recommended to choose accordingly to personal comfortable trading style and timeframe.
The trendline painted with 3 colors depending of the next modes:
up tend - green
cycling - black
downtrend - red
So the buy signal is generated when trend line in cycling mode and filtered component reaches it local minimum.
And the sell signal is generated when trend line in cycling mode and filtered component reaches it local maximum.
Secure long and short zones marked with color.
---
// TO DO
// - compare truncated and full version using signal generators
// - apply zero lag filter modification fordetectig ternd and swing peroids
// - implement strategy scripts
// - implement somewhat "true" EMD with sevral IMFs(intrinsic mode function)
// - better description?
// - parameter optimization
---
Please, feel free to report any issues and improvement suggestions.
Truncated
Truncated Bandpass Filter and Bandpass Filter - Dr. John EhlersWith the arrival of the blessed gifts of arrays from TV, I now present the REAL "Truncated Bandpass Filter" indicator employing PSv4.0 upon initial release, originally formulated by the magnificent mathemagician Dr. John Ehlers for TASC - July 2020 Traders Tips. Don't be bamboozled by the other incorrect truncated bandpass filters found on TV, those published with an erroneous haste that preceded Pine array availability. More information about these bandpass filters can be acquired with a simple search for this indicator's white paper, entitled "TRUNCATED INDICATORS by John F. Ehlers", on his site in the educational reference section.
This actually contains two indicators, one being the truncated bandpass, the other being a two pole bandpass which is also found in my Voss implementation. The two pole bandpass is primarily for comparison of both types, but as you can see, they share common code within both, one being truncated and the other not. I modified Ehlers' original truncation formulation by allowing the capability to alter the truncation period using two distinct methods. I will explain very briefly that the purpose of a truncated "infinite impulse response" filter is to dampen it's response. Truncation techniques aren't limited to only bandpass filters, "some" other IIR filters, but not all, may benefit from this as well.
Lastly this is a miniature starter lesson by example of how the new native Pine array functions may be used, along with other various methods such as `var` to improve computational efficiency on the cloud servers. Yep, native Pine arrays just doubled the "Power of Pine" by exponential magnitudes of power into the dimension of what I would now term as the "Immense Power of Pine" . The next generation capability of programming extremely advanced indicators has now successfully arrived on mothership Earth, right on TradingView's front lawn. Who would of known?? This is brought to you in part by the devoted voluntary efforts of the most skilled poetic programmers on TV, the likes of which most extraterrestrial alien programmers would fear. Ladies and Gents, YOU KNOW WHO YOU ARE. Wink, wink!
NOTICE: You have absolute freedom to use this source code any way you see fit within your new Pine projects. You don't have to ask for my permission to reuse these functions in your published scripts, simply because I have better things to do than answer requests for the reuse of the tbpf() and bpf() functions. Sufficient accreditation regarding this script and compliance with "TV's House Rules" regarding code reuse, is as easy as copying the functions in their entirety as is. Fair enough? Good!
Features List Includes:
Dark Background - Easily disabled in indicator Settings->Style for "Light" charts or with Pine commenting
AND a few more... Why list them, when you have the source code to explore!
When available time provides itself, I will consider your inquiries, thoughts, and concepts presented below in the comments section, should you have any questions or comments regarding this indicator. When my indicators achieve more prevalent use by TV members, I may implement more ideas when they present themselves as worthy additions. Have a profitable future everyone!
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!