EMA(20) at the 7th bar

Questions about MultiCharts .NET and user contributed studies.
Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

EMA(20) at the 7th bar

Postby Fabrice » 10 Jul 2013

How can an EMA(20) be calculated after only the 7th bar (see picture) ?
Regards.
Attachments
Screen Shot 2013-07-10 at 11.08.42 AM.png
Screen Shot 2013-07-10 at 11.08.42 AM.png (37.4 KiB) Viewed 1393 times

User avatar
Henry MultiСharts
Posts: 9064
Joined: 25 Aug 2011
Has thanked: 1256 times
Been thanked: 2911 times

Re: EMA(20) at the 7th bar

Postby Henry MultiСharts » 17 Jul 2013

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 ) ).

Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Re: EMA(20) at the 7th bar

Postby Fabrice » 19 Jul 2013

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.

User avatar
Alex MultiCharts
Posts: 194
Joined: 09 Aug 2013
Has thanked: 43 times
Been thanked: 76 times

Re: EMA(20) at the 7th bar

Postby Alex MultiCharts » 14 Aug 2013

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);

Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Re: EMA(20) at the 7th bar

Postby Fabrice » 14 Aug 2013

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.

User avatar
Alex MultiCharts
Posts: 194
Joined: 09 Aug 2013
Has thanked: 43 times
Been thanked: 76 times

Re: EMA(20) at the 7th bar

Postby Alex MultiCharts » 15 Aug 2013

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

Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Re: EMA(20) at the 7th bar

Postby Fabrice » 15 Aug 2013

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.

User avatar
Alex MultiCharts
Posts: 194
Joined: 09 Aug 2013
Has thanked: 43 times
Been thanked: 76 times

Re: EMA(20) at the 7th bar

Postby Alex MultiCharts » 15 Aug 2013

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.
These users thanked the author Alex MultiCharts for the post:
Henry MultiСharts


Return to “MultiCharts .NET”