OPEN-SOURCE SCRIPT
Better DEMA

The Better DEMA is a new tool designed to recreate the classical moving average DEMA, into a smoother, more reliable tool. Combining many methodologies, this script offers users a unique insight into market behavior.
How does it work?
First, to get a smoother signal, we need to calculate the Gaussian filter. A Gaussian filter is a smoothing filter that reduces noise and detail by averaging data with weights following a Gaussian (bell-shaped) curve.
Now that we have the source, we will calculate the following:
n2 = n/2 (half of the user defined length)
a = 2/(1+n)
ns
Now that we have that out of the way, it is time to get into the core.
Now we calculate 2 EMAs:
slow EMA => EMA over n
fast EMA => EMA over n2 period
Rather then now doing this:
DEMA = fast EMA * 2 - slow EMA
I found this to be better:
DEMA = slow EMA * (1-a) + fast EMA * a
As a last touch I took a little something from the HMA, and used a EMA with period of √n to smooth the entire the thing.
The Trend condition at base is the following (but feel free to FAFO with it):
Long = dema > dema yesterday and dema < src
Short = dema < dema yesterday and dema > src
Methodology
While the DEMA is an amazing tool used in many great indicators, it can be far too noisy.
This made me test out many filters, out of which the Gaussian performed best.
Then I tried out the non subtractive approach and that worked too, as it made it smoother.
Compacting on all I learned and smoothing it bit by bit, I think I can say this is worth looking into :).
Use cases:
Following Trends => classic, effective :)
Smoothing sources for other indicators => if done well enough, could be useful :)
Easy trend visualization => Added extra options for that.
Strategy development => Yes
Another good thing is it does not a high lookback period, so it should be better and less overfit.
That is all for today Gs,
Have fun and enjoy!
How does it work?
First, to get a smoother signal, we need to calculate the Gaussian filter. A Gaussian filter is a smoothing filter that reduces noise and detail by averaging data with weights following a Gaussian (bell-shaped) curve.
Now that we have the source, we will calculate the following:
n2 = n/2 (half of the user defined length)
a = 2/(1+n)
ns
Now that we have that out of the way, it is time to get into the core.
Now we calculate 2 EMAs:
slow EMA => EMA over n
fast EMA => EMA over n2 period
Rather then now doing this:
DEMA = fast EMA * 2 - slow EMA
I found this to be better:
DEMA = slow EMA * (1-a) + fast EMA * a
As a last touch I took a little something from the HMA, and used a EMA with period of √n to smooth the entire the thing.
The Trend condition at base is the following (but feel free to FAFO with it):
Long = dema > dema yesterday and dema < src
Short = dema < dema yesterday and dema > src
Methodology
While the DEMA is an amazing tool used in many great indicators, it can be far too noisy.
This made me test out many filters, out of which the Gaussian performed best.
Then I tried out the non subtractive approach and that worked too, as it made it smoother.
Compacting on all I learned and smoothing it bit by bit, I think I can say this is worth looking into :).
Use cases:
Following Trends => classic, effective :)
Smoothing sources for other indicators => if done well enough, could be useful :)
Easy trend visualization => Added extra options for that.
Strategy development => Yes
Another good thing is it does not a high lookback period, so it should be better and less overfit.
That is all for today Gs,
Have fun and enjoy!
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。