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 ??
Ha,
I have just added the KDJ Indicator as requested. It should appear shortly depending on how long Matlab takes to approve my submission.
This indicator was a little confusing. I'm not sure exactly which method is correct so I input 3 different methods. Simply uncomment whichever method you wish to use.
Method # 1:
J = 3*FastK - 2*FastD;
Method # 2:
J = ema(K,period);
Method # 3:
J = 3*SlowK - 2*SlowD;
Hope that helps!
Nate
Comment only
11 Mar 2013
Technical Indicators
A single function that calculates 25 different technical indicators
so does it connect to existing R session or creates a new one ?? I think It creates a new one as it was working without starting R.
Is it possible to connect to existing R seession ??
5
19 Dec 2012
Technical Indicators
A single function that calculates 25 different technical indicators
Thanks Lu Li!
I'll try my hand at the mex function, but unfortunately I don't have a whole lot of experience with them so no guarantees.
I do agree with you, this function is slow as an optimizer. I suggest pulling out the individual indicators that you are interested in and turn them into their own functions. Then try to optimize those, that way you aren't bogged down by the 'Switch' statement.
Comment only
19 Dec 2012
Technical Indicators
A single function that calculates 25 different technical indicators
Excellent work!
I want to use it in an optimization, but it is kind of slow.
It would be wonderful if it can be into mex funtcion so the it will be much faster.
Comment only