Login Page - Create Account

Support Board


Date/Time: Wed, 15 May 2024 06:58:35 +0000



Ehlers Even Better Sine Wave

View Count: 2240

[2021-01-21 14:28:22]
cmet - Posts: 538
Is it possible to get a native version of John Ehlers' Even Better Sine Wave in Sierrachart?

This study is from the 2013 book "Cycle Analytics for Traders" and is a great timing tool. Especially for intraday Futures data.


Here is the Easylanguage code from the book:


{
Even Better Sinewave Indicator © 2013 John F. Ehlers
}

Inputs:
Duration(40);
Vars:
alpha1(0),
HP(0),
a1(0),
b1(0),
c1(0),
c2(0),
c3(0),
Filt(0),
count(0),
Wave(0),
Pwr(0);

//HighPass filter cyclic components whose periods areshorter than Duration input

alpha1 = (1 - Sine (360 / Duration)) / Cosine(360 /
Duration);
HP = .5*(1 + alpha1)*(Close - Close[1]) + alpha1*HP[1];

//Smooth with a Super Smoother Filter from equation 3-3
a1 = expvalue(-1.414*3.14159 / 10);
b1 = 2*a1*Cosine(1.414*180 / 10);
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(HP + HP[1]) / 2 + c2*Filt[1] + c3*Filt[2];

//3 Bar average of Wave amplitude and power

Wave = (Filt + Filt[1] + Filt[2]) / 3;

Pwr = (Filt*Filt + Filt[1]*Filt[1] + Filt[2]*Filt[2]) / 3;

//Normalize the Average Wave to Square Root of the Average Power

Wave = Wave / SquareRoot(Pwr);

Plot1(Wave);



Image of plot attached.
imageebs.png / V - Attached On 2021-01-21 14:27:48 UTC - Size: 130.42 KB - 440 views
[2022-06-07 00:49:36]
SC Support Tom - Posts: 450
This is done. It will be available in the next release.
[2022-06-10 18:05:18]
cmet - Posts: 538
Is an input below 3 supposed to invert the plot on this?
[2022-06-13 21:57:56]
SC Support Tom - Posts: 450
WRT Post #3:


Is an input below 3 supposed to invert the plot on this?

No, there is no reason why that should happen.
[2022-06-13 22:32:13]
cmet - Posts: 538
Okay. Please check. Plot with a setting of 3. Then with 2 or 1.

There is clearly a huge difference in what's being plotted.
[2022-06-15 02:25:09]
SC Support Tom - Posts: 450
I am looking into it and will get back to you ASAP.
[2022-06-15 06:36:48]
SC Support Tom - Posts: 450
WRT Post #5:

I have just uploaded the documentation for this study. You can find it here:

Even Better Sinewave Indicator

The logic of the study is faithful to the code in Post #1. The problem is that you should not use n = 2. This is because, when n = 2, the smoothing constant (alpha1) is equal to -1. This means that the High Pass Filter HP is equal to 0 for all values of sc.Index. So when n = 2, the values of HP are random garbage that are only equivalent to 0 up to floating point precision.

I have made a note of this in the documentation.
[2022-06-15 21:31:43]
SC Support Tom - Posts: 450
I have just changed the lower limit of the Length Input to 3. I will edit the documentation accordingly.
[2022-06-15 21:44:24]
cmet - Posts: 538
Can you please not do that?

I'm using the Subgraph Multiply to flip the plot with a 2 setting. The plot is correct, it's just inverted.

Won't be able to upgrade without that ability being removed.
Date Time Of Last Edit: 2022-06-15 21:44:46
[2022-06-15 21:52:28]
SC Support Tom - Posts: 450
WRT Post #9:


The plot is correct, it's just inverted.

But the plot is not correct, even if you invert it. If n = 2, the indicator should be zero for all values of sc.Index. You are looking at a Subgraph that is generated by random numbers that are beyond floating point precision.

Please see the attached spreadsheet, which I generated using n = 2. The only reason that you see a Subgraph that is not zero everywhere is that the calculated values of HP differ slightly from zero, when they should be exactly zero.
Date Time Of Last Edit: 2022-06-15 22:56:41
attachmentEBSWI_n=2.scss - Attached On 2022-06-15 21:56:47 UTC - Size: 5.84 KB - 131 views
Attachment Deleted.
[2022-06-15 22:55:45]
cmet - Posts: 538
I don't see an image attached even when I log in. Just says Private File.

I'm sure what you're saying is right but please take a look at the attached image.

You can see that an input of 2 in the study interface, when inverted, plots like the 3 input but is a bit more responsive (faster).

That's exactly what you would expect.

All I'm asking is you don't put the limit on it so I can continue to use the study this way.
imageEBS.jpg / V - Attached On 2022-06-15 22:55:39 UTC - Size: 291.29 KB - 162 views
[2022-06-15 22:59:28]
SC Support Tom - Posts: 450
WRT Post #11:


I don't see an image attached even when I log in. Just says Private File.

I just made it public. Please have a look at it.


You can see that an input of 2 in the study interface, when inverted, plots like the 3 input but is a bit more responsive (faster).

It is more responsive, but with random data. This is a clear cut case of GIGO (Garbage In, Garbage Out).


That's exactly what you would expect.

No. A horizontal line at zero is exactly what you would expect.

Please observe:

alpha1 = (1 - sin(360/2))/cos(360/2) = (1 - sin(180))/cos(180) = (1 - 0)/(-1) = -1

HP = 0.5(-1 + 1)(Close - Close[1]) + (-1)HP[1]
HP = 0 - HP[1]
HP = -HP[1]

Since all Subgraphs are initialized to 0 by default, HP should be 0 for all values of sc.Index, and consequently, so should the values of the Indicator. But since the calculated values of HP differ slightly from zero, this is not what we see.

What you are looking at is due to the vagaries of floating point arithmetic in C++. That's it. It is not a problem for other values of the Length, because the errors are so small. But when the exact value of a calculation is 0, any error is a 100% error.

Strictly speaking, we should be disallowing a Length of 4 as well, since the exact value of alpha1 is undefined for that Length. But again, floating point error stops that from happening.


All I'm asking is you don't put the limit on it so I can continue to use the study this way.

I was directed to change it by one of my superiors who reviewed the thread, and I agree with him that it should be done. I will call him over here for a final ruling.

In the meantime, as a compromise, I am attaching a .cpp file for the EBSWI as an Advanced Custom Study that will allow you to use Lengths from 1 onwards. You can build it and use it.
Date Time Of Last Edit: 2022-06-16 02:33:33
attachmentscsf_EvenBetterSinewaveIndicator.cpp - Attached On 2022-06-15 23:17:06 UTC - Size: 2.45 KB - 116 views
[2022-06-16 13:09:32]
John - SC Support - Posts: 31627
We will not put out a study that can produce incorrect information, therefore we are limiting the inputs to ensure that people that are not as familiar with the study do not use it inappropriately.

But, this is also why these studies have their source code available. You can then modify it to your specific needs.

In order to do this, use the file that was supplied and then follow these instructions:
How to Build an Advanced Custom Study from Source Code: Step-By-Step Instructions
For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2022-06-16 13:19:43]
cmet - Posts: 538
Understood. However, if accuracy is the main goal no matter the setting, many other studies need to be looked at as well.

Especially those that include linear regression moving average as an option.

Ultimately, I think most users are using studies to help construct signals. If a particular setting produces a reliable, consistent signal over all data, then, in my opinion, it's useful.

Whether or not a user wants to use that setting should be up to them. Again, in my opinion.

I'll take a look at making an alt version. Thanks.
[2022-06-17 20:34:32]
SC Support Tom - Posts: 450
WRT Post #14


Understood. However, if accuracy is the main goal no matter the setting, many other studies need to be looked at as well.

That's a large part of what I do around here. Have you noticed those spreadsheet files at the bottom of most of the Technical Studies Reference pages? I made them.


Especially those that include linear regression moving average as an option.

The LRMA is just fine. I checked it myself. Using the default settings, the errors are on the order of magnitude of 10^(-6)%, as you can see in the attached spreadsheet.
Attachment Deleted.
Private File
[2022-06-20 00:09:03]
User90125 - Posts: 715
The LRMA is just fine. I checked it myself.

So why is there an error with the various Linear Regression Moving Averages found in SC when the Period is set to 1?

By convention, Moving Averages should output the input when set to 1. Please advise.
[2022-06-21 02:38:18]
SC Support Tom - Posts: 450
WRT Post #16


So why is there an error with the various Linear Regression Moving Averages found in SC when the Period is set to 1?

Because linear regression is impossible with a single data point. It just cannot be done. That is not a failure of the study. It is a feature of linear regression itself.


By convention, Moving Averages should output the input when set to 1.

If you are going to use a period of 1 just to get the output to be identical to the input, then why not just use the Simple Moving Average?


Please advise.

OK, I advise this: Do not use a period of 1 with LRMA. Linear regression makes absolutely no sense on a single chart bar.
Date Time Of Last Edit: 2022-06-21 09:33:43

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account