## EVWMA

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

### EVWMA

Hi there!

I know we have the VWMA (volume weighted moving average), but I haven't seen the exponential version of it (so VWMA is simple, i guess).

I found this code here but I can't say if this is indeed the right formula of a EVWMA:

Volume-weighted Exponential Moving Average (V-EMA)

We collect Price and Volume data for some stock (or mutual fund), for the past N days, namely:
(P1, V1), (P2, V2), (P3, V3), ... (PN, VN)
and compute, with this info:

Num(Now) = EMA of last N values of (Volume)*(Price)
and
Den(Now) = EMA of last N values of (Volume)
>That doesn't explain how to calculate them!
Patience. Tomorrow, once we've got the Price, PN+1, and Volume, VN+1, we calculate:

Magic Formula :
V-EMA(Next) = Num(Next)/Den(Next)
where
Num(Next) = α Num(Now) + (1 - α) VN+1 PN+1
and
Den(Next) = α Den(Now) + (1 - α) VN+1
and "Num" and "Den" stand for Numerator and Denominator, respectively
and α = 1 - 2/(N + 1) so, for N = 14 (a 14-day V-EMA) we'd have α = 1 - 2/15 = 0.867
(See Technical Analysis stuff.)

To start this procedure (before we've got a bunch of Prices and Volumes) we just use

Num(Now) = (1 - α) Volume x Price and Den(Now) = (1 - α) Volume
Thereafter, we use the Magic Formula.

>Example?
Okay, suppose the closing Price and Volume are \$23.50 and 5,250.9, in thousands of shares traded. Suppose, further, that we're working with a 14-day moving average, so

α = 0.867.
and
Num(Now) = (1-0.867) (5,250.9) (23.50) = 16,412
and
Den(Now) = (1-0.867) (5,250.9) = 698.37
so
V-EMA(Now) = Num(Now)/Den(Now) = 16412/698.37 = \$23.50 hence ...
>But that's just today's price!
I'm glad you noticed. However, we need to have a starting value for Num and Den. Tomorrow, we suppose that our Price and Volume are \$24.50 and 1,477.8 kilo-shares, so now we use Magic Formula :

Num(Next) = α Num(Now) + (1 - α) VN+1 PN+1 = 0.867(16412)+(1-0.867)(1477.8)(24.50) = 19044.6
and
Den(Next) = α Den(Now) + (1 - α) VN+1 = 0.867(698.37)+(1-0.867)(1477.8) = 802.03
so
V-EMA = 19044.6/802.03 = \$23.74
>And so on ... and so on.
Right. As we continue, we generate a Volume-weighted Exponential Moving Average
logicgate

Posts: 223
Joined: Tue Dec 11, 2018 7:54 am

### Re: EVWMA

Just wanted to let you know that this is for MT4 ok brother? Thanks!
logicgate

Posts: 223
Joined: Tue Dec 11, 2018 7:54 am

### Re: EVWMA

Try Smoothed Volume Weighted Moving Average.mq4
viewtopic.php?f=38&t=67144 Apprentice
FXCodeBase: Confirmed User

Posts: 21785
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: EVWMA

Hello dear friend! Thanks!

I will check it, but I don't think that it is the same result. Applying smoothing to smoothing is not the same than the calculation to generate a exponential moving average.
logicgate

Posts: 223
Joined: Tue Dec 11, 2018 7:54 am

### Re: EVWMA

Dear friend apprentice, I found a code for the EVWMA:

VEMA <- function(x, volumes, n = 10, wilder = F, ratio = NULL, ...)
{
x <- try.xts(x, error = as.matrix)
if (n < 1 || n > NROW(x))
stop("Invalid 'n'")
if (any(nNonNA <- n > colSums(!is.na(x))))
stop("n > number of non-NA values in column(s) ", paste(which(nNonNA),
collapse = ", "))
x.na <- xts:::naCheck(x, n)
if (missing(n) &#038;&#038; !missing(ratio))
n <- trunc(2/ratio - 1)
if (is.null(ratio)) {
if (wilder)
ratio <- 1/n
else ratio <- 2/(n + 1)
}

foo <- cbind(x[,1], volumes, VEMA.num(as.numeric(x[,1]), volumes, ratio), VEMA.den(volumes, ratio))
(foo[,3] / foo[,4]) -> ma

ma <- reclass(ma, x)
if (!is.null(dim(ma))) {
colnames(ma) <- paste(colnames(x), "VEMA", n, sep = ".")
}
return(ma)
}

VEMA.num <- function(x, volumes, ratio) {
ret <- c()
s <- 0
for(i in 1:length(x)) { s <- ratio * s + (1-ratio) * x[i] * volumes[i]; ret <- c(ret, s); }
ret
}

VEMA.den <- function(volumes, ratio) {
ret <- c()
s <- 0
for(i in 1:length(x)) { s <- ratio * s + (1-ratio) * volumes[i]; ret <- c(ret, s); }
ret
}

VEMA(1:20, 20:1, ratio=0.1)

VEMA(1:20, 20:1, ratio=0.9)
logicgate

Posts: 223
Joined: Tue Dec 11, 2018 7:54 am

### Re: EVWMA

α = 1 - 2/(N + 1)
Num(Now) = α Num(Now) + (1 - α) VN+1 * PN+1

In my example we have
PV[pos]=Close[pos]*Volume[pos];
PVSum=iMAOnArray(PV,0,Volume_MA_Period,0,(MA_Type-1),pos);

These two will do the same thing.

iMAOnArray will call MT4 internal EMA function. Apprentice
FXCodeBase: Confirmed User

Posts: 21785
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: EVWMA

Apprentice wrote:In your examople we have
α = 1 - 2/(N + 1)
Num(Now) = α Num(Now) + (1 - α) VN+1 * PN+1

In my example we have
PV[pos]=Close[pos]*Volume[pos];
PVSum=iMAOnArray(PV,0,Volume_MA_Period,0,(MA_Type-1),pos);

These two will do the same thing.

iMAOnArray will call MT4 internal EMA function.

ah I see, great then!
logicgate