How can an EMA(20) be calculated after only the 7th bar (see picture) ?
Regards.
EMA(20) at the 7th bar
EMA(20) at the 7th bar
 Attachments

 Screen Shot 20130710 at 11.08.42 AM.png
 (37.4 KiB) Downloaded 1528 times
 Henry MultiСharts
 Posts: 9149
 Joined: 25 Aug 2011
 Has thanked: 1260 times
 Been thanked: 2932 times
Re: EMA(20) at the 7th bar
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 ) ).
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
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.
Regards.
 Alex MultiCharts
 Posts: 194
 Joined: 09 Aug 2013
 Has thanked: 43 times
 Been thanked: 76 times
Re: EMA(20) at the 7th bar
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);
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);
 Alex MultiCharts
 Posts: 194
 Joined: 09 Aug 2013
 Has thanked: 43 times
 Been thanked: 76 times
Re: EMA(20) at the 7th bar
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
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
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.
May be the better is to close this thread, that leads to nothing. I will use my own formula for the EMA anyway.
Regards.
 Alex MultiCharts
 Posts: 194
 Joined: 09 Aug 2013
 Has thanked: 43 times
 Been thanked: 76 times
Re: EMA(20) at the 7th bar
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.
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.