How to Calculate MME?

 

How do I calculate an MME via code? I used several formulas and I can not get it right. The most correct was:

lastMME = (v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9)/9;
MME = (PriceActual-lastMME)*(2/(9+1))+lastMME;
 
Márcio Andrade: How do I calculate an MME via code? I used several formulas and I can not get it right. The most correct was:

MME is the Portuguese abbreviation (Média Móvel Exponencial). In English it is called EMA (Exponential Moving Average).

Here are some links to help you understand how it is calculated:

The PDF file (Incremental calculation of weighted mean and variance) is for me the most informative because it also shows how to calculate the variance and standard deviation in an incremental way with much less rounding errors which is perfect for indicators.
Moving Average - Trend Indicators - MetaTrader 5
Moving Average - Trend Indicators - MetaTrader 5
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average, one averages out the instrument price for this time period. As the price changes, its moving average either increases, or decreases. There are four different types of moving averages: Simple (also...
 
Dear, Thanks!!!!!! PERFECT.
      MMEanterior = (v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9)/9;
      
      
      MMEanterior=(v31+v32+v33+v34+v35+v36+v37+v38+v39)/9;
      MME = 0.2*(v30-MMEanterior)+MMEanterior;
      
      MME = 0.2*(v29-MME)+MME;
      MME = 0.2*(v28-MME)+MME;
      MME = 0.2*(v27-MME)+MME;
      MME = 0.2*(v26-MME)+MME;
      MME = 0.2*(v25-MME)+MME;
      MME = 0.2*(v24-MME)+MME;
      MME = 0.2*(v23-MME)+MME;
      MME = 0.2*(v22-MME)+MME;
      MME = 0.2*(v21-MME)+MME;
      MME = 0.2*(v20-MME)+MME;
      MME = 0.2*(v19-MME)+MME;
      MME = 0.2*(v18-MME)+MME;
      MME = 0.2*(v17-MME)+MME;
      MME = 0.2*(v16-MME)+MME;
      MME = 0.2*(v15-MME)+MME;
      MME = 0.2*(v14-MME)+MME;
      MME = 0.2*(v13-MME)+MME;
      MME = 0.2*(v12-MME)+MME;
      MME = 0.2*(v11-MME)+MME;
      MME = 0.2*(v10-MME)+MME;
      MME = 0.2*(v9-MME)+MME;
      MME = 0.2*(v8-MME)+MME;
      MME = 0.2*(v7-MME)+MME;
      MME = 0.2*(v6-MME)+MME;
      MME = 0.2*(v5-MME)+MME;
      MME = 0.2*(v4-MME)+MME;
      MME = 0.2*(v3-MME)+MME;
      MME = 0.2*(v2-MME)+MME;
      MME = 0.2*(v1-MME)+MME;
      MME = 0.2*(vBar1-MME)+MME;
Reason: