[blackcat] L2 Ehlers Autocorrelation PeriodogramLevel: 2
Background
John F. Ehlers introduced Autocorrelation Periodogram in his "Cycle Analytics for Traders" chapter 8 on 2013.
Function
Construction of the autocorrelation periodogram starts with the autocorrelation function using the minimum three bars of averaging. The cyclic information is extracted using a discrete Fourier transform (DFT) of the autocorrelation results. This approach has at least four distinct advantages over other spectral estimation techniques. These are:
1. Rapid response. The spectral estimates start to form within a half-cycle period of their initiation.
2. Relative cyclic power as a function of time is estimated. The autocorrelation at all cycle periods can be low if there are no cycles present, for example, during a trend. Previous works treated the maximum cycle amplitude at each time bar equally.
3. The autocorrelation is constrained to be between minus one and plus one regardless of the period of the measured cycle period. This obviates the need to compensate for Spectral Dilation of the cycle amplitude as a function of the cycle period.
4. The resolution of the cyclic measurement is inherently high and is independent of any windowing function of the price data.
The dominant cycle is extracted from the spectral estimate in the next block of code using a center-of-gravity (CG) algorithm. The CG algorithm measures the average center of two-dimensional objects. The algorithm computes the average period at which the powers are centered. That is the dominant cycle. The dominant cycle is a value that varies with time. The spectrum values vary between 0 and 1 after being normalized. These values are converted to colors. When the spectrum is greater than 0.5, the colors combine red and yellow, with yellow being the result when spectrum = 1 and red being the result when the spectrum = 0.5. When the spectrum is less than 0.5, the red saturation is decreased, with the result the color is black when spectrum = 0.
Key Signal
DominantCycle --> Dominant Cycle
Period --> Autocorrelation Periodogram Array
Pros and Cons
100% John F. Ehlers definition translation of original work, even variable names are the same. This help readers who would like to use pine to read his book. If you had read his works, then you will be quite familiar with my code style.
Remarks
The 49th script for Blackcat1402 John F. Ehlers Week publication.
Courtesy of @RicardoSantos for RGB functions.
Readme
In real life, I am a prolific inventor. I have successfully applied for more than 60 international and regional patents in the past 12 years. But in the past two years or so, I have tried to transfer my creativity to the development of trading strategies. Tradingview is the ideal platform for me. I am selecting and contributing some of the hundreds of scripts to publish in Tradingview community. Welcome everyone to interact with me to discuss these interesting pine scripts.
The scripts posted are categorized into 5 levels according to my efforts or manhours put into these works.
Level 1 : interesting script snippets or distinctive improvement from classic indicators or strategy. Level 1 scripts can usually appear in more complex indicators as a function module or element.
Level 2 : composite indicator/strategy. By selecting or combining several independent or dependent functions or sub indicators in proper way, the composite script exhibits a resonance phenomenon which can filter out noise or fake trading signal to enhance trading confidence level.
Level 3 : comprehensive indicator/strategy. They are simple trading systems based on my strategies. They are commonly containing several or all of entry signal, close signal, stop loss, take profit, re-entry, risk management, and position sizing techniques. Even some interesting fundamental and mass psychological aspects are incorporated.
Level 4 : script snippets or functions that do not disclose source code. Interesting element that can reveal market laws and work as raw material for indicators and strategies. If you find Level 1~2 scripts are helpful, Level 4 is a private version that took me far more efforts to develop.
Level 5 : indicator/strategy that do not disclose source code. private version of Level 3 script with my accumulated script processing skills or a large number of custom functions. I had a private function library built in past two years. Level 5 scripts use many of them to achieve private trading strategy.
Autocorrelation
[blackcat] L2 Ehlers Autocorrelation IndicatorLevel: 2
Background
John F. Ehlers introduced Autocorrelation Indicator in his "Cycle Analytics for Traders" chapter 8 on 2013.
Function
If we correlate a waveform composed of perfectly random numbers by itself, the correlation will be perfect. However, if we lag one of the data streams by just one bar, the correlation will be dramatically reduced. In a long memory process with normally distributed random numbers the autocorrelation follows the power law.
One of the underlying principles of technical analysis is that market data do not follow this power law of an efficient market, and we therefore can extract information from the partial correlation of the autocorrelation function. For example, assume the data being examined is a perfect sine wave whose period is 20 bars. The autocorrelation with zero lag, averaged over one full period of the sine wave, is unity. That is, the correlation is perfect. Introducing a lag of one bar in the autocorrelation process causes the average correlation to be decreased slightly. Introducing another bar of lag further decreases the average correlation, and so on. That is, until a lag of 10 bars is reached. In this case, the positive alternation of the sine wave is correlated with the negative alternation of the lagged waveform and the negative alternation of the sine wave is correlated with the positive alternation of the lagged waveform, with the result that perfect anticorrelation has been reached. Continued lag increases causes the average correlation to increase until a lag of 20 bars is reached. When the lag is equal to the period of the sine wave waveform, the correlation is again perfect. In this theoretical example, the correlation values as a function of lag vary exactly as a sine wave.
Market data are considerably messier than purely random numbers or perfect sine waves but contain features of both. However, the characteristics that are uncovered by autocorrelation offer unique trading perspectives. Aside from appearing psychedelic, there are two distinct characteristics of the autocorrelation indicator using minimum averaging. First, there is a sharp reversal from red to yellow and from yellow to red at the timing of price reversals for all periods of lag. Second, there is a variation of the thickness of the bars and the number of bars over the vertical range of the indicator as a function of time.
Key Signal
Corr --> Pearson correlation data array
Pros and Cons
I am sorry this script is NOT 100% as original Ehlers works but I modified it accordingly which demostrated with better visual effect.
Remarks
The 47th script for Blackcat1402 John F. Ehlers Week publication.
Courtesy of @RicardoSantos for RGB functions.
Readme
In real life, I am a prolific inventor. I have successfully applied for more than 60 international and regional patents in the past 12 years. But in the past two years or so, I have tried to transfer my creativity to the development of trading strategies. Tradingview is the ideal platform for me. I am selecting and contributing some of the hundreds of scripts to publish in Tradingview community. Welcome everyone to interact with me to discuss these interesting pine scripts.
The scripts posted are categorized into 5 levels according to my efforts or manhours put into these works.
Level 1 : interesting script snippets or distinctive improvement from classic indicators or strategy. Level 1 scripts can usually appear in more complex indicators as a function module or element.
Level 2 : composite indicator/strategy. By selecting or combining several independent or dependent functions or sub indicators in proper way, the composite script exhibits a resonance phenomenon which can filter out noise or fake trading signal to enhance trading confidence level.
Level 3 : comprehensive indicator/strategy. They are simple trading systems based on my strategies. They are commonly containing several or all of entry signal, close signal, stop loss, take profit, re-entry, risk management, and position sizing techniques. Even some interesting fundamental and mass psychological aspects are incorporated.
Level 4 : script snippets or functions that do not disclose source code. Interesting element that can reveal market laws and work as raw material for indicators and strategies. If you find Level 1~2 scripts are helpful, Level 4 is a private version that took me far more efforts to develop.
Level 5 : indicator/strategy that do not disclose source code. private version of Level 3 script with my accumulated script processing skills or a large number of custom functions. I had a private function library built in past two years. Level 5 scripts use many of them to achieve private trading strategy.
AutocorrelogramFast estimation of an autocorrelogram, more commonly called autocorrelation function (ACF). The script sets the maximum lag as 10*log10(N)-1 and sets the autocorrelation at lag 0 to 1.
Length controls the number of past observations of Src to use as input, while Differentiate Src perform first order differencing to Src before calculating the autoccorelations.
The ACF can return a lot of information, for technical analysis, the ACF can be used to determine whether the market is trending or ranging. Without prior processing, we expect trending prices to have a slowly decaying ACF with significant autocorrelation at each lag, while ranging prices will have an ACF that decay faster toward 0.
I won't post a lot on this profile, I'll post most of my future work on the LuxAlgo profile instead, link in the signature.
Ehler's Autocorrelation Periodogram - RSI/MFIWarning! Frequently hits the execution time limit for scripts.
Especially on initially adding to your chart. Often requires toggling show/hide indicator to get it to complete script execution within the time limit. YMMV!
From TASC Sept 2016 this is Ehler's Autocorrelation periodogram. A means of determining the dominant cycle ("ideal" indicator length / dynamic length).
As an example it's applied here to RSI or MFI. Lower indicator segment displays the autocorrelation spectrum and the computed dominant cycle. Upper segment is RSI/MFI.
Autocorrelation PlotA tool to plot auto correlation of time series, this is useful in identifying periodicity in a time series or signal.
Due to the limits of Pine Script you'll need to add it multiple times if you want autocorrelation beyond 55 periods. I have added it 4 times here for 220 periods.
For more information on Autocorrelation see: en.wikipedia.org
Note: There are 1 bar gaps every 55 because I wanted the labels to remain every 5, but you don't have to have gaps....
Ehlers Correlation Trend Indicator CTI by Cryptorhythms [CR]Ehlers Correlation Trend Indicator CTI by Cryptorhythms
📜Intro
In his article “Correlation As A Trend Indicator” in issue May 2020 of TASC, author John Ehlers introduces a new trend indicator that is based on the correlation between a security’s price history and the ideal trend: a straight line. He describes methods for using the indicator to not only identify the onset of new trends but to identify trend failures as well. He presents what looks like a simple and elegant idea for a trend-detection and mode-switching indicator.
📋Comments
Careful market selection may be the key to a correct application of the indicator. Even such barebone rules could shine with stocks like AAPL that tend to develop prolonged trends. But for others like CAT, which can keep oscillating in ranges for years, results will be much less impressive. They require a different approach. For example, you would want to buy when Correlation Trend falls significantly below zero and sell when it reaches positive values.
Therefore, it would be an interesting problem to research Correlation Trend’s ability to identify the switch to a cycle mode. That might help develop countertrend systems and
trade pullbacks. Another possible application might be to act as a system filter of change from trending mode to mean-reversion mode.
Extras
As usual when porting indicators to the library here on tradingview, I like to add some extra flare!
💠Customizable Overbought and Oversold Zones for Alert Creation
💠Bar coloration based on trade state for easy visual at a glance chart checking
💠Some basic example Entry and Exit conditions and a simple Trade State Engine to get you going creating your own strategy
Enjoy!
👍 We hope you enjoyed this indicator and find it useful! We post free crypto analysis, strategies and indicators regularly. This is our 81st script on Tradingview!
Multistep AutocorrelationAutocorrelation, also known as serial correlation, is the correlation of a signal with a delayed copy of itself as a function of delay. Informally, it is the similarity between observations as a function of the time lag between them. The analysis of autocorrelation is a mathematical tool for finding repeating patterns, such as the presence of a periodic signal obscured by noise, or identifying the missing fundamental frequency in a signal implied by its harmonic frequencies. It is often used in signal processing for analyzing functions or series of values, such as time domain signals.
This multistep autocorrelation function calculates the correlation of roc (rate of change) between an asset at t and t-1 as well as the correlation of the same asset at t and t-4. The output is an average of the two.
If both outputs show a positive correlation, the color will be green.
If only one shows a positive correlation, the color will be yellow.
If neither show a positive correlation, the color will be red.
This indicator can be useful as a filter for strategy entry logic (only enter on strong correlation and the strategy entry condition), or as standalone confirmation of strength in a specific direction. It can also be used to filter chop.
Another potential usecase would be as a variable in regression applications.
Enjoy!