dema: Double Exponential Moving Average

Description Usage Arguments Details See Also Examples

Description

dema performs exponential smoothing twice on the same vector.
This is not the same as the DEMA typically used in technical trading.

Usage

1
dema(x, a = 2, direction = c("ff", "fb", "bf", "av"))

Arguments

x

a numeric vector

a

numeric; smoothing factor

direction

character; should the two moving averages be run

  • ff: forwards both times

  • fb: forwards then backwards

  • bf: backwards then forwards

  • av: both fb and bf, returning the average

Details

The moving averages are done as in ema, except that the root-two'th root of a is used, to make the outputs more comparable.

That is

a* = a^(1/sqrt(2))

See Also

ema, iema

Examples

1
2
3
4
5
6
s <- c(0, 0, 1, NA, 2, 0, 1, 1, NA, NA, 2, NA, 3, 1, 2, 1, 0, 1, NA, 0, 0, 0)
plot(s, type="b", col="#00000088")
lines(dema(s, 2, dir="ff"), col=2)
lines(dema(s, 2, dir="fb"), col=3)
lines(dema(s, 2, dir="bf"), col=4)
lines(dema(s, 2, dir="av"), col=5)

AkselA/R-rollfun documentation built on May 31, 2019, 8:41 a.m.