Coefficient weights of Simple Moving Average (SMA) on SMA
The green curve in your plot corresponds to the correct result. The red curve is wrong, because the weights in the vector cnvweights are in the wrong order (left and right halves are interchanged). The correct way to compute those weights is
cnvweights &lt;- convolve(rep(1/n,n), rev(rep(1/n,n)), conj = TRUE, type = &quot;open&quot;)
According to the R documentation of the function 'convolve', you need to use conj = TRUE for standard convolution.