blackcat1402

[blackcat] L2 Ehlers Sine Wave Indicator

Level: 2

Background

John F. Ehlers introuced Sine Wave Indicator in his "Rocket Science for Traders" chapter 9.

Function

blackcat L2 Ehlers Sine Wave Indicator compared to conventional oscillators such as the Stochastic or Relative Strength Indicator ( RSI ), the Sinewave Indicator has two major advantages. These are
1. The Sinewave Indicator anticipates the Cycle Mode turning point rather than waiting for confirmation.
2. The phase does not advance when the market is in a Trend Mode. Therefore, the Sinewave Indicator tends to not give false whipsaw signals when the market is in a Trend Mode.
An additional advantage is that the anticipation signal is obtained strictly by mathematically advancing the phase. Momentum is not employed. Therefore, the Sinewave Indicator signals are no more noisy than the original signal.


Key Signal

Smooth --> 4 bar WMA w/ 1 bar lag
Detrender --> The amplitude response of a minimum-length HT can be improved by adjusting the filter coefficients by
trial and error. HT does not allow DC component at zero frequency for transformation. So, Detrender is used to remove DC component/ trend component.
Q1 --> Quadrature phase signal
I1 --> In-phase signal
Period --> Dominant Cycle in bars
SmoothPeriod --> Period with complex averaging
DCPhase ---> dominant cycle phase for sine wave

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 8th script for Blackcat1402 John F. Ehlers Week publication.

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.
Release Notes: based on important reminding from @@sal157011
i corrected the errors in original books and now sinewave indicator look much better :D
the new corrections in this update are:
change origintal script to grammar as below:
....... RealPart = RealPart + Sine(360*count/DCPeriod)*(SmoothPrice(count));
....... ImagPart = ImagPart + Cosine(360*count/DCPeriod)*(SmoothPrice(count);
....... If AbsValue(ImagPart) > 0 then DCPhase = Arctangent(RealPart/ImagPart);
....... If AbsValue(ImagPart) <= .001 then DCPhase = DCPhase + 90*Sign(RealPart):
Release Notes: 1. Add buy and sell labels
2. sine wave indicator is inverse with price trend as claimed by Dr. Ehlers
Release Notes: Correct label bar_index issue
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?
"Win$ & Donate w/ This" Address:
BTC: 1GeuxGE6UUato7AgMnNUjSg56mSzQ6Wxxk
USDT TRC20: TWVYATJFN7SsbrmH8jLVrWHaV2aNruvvcT
USDT ERC20: 0xfd4d0eb131e81f44530849c1a966cb261dd6bda2
ETH: 0xfd4d0eb131e81f44530849c1a966cb261dd6bda2
LINK: 0xfd4d0eb131e81f44530849

Comments

The code on the book has some errors. Ehlers on his site had an errata that is no longer available.
I paste that errata bellow. This editor doesn't write the square brackets so I warn you that after Price, SmoothPrice, Low and Predict there are 2 square brackets missing.
See other implementations of this sine wave code on other Tradingview scripts.
------------------------------
As many times as the book was editied, some errors still got through. Here are the new corrections:
page 25: the correct equation is WMA = (4*Price + 3*Price(1) + 2*Price(2) + Price(3))/10;

page 56: the lag of the Hilbert Transform is 7 bars.

page 80: Figure 8.1 (a) and (b) are reversed.

pages 98 and 102 and 116 and 120 & 121: the code should be corrected to be:
....... RealPart = RealPart + Sine(360*count/DCPeriod)*(SmoothPrice(count));
....... ImagPart = ImagPart + Cosine(360*count/DCPeriod)*(SmoothPrice(count);
....... If AbsValue(ImagPart) > 0 then DCPhase = Arctangent(RealPart/ImagPart);
....... If AbsValue(ImagPart) <= .001 then DCPhase = DCPhase + 90*Sign(RealPart):
page 175: Figure 16.3 The fourth line from the end should corrected to be:
....... > Low(1) and Close < High - (High -
page 183: Figure 17.1. The word "Speed" should be replaced with "FastLimit"
page 212: Figure 20.4. The code should be corrected to be:
....... Trigger = (4*Predict + 3*Predict(1) + 2*Predict(2) + Predict(3)) / 10;
+2 Reply
blackcat1402 sal157011
@sal157011, thank you very much for sharing these precious information, this is the biggest gain I have released the Ehlers script this week! I reviewed the original book based on your information. As you said, these errors do exist, and some are very hidden. I share the results of my investigation as follows:
page 25: the correct equation is WMA = (4*Price + 3*Price(1) + 2*Price(2) + Price(3))/10;
blackcat1402: this error did not happen in EL scripts in the book.

page 56: the lag of the Hilbert Transform is 7 bars.
this error does not impact scripts and translations.

page 80: Figure 8.1 (a) and (b) are reversed.
blackcat1402: this error is obvious but really make me confused during reading.

pages 98 and 102 and 116 and 120 & 121: the code should be corrected to be:
....... RealPart = RealPart + Sine(360*count/DCPeriod)*(SmoothPrice(count));
....... ImagPart = ImagPart + Cosine(360*count/DCPeriod)*(SmoothPrice(count);
....... If AbsValue(ImagPart) > 0 then DCPhase = Arctangent(RealPart/ImagPart);
....... If AbsValue(ImagPart) <= .001 then DCPhase = DCPhase + 90*Sign(RealPart):
blackcat1402: this error impacts "computing the dominant cycle phase", "Sinewave Indicator", "identify the market mode", and "automatic sinetrend trading system".

page 175: Figure 16.3 The fourth line from the end should corrected to be:
....... > Low(1) and Close < High - (High -
blackcat1402: this error impacts "zerolag intraday trading system"

page 183: Figure 17.1. The word "Speed" should be replaced with "FastLimit"
blackcat1402: this error impacts "MAMA"

page 212: Figure 20.4. The code should be corrected to be:
....... Trigger = (4*Predict + 3*Predict(1) + 2*Predict(2) + Predict(3)) / 10;
blackcat1402: this error impacts "compute predictive averages"
+1 Reply