37 lines
504 B
Text
37 lines
504 B
Text
module Simple_moving_average {
|
|
class smaMaker {
|
|
private:
|
|
s=stack
|
|
m
|
|
public:
|
|
set {
|
|
read this
|
|
}
|
|
value (N) {
|
|
stack .s {
|
|
if len(.s)=.m then drop
|
|
data N
|
|
}
|
|
= array(stack(.s))#sum()/len(.s)
|
|
}
|
|
class:
|
|
module smaMaker (.m) {
|
|
}
|
|
}
|
|
Print "Period = 3"
|
|
ma=smaMaker(3)
|
|
test(0, 9)
|
|
Print "Period = 5"
|
|
ma=smaMaker(5)
|
|
test(9, 0)
|
|
end
|
|
sub test(A, B)
|
|
local i
|
|
Print
|
|
for i=A to B
|
|
Print "Add ";i;" => moving average ";ma(i)
|
|
next
|
|
Print
|
|
end sub
|
|
}
|
|
Simple_moving_average
|