EMA: how is it calculated in JForex?
I have been trying to reproduce EMA(14) indicator in JForex in java and compare it with the built-in one.
However I am struggling finding how EMA is computed by Dukascopy, since I get discrepancies with my results.
This is my "ema" function: (which is derived from the formula ema[t] = a * x[t] + (1-a) x[t-1])
public double f_ema(double val, double k)
if (val.length == 1) return val;
int t = val.length - 1;
double past = Arrays.copyOfRange(val, 0, t);
return k * val[t] + (1 - k) * f_ema(past, k);
And I call it in this way:
timeframe = (take m_tperiod + 1 entries from inputs array)
m_output[j] = f_ema(timeframe, 2.0 / (1.0 + m_tperiod));
Do you have an idea about where I am wrong?
Thank you very much in advance.