With all these problems with EMA I decided to rewrite this indicator. I first tried to understand what the original authors were doing, but as coded it seems to do things differently from the definition of EMA and from what I see in other tools. In particular, it makes the data it depends on dynamically dependent on the series it works on. Then there are many more calculations that are not in the definition of the EMA, as far as I can tell. I took the straightforward approach and followed the text books. The EMA is computed in the following manner: alpha = 2 / ( N + 1 ) EMA[n] = EMA[n-1] + alpha * ( INPUT - EMA[n-1] ) Where EMA[n] refers to the EMA at period n, and INPUT is the value of the input series at period n. The starting point is usually computed as the SMA(n) over the period from start - n to start. (One could also start with the actual value of the series, in which case there would be no dependency on past data. Maybe I make that an option. Please find this indicator attached. I compared it with the output from TA_lib and metastock. I also ran my tests. It depends only on the past n data points (if we use the SMA start computation). It is not affected whether called directly or in another indicator. Please do your own testing. But I think it works better and faster than the existing EMA. Cheers, Th.
Attachment:
EMA.pm
Description: EMA.pm