I want to calculate the Simple Moving Average (SMA) for Stock Prices with for period 'N'.
Normal Formula for 4 Period Moving Average is
MA = (a + b + c + d) / 4
for new entry e we do as following:
MA(new) = (b + c + d + e) / 4
Problem here is that I need to store for the N period's prices. I have tried for multiple things like
New Average = {(Old_Average x N) + (New_Data_Point - Old_Average)}/N
but I am loosing on precision.
The sole aim is to reduce the dependency on previous period array values. Can anyone please help. Thanks in advance.