简体   繁体   中英

Moving everage - how to calculate?

Please explain how to calculate the EMA indicator on trading candles? I found the formula here: https://www.investopedia.com/ask/answers/122314/what-exponential-moving-average-ema-formula-and-how-ema-calculated.asp

But there is some strange, incomprehensible explanation, I would even say stupid.

It says there:

The formula for calculating the EMA is a matter of using a multiplier and starting with the SMA:

Compute the SMA Calculate the multiplier for weighting the EMA Calculate the current EMA

The calculation for the SMA is the same as computing an average or mean. That is, the SMA for any given number of time periods is simply the sum of closing prices for that number of time periods, divided by that same number

Okay, so far everything is clear.

The following is written next:

So when it comes to calculating the EMA of a stock:

EMA=Price(t)×k+EMA(y)×(1−k)

where: t=today y=yesterday N=number of days in EMA k=2÷(N+1)

And from that moment begins, some kind of trash.

where in the EMA formula - SMA indicator?

WHY did they write about the calculation of SMA - if it is not used in any way in the ETA formula?

How can I calculate the EMA indicator - if there is an ETA indicator for yesterday inside the formula??

I got completely lost at the end.

I presume EMA is Exponential Moving Average. This is what the formula shown by the OP calculates. This is not really an average at all, since it doesn't give equal weight to all values. Instead it gives exponentially decaying weight to past values. The most recent value has weight k , the n th past value has weight (1- k ) to the n th power.

The starting value of the EMA always has some influence: its weight is again (1- k ) to the n th power where n is now one less than the total number of values processed, so its effect decays exponentially with time.

If you want a moving average of the last m values, you have to keep an array of them and just sum the array and divide m . Each time you get a new value, you remove the oldest one from the array, shift everything along, insert the new one, and sum the array and divide m again. There is a slightly faster algorithm which avoids summing the array every time.

#define N 100 /* the number of items to average over */
double array[N]; /* the last N items, each divided by N */
double average;

double step(double x /* new item */) /* insert new item and recompute */ {
    int i; /* indexing */
    average -= array[0]; /* subtract oldest item from average */
    for (i = 0; i < N - 1; ++i) {
        array[i] = array[i+1]; /* shift old items down array */
    }
    x = x/N; /* apply weight 1/N to new item */
    array[N-1] = x; /* add new item to array */
    average += x; /* add new item to average */
    return average;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM