RosettaCodeData/Task/Averages-Simple-moving-average/Run-BASIC/averages-simple-moving-aver...

20 lines
678 B
Plaintext

data 1,2,3,4,5,5,4,3,2,1
dim sd(10) ' series data
global sd ' make it global so we all see it
for i = 1 to 10:read sd(i): next i
x = sma(3) ' simple moving average for 3 periods
x = sma(5) ' simple moving average for 5 periods
function sma(p) ' the simple moving average function
print "----- SMA:";p;" -----"
for i = 1 to 10
sumSd = 0
for j = max((i - p) + 1,1) to i
sumSd = sumSd + sd(j) ' sum series data for the period
next j
if p > i then p1 = i else p1 = p
print sd(i);" sma:";p;" ";sumSd / p1
next i
end function