DEMA and TEMA are technical indicators built into MetaTrader 5 (MT5). Abbreviations for Double Exponential Moving Average and Triple Exponential Moving Average, respectively, which are translated as double exponential moving average and triple exponential moving average.
In this article, we'll look at the differences between EMA, DEMA, and TEMA.
EMA Below is a basic description of the EMA. Comparing IIR filter type moving averages with pandas and scipy
The formula is
DEMA
DEMA is an abbreviation for Double EMA, but it is not just about applying EMA twice. Even if you apply EMA twice, the smoothing will only proceed and you will not get very characteristic characteristics.
The above EMA formula
Then, the formula of DEMA is
Can be written. I also use double EMA, but I also use EMA to calculate. The derivation principle of this formula is described in here.
TEMA
The formula for TEMA is
Write, and calculate using triple EMA, double EMA, and EMA. The derivation principle of this formula is here.
Here is an example of applying EMA, DEMA, and TEMA to the Forex chart.
This is what is displayed on the MT5 chart, red is EMA, blue is DMA, and green is TEMA. All periods are also $ period = 14 $.
Looking at this, we can see that DEMA, TEMA and price followability are higher than EMA. In other words, the delay that tends to be a moving average is reduced. However, I feel that the noise is increasing.
The difference in the above processing example can be explained by the difference in frequency characteristics.
Comparing IIR filter type moving averages with pandas and scipy
According to the EMA system function, it can be written as:
Using this, the system functions of DEMA and TEMA are as follows.
Substituting $ H_ {EMA} (z) $ into this and dividing it, the result is as follows.
However, $ b_0 = \ alpha (2- \ alpha) $, $ b_1 = 2 \ alpha (\ alpha-1) $, $ a_0 = 1 $, $ a_1 = 2 (\ alpha-1) $, $ a_2 = (1- \ alpha) ^ 2 $
However, $ b_0 = 3 \ alpha (1- \ alpha) + \ alpha ^ 3 $, $ b_1 = 3 \ alpha (\ alpha-2) (1- \ alpha) $, $ b_2 = 3 \ alpha (1- \ alpha) ^ 2 $, $ a_0 = 1 $, $ a_1 = 3 (\ alpha-1) $, $ a_2 = 3 (1- \ alpha) ^ 2 $, $ a_3 = (\ alpha-1) ^ 3 $
With this transformation, you can use the functions freqz
and group_delay
that calculate the frequency characteristics with the coefficients of the molecular polynomial and denominator polynomial in Python's scipy as arguments.
Let's find the amplitude characteristics of each EMA with the following code.
%matplotlib inline
import numpy as np
import scipy.signal as sp
import matplotlib.pyplot as plt
period = 14 #period
alpha = 2/(period+1)
#EMA
a = [1, alpha-1]
b = alpha
w, h = sp.freqz(b, a)
#DEMA
a_d = [1, 2*(alpha-1), (1-alpha)**2]
b_d = [alpha*(2-alpha), 2*alpha*(alpha-1)]
w, h_d = sp.freqz(b_d, a_d)
#TEMA
a_t = [1, 3*(alpha-1), 3*(1-alpha)**2, (alpha-1)**3]
b_t = [3*alpha*(1-alpha)+alpha**3, 3*alpha*(alpha-2)*(1-alpha), 3*alpha*(1-alpha)**2]
w, h_t = sp.freqz(b_t, a_t)
plt.xlabel('Frequency(rad/s)')
plt.ylabel('Amplitude')
plt.plot(w, abs(h), 'r', label='EMA')
plt.plot(w, abs(h_d), 'b', label='DEMA')
plt.plot(w, abs(h_t), 'g', label='TEMA')
plt.legend(loc="best")
Basically, the moving average shows the characteristics of a low-pass filter that passes low frequencies, but compared to EMA, DEMA and TEMA have a slightly wider band to pass through. Due to this, some high frequency signals remain. Therefore, DEMA and TEMA had some noise left compared to EMA.
Next, among the frequency characteristics, let's find the group delay characteristic that differentiates the phase characteristic.
#Group delay characteristics
w, gd = sp.group_delay((b, a))
w, gd_d = sp.group_delay((b_d, a_d))
w, gd_t = sp.group_delay((b_t, a_t))
plt.xlabel('Frequency(rad/s)')
plt.ylabel('Group delay')
plt.plot(w, gd, 'r', label='EMA')
plt.plot(w, gd_d, 'b', label='DEMA')
plt.plot(w, gd_t, 'g', label='TEMA')
plt.legend(loc="best")
The group delay characteristic represents the delay of the signal at that frequency. Looking at this, EMA has a large delay at low frequencies, while DEMA and TEMA have a small delay. The high followability to input changes can be explained by this group delay characteristic.
Recommended Posts