I made some more investigation and I think tsmovavg based solution has a major drawback i.e. will not work for real time application. Lets assume you have 10k bars and you calculate ema on it. Than a new bar comes and calculate again 10k would be very time costly - much easier to calculate just last bar.

But in this case this code will not work because instead of use x-1 data
for initial value (so last data point of 1st calculation of ema) it will use some average values.

in other words it means that ema calculated on 10k+1 bars in one pass will have different value than ema calculated on last bar and it should not be a case.

It looks that there are at least 2 versions of code for EMA around i.e.
EMA calculated with algorithm from this function and EMA calculated with this code

% convert the period to an exponential percentage
ep = 2/(period+1);

% calculate the EMA
out = filter(ep,[1-(1-ep)],data,data(1)*(1-ep));

Unfortunately they give different results. Which one is correct ??

I also got the error
Error using COM.StatConnectorSrv_StatConnector/Init
Error: Object returned error code: 0x80040013
when I first tried this. However, I reinstalled R using the directions on this website:
http://homepage.univie.ac.at/erich.neuwirth/php/rcomwiki/doku.php?id=wiki:how_to_install#further_remarks
Making sure that I was running R as an administrator when I typed in the install.package commands. Now it works fine.

Comment only

10 Dec 2014

Technical Indicators
A single function that calculates 27 different technical indicators

After installing R 3.1.0 and matlab 2012a, I find it reported
Error using COM.StatConnectorSrv_StatConnector/Init
Error: Object returned error code: 0x80040013
Donot know why

Comment only

11 Nov 2014

Technical Indicators
A single function that calculates 27 different technical indicators

Comment only