Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Calculate Extended Moving Average (EMA)

Does anyone have an example of a QlikView expressio to calculate an "x" period exponential moving average (EMA)? I know how to do a simple (rolling) average using RangeAvg() and Above(), but an EMA is more complex, because it uses the prior record's EMA.

"x" can be any number you'd like (e.g. 50, 200, etc.)

Thanks.

4 Replies
Gysbert_Wassenaar

EMA is a recursive calculation. That can't be done in an expression afaik since an expression can't reference itself. You can calculate it in the script using the peek function. But that's not very dynamic since you can't vary x. Maybe you can use R.

edit: fixed some typos, i.e can to can't


talk is cheap, supply exceeds demand
Not applicable
Author

You're saying that it "can" reference itself? Do you have an example of this?

Anonymous
Not applicable
Author

I know this thread is a bit old but for the sake of posterity I'd thought I'd point out that a chart expression CAN reference itself.  For example, I've had a quick go at doing an exponential moving average with a period of 9 and a weighting of 0.2 where the expression has the Label "EMA9":

if(RowNo() = 1, Data, (Data - Above(EMA9)) * .2 + Above(EMA9))

Technically I guess I shouldn't be starting the EMA from row 1 the way I have, but I hope it gives you the idea.

Cheers,

Rod

Not applicable
Author

Rod, That turns out to be exactly what I did. I simply named the column and then referred to the column by name in the row above. I just never got to post the result.