[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.
Iir
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!
Combination Parabolic MA/IIR/ALMA Strategy, with other goodiesOkay, so this is a lot. It started mostly with me combining indicators and looking for ideal entry criteria.
It is also a collection of conditions, whether used or unused, for my current chosen "best" strategy. It is currently set how I like it, but it has changed with time, and will continue to do so. Within, there are variables that are unused, but offer some insight into the overall odds of a trade. They were, in fact, once used but fell out of favor. And all details for this strategy are within the comment header of the script.
As this evolves, I most certainly wont keep any future findings and hope for profit from my peers (yinz). Also, I'd like to give a sincere thanks to the people of TV for what I learned in a few month's time and their flexible membership plans. Basically, I'm just a mad scientist, but this monster's a masterpiece and folks here before me made many indirect contributions to it.
--------------------------
Okay guys, lastly and most importantly,
Each smack of the like button is a vote of your confidence in me, to my beautiful landladies, Celeste and Adele, that my rent will be caught up and that it won't always be a problem. Which, in my mind, makes me a graph. And they've got strong hands and don't sell the low. I more than respect that. Seriously. And I'm very grateful for their willingness to work with me, but the thing is that I didn't ask first; life just happens. But few are tolerant of others. And quite importantly, I truly believe that I will be successful one day, and that "thumbs-up" button is your vote of confidence. If you're not sure, then don't hit it yet. Maybe my scripts will boost your confidence in me :)
-------------------------
PS: And you know what? I'ma give a shout-out to Philakone for teaching me everything that I know about Elliot Wave . Absolutely. Two years ago, I would keep telling myself that one day I will put something in his gratuity wallet or pursue the paid courses. And, I still plan on it, because I'm grateful. And so also, to everybody else, I'm recommending him to learn from. because as a trader who might not know everything for free, you can certainly fill in the gaps with his altruistic offerings. And I'm betting that you will then feel more than inclined to buy the Udemy course.
"If wave 2 retraces a lot; number 4 will not". Repetition. Philakone didn't fix my memory but he sure did find a workaround, haha
Okay, everyone, Thanks!
Realized Volatility IIR Filters with BandsDISCLAIMER:
The Following indicator/code IS NOT intended to be a formal investment advice or recommendation by the author, nor should be construed as such. Users will be fully responsible by their use regarding their own trading vehicles/assets.
The following indicator was made for NON LUCRATIVE ACTIVITIES and must remain as is following TradingView's regulations. Use of indicator and their code are published by Invitation Only for work and knowledge sharing. All access granted over it, their use, copy or re-use should mention authorship(s) and origin(s).
WARNING NOTICE!
THE INCLUDED FUNCTION MUST BE CONSIDERED AS TESTING. The models included in the indicator have been taken from open sources on the web and some of them has been modified by the author, problems could occur at diverse data sceneries.
WHAT'S THIS...?
Work derived by previous own research for study:
This is mainly an INFINITE IMPULSE RESPONSE FILTERING INDICATOR , it's purpose is to catch trend given by the nature of lag given by a VOLATILITY ESTIMATION ALGORITHM as it's coefficient. It provides as well an INFINITE IMPULSE RESPONSE DEVIATION FILTER that uses the same coefficients of the main filter to plot deviation bands as an auxiliary tool.
The given Filter based indicator provides my own Multi Volatility-Estimators Function with only 3 models:
ELASTIC VOLUME WEIGHTED VOLATILITY : This is a Modified Daigler & Padungsaksawasdi "Volume Weighted Volatility" as on DOI: 10.1504/IJBAAF.2018.089423 but with Elastic Volume Weighted Moving Average instead of VWAP (intraday) for faster (but inaccurate) calculation. A future version is planned on the way using intra-bar inspection for intraday timeframe as described in original paper.
GARMAN & KLASS / YANG-ZANG EXTENSION : As one of the best range based (OHLC) with open gaps inclusion in a single bar.
PETER MARTIN'S ULCER INDEX : This is a better approach to measure realized volatility than standard deviation of log returns given it's proven convex risk metric for DrawDowns as shown in Chekhlov et al. (2005) . Regarding this particular model, I take a different approach to use it as coefficient feed: Given that the UI only takes in consideration DrawDawns, I code myself the inverse of this to compute Draw-Ups as well and use both of them to filter minimums volatility levels in order to create a SLOW version of the IIR filter, and maximums of both to calculate as FAST variation. This approach can be used as a better proxy instead of any other common moving average given that with NO COMPOUND IN TIME AT ALL (N=1) or only using as long as N=3 bars of compund, the filter can catch a trend easily, making the indicator nearly a NON PARAMETRIC FILTER.
NOTES:
This version DO NOT INCLUDE ALERTS.
This version DO NOT INCLUDE STRATEGY: ALL Feedback welcome.
DERIVED WORK:
Incremental calculation of weighted mean and variance by Tony Finch (fanf2@cam. ac .uk) (dot@dotat.at), 2009.
Volume weighted volatility: empirical evidence for a new realised volatility measure by Chaiyuth Padungsaksawasdi & Robert T. Daigler, 2018.
Basic DSP Tips & Trics by TradingView user @alexgrover
CHEERS!
@XeL_Arjona 2020.
IIR Least-Squares EstimateIntroduction
Another lsma estimate, i don't think you are surprised, the lsma is my favorite low-lag filter and i derived it so many times that our relationship became quite intimate. So i already talked about the classical method, the line-rescaling method and many others, but we did not made to many IIR estimate, the only one was made using a general filter estimator and was pretty inaccurate, this is why i wanted to retry the challenge.
Before talking about the formula lets breakdown again what IIR mean, IIR = infinite impulse response, the impulse response of an IIR filter goes on forever, this is why its infinite, such filters use recursion, this mean they use output's as input's, they are extremely efficient.
The Calculation
The calculation is made with only 1 pole, this mean we only use 1 output value with the same index as input, more poles often means a transition band closer to the cutoff frequency.
Our filter is in the form of :
y = a*x+y - a*ema(y,length/2)
where y = x when t = 1 and y(1) when t > 2 and a = 4/(length+2)
This is also an alternate form of exponential moving average but smoothing the last output terms with another exponential moving average reduce the lag.
Comparison
Lets see the accuracy of our estimate.
Sometimes our estimate follow better the trend, there isn't a clear result about the overshoot/undershoot response, sometimes the estimate have less overshoot/undershoot and sometime its the one with the highest.
The estimate behave nicely with short length periods.
Conclusion
Some surprises, the estimate can at least act as a good low-lag filter, sometimes it also behave better than the lsma by smoothing more. IIR estimate are harder to make but this one look really correct.
If you are looking for something or just want to say thanks try to pm me :)
Thank for reading !
One Dimensional Parametric Kalman FilterA One Dimensional Kalman Filter, the particularity of Kalman Filtering is the constant recalculation of the Error between the measurements and the estimate.This version is modified to allow more/less filtering using an alternative calculation of the error measurement.
Camparison of the Kalman filter Red with a moving average Black of both period 50
Can be used as source for others indicators such as stochastic/rsi/moving averages...etc
For any questions/suggestions feel free to contact me
Butterworth FilterButterworth Filter script.
This indicator was described by John F. Ehlers in his book "Rocket Science for Traders" (2001, Chapter 15: Infinite Impulse Response Filters).
Retrospective Candlestick ChartWhen i was in Japan with some traders colleagues we talked about traditional charting tools from this country and how they changed the way we look at our charts today. Then suddenly one of the japanese traders i have met earlier said "Why not making another charting tool ? Smoother than Heikin-Ashi and including all the information a trader may need but easier to interpret".
So i had the idea of averaging the input and the output of the respective close / open / high and low price using a recursive exponential window functions, each values will be closer to their true value if they are volatile, if they are not then those values will look smoother, the length input represents the reactivity of the candles, high values represents smoother results but less reactive.The goal of those candles is to make all the information easier to interpret by a trader.
500 input length , the price look smoother, supports and resistances are easier to make.
The interpretation of highs and lows are important, the Retrospective Candlestick Chart save you time by showing only huge movements.
Infinite Impulse Response (IIR) FilterInfinite Impulse Response (IIR) Filter indicator script.
This indicator was originally developed by John Ehlers (Stocks & Commodities V. 20:7 (26-31): Zero-Lag Data Smoothers).