Ma/sma/dma/ema moving Average algorithm Formula 1, simple moving average MA usage: MA (x,n): X's N-day simple moving Average algorithm (X1+X2+X3+...+XN)/n2, moving average SMA usage: SMA (X,N,M), N-day moving average for x, m/ N is the weight given to the observed value x, which must be greater than M. Algorithm: If Y=sma (x,n,m) is y=[m*x+ (n-m) *y ')]/n=m/n*x + (n-m)/n *y '), where Y ' represents the previous period Y value. Note that when m/n is greater than/equal to/less than 1/2, the weight given to the observed x is changed. When M=1, only the weight of the observed value 1/n is given, the greater the N, the smaller the current observations contribute to or affect the mean. For example: SMA (close,30,1) Represents the 30th moving average price for the closing price. 3, smooth moving average MEMA usage: MEMA (x,n): X's N-day smoothed moving average, such as y= (X+y ' * (N-1))/n, especially when n=2, y= (X+y ')/2, i.e. Y takes value from the observed value X and the median mid-term value, when N >2 and gradually increase, the weight of the observed value X is gradually reduced. MEMA (X,n) equivalent to SMA (x,n,1) 4, moving average TMA usage: TMA (X,A,B), A and B must be less than 1 algorithm y= (a*y ' +b*x), where Y ' Represents the previous period Y value. The initial value is x. Note that if the specific values of a and B are not specified, the total weight is not necessarily 1, then the moving average result will be very arbitrary. 5, exponential moving average EMA usage: EMA (x,n), the N-day exponential moving average of X. Algorithm: If Y=ema (x,n), then y=[(1/n) * x+ (1-1/n) * Y '], where Y "represents the previous period Y value. Please note that the y= (x+y ' * (N-1))/n is exactly the same as above "3, smooth moving average Mema" when 1/n is presented in Bashi. For example: EMA (close,30) represents the 30th exponential smoothed average. Note: Exponential moving average EXPMA is consistent with EMA usage 6, exponential smoothed moving average Expmema usage: Expmema (x,n): X's N daily exponential smoothed moving average. The difference between the Expmema and EMA (EXPMA) is that its starting value is a smoothing value, and if X is an exponential smoothing result then the formula Expmema (X,n) represents the two exponential smoothing of X. 7. Weighted moving average WMA usage: WMA (X,N): N-day weighted moving average of X. Count: yn= (1*X1+2*X2+...+N*XN)/(1+2+...+n). The formula gives the most recent observation value xn the most weight. 8. Dynamic Moving Average DMA usage: DMA (X,A) for X dynamic shiftDynamic average. Algorithm: If Y=DMA (X,a) is y=a*x+ (1-a) *y ', where Y ' represents the previous period Y value, A must be less than 1. For example, DMA (Close,vol/capital) indicates that the average price for the smoothing factor is the change in hand rate. If you do a continuous iteration, you can see that the DMA is the true (in period) exponential smoothing formula. 9. Adaptive average value AMA usage: AMA (x,a), A is an adaptive coefficient and must be less than 1. Algorithm: Y=y ' +a* (x-y '), initial value is X. 10, the offset moving average XMA belongs to the future function usage: XMA (x,n): The N-day offset moving average of X, using the data of N/2 days after the same day, only for internal testing purposes. It is worth noting that the results of the above moving averages are the same as the average of the last period of observation, so there is no tail-missing data, which is different from many of the measurement or statistical analysis textbooks (see Gao Yumei). (Source: Tongda Letter System Formula Editor function)
Moving Average algorithm formula