Page 1 of 1

EMA(20) at the 7th bar

Posted: Jul 10 2013
by Fabrice
How can an EMA(20) be calculated after only the 7th bar (see picture) ?
Regards.

Re: EMA(20) at the 7th bar

Posted: Jul 17 2013
by Henry MultiŠ”harts
Hello Fabrice,

Each study requires a certain amount of bars for calculation of initial function and variable values.
Exponential Moving Average does not use historical data, it uses only its previous value. Len input is not an index, it is a denominator in the formula var0( 2 / ( Len + 1 ) ).

Re: EMA(20) at the 7th bar

Posted: Jul 19 2013
by Fabrice
Yes the EMA for the current bar is calculated from the EMA of the previous bar... except for the 1st bar. In the book "Technical Analysis 2nd Ed / KirkPatrick II" (p 282), they mention that the 1st bar of an EMA is calculated from an SMA. They give the example of a 10 days EMA, which then can only be calculated at the close of the 11th day. As MC displays the 1st 20 EMA at the 7th bar, I wonder how "only" 6 bars of data can be enough for that.
Regards.

Re: EMA(20) at the 7th bar

Posted: Aug 14 2013
by Alex MultiCharts
Mov_Avg_Exponential indicator, you are referring to, is calculated basing on XAverage function.
XAverage formula is different from the regular moving average. You can compare their scripts.
So, for XAverage calculation less bars are required, as it is not requesting historical values more than one bar back:

if (1 == Bars.CurrentBar)
return Price[0];
double prev = this[1];
return prev + 2.0 / (Length + 1) * (Price[0] - prev);

Re: EMA(20) at the 7th bar

Posted: Aug 14 2013
by Fabrice
The good answer would have been to explain us why MC has chosen to use close[0] as 1st EMA value instead of the 20-SMA...
Regards.

Re: EMA(20) at the 7th bar

Posted: Aug 15 2013
by Alex MultiCharts
It happens because of the difference between Moving Average and Expotential Moving Average.

Please follow this link to read more about Expotential Moving Average:
http://en.wikipedia.org/wiki/Moving_average

Re: EMA(20) at the 7th bar

Posted: Aug 15 2013
by Fabrice
Sorry but I believe you completely miss the point. The issue is not about the difference between an SMA and an EMA... The issue is about calculating the 1st value of an EMA.
May be the better is to close this thread, that leads to nothing. I will use my own formula for the EMA anyway.
Regards.

Re: EMA(20) at the 7th bar

Posted: Aug 15 2013
by Alex MultiCharts
Please compare the formulas, and read about the differences between them, you will notice, why the calculation starts differently.

SMA (Length = 20) - to receive the first value, you need to have at least 20 bars, as according to the formula, it is necessary to sum 20 Close values and divide this by 20. That is why the first SMA (Length = 20) value is possible at the 21st bar.

But for EMA (Length = 20), 20 historical bars are not necessary for the calculation start. You can see it in the formula. For EMA calculation with any length, less than 10 bars are required, even if the Length Input = 1000, and there are only 500 bars on the chart, EMA (Length = 1000) will be calculated.

And if it is necessary to start the calculation from another bar, you need to set your own value in Format Indicators -> Mov Avg Exponental -> Properties -> Max Number of bars -> select User Srecified field.