The 5 in the function call is specifying the number of rows before the current row to include in the moving average. You can actually specify the function in the following way.....which is really the way it should be called, to make the script more readable
Col Moving Average( :height, weighting=1, Before=5, after=0, :sex )
In your manual calculation you have to remember that the moving average is being tracked for both Males and Females. And the average does not restart every time the data changes from F to M or M to F. It is treating the calculations as if there are 2 separate columns.
Jim