MovingAverage bug and unit test for issue #1538

@scottpurdy please review.