MAXPERIOD = 10 FOR n = 1 TO 5 PRINT "Number = ";n TAB(12) " SMA3 = ";FNsma(n,3) TAB(30) " SMA5 = ";FNsma(n,5) NEXT FOR n = 5 TO 1 STEP -1 PRINT "Number = ";n TAB(12) " SMA3 = ";FNsma(n,3) TAB(30) " SMA5 = ";FNsma(n,5) NEXT END DEF FNsma(number, period%) PRIVATE nums(), accum(), index%(), window%() DIM nums(MAXPERIOD,MAXPERIOD), accum(MAXPERIOD) DIM index%(MAXPERIOD), window%(MAXPERIOD) accum(period%) += number - nums(period%,index%(period%)) nums(period%,index%(period%)) = number index%(period%) = (index%(period%) + 1) MOD period% IF window%(period%)