But here's an example, assuming you want a "flat" moving average:
Modify if you do not want output at every point. Modify as desired to handle the edges in a nicer way (e.g. extend the original signal to the sides before smoothing, with x(1) and x(end) respectively, or with a time-reversed and inverted extension, or whatever...). If you want a non-flat window, you have to do a bit more. For example, a triangular window of width M:
Multipy elements of b by appropriate elements of x to get filtered version.