How to write Arithmetic Mean for i periods?

Hello Family
I have been trying to write a code for calculating arithmetic mean of I periods in for loop.

for( i = 0; i < BarCount; i++ )
Please help , I have spent lot of time on this I could fetch only moving averages but not arithemetic mean .

Best ,

Moving average IS arithmetic mean:

z = MA( x, i );