Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Here's another version that allows the user to set the number of Periods parameter between 2 and 40. MetaStock's restriction of 40 numeric values is somewhat of a pain, but a rather clumsy way around this as used here is to add or subtract numbers smaller than 40 to create values greater than 40.
Roy
{Modified Moving Average} {Linear Regression} {TASC January 2000 article by Joe Sharp} {MetaStock code by Roy Larsen, 11/7/2115}
N:=Input("MMA Periods",2,40,20); M:=Mov(C,N,S); X:=((N-1)/2)*C +(N>1)*((N-3)/2)*Ref(C,-1) +(N>2)*((N-5)/2)*Ref(C,-2) +(N>3)*((N-7)/2)*Ref(C,-3) +(N>4)*((N-9)/2)*Ref(C,-4) +(N>5)*((N-11)/2)*Ref(C,-5) +(N>6)*((N-13)/2)*Ref(C,-6) +(N>7)*((N-15)/2)*Ref(C,-7) +(N>8)*((N-17)/2)*Ref(C,-8) +(N>9)*((N-19)/2)*Ref(C,-9) +(N>10)*((N-21)/2)*Ref(C,-10) +(N>11)*((N-23)/2)*Ref(C,-11) +(N>12)*((N-25)/2)*Ref(C,-12) +(N>13)*((N-27)/2)*Ref(C,-13) +(N>14)*((N-29)/2)*Ref(C,-14) +(N>15)*((N-31)/2)*Ref(C,-15) +(N>16)*((N-33)/2)*Ref(C,-16) +(N>17)*((N-35)/2)*Ref(C,-17) +(N>18)*((N-37)/2)*Ref(C,-18) +(N>19)*((N-37-2)/2)*Ref(C,-19) +(N>20)*((N-37-4)/2)*Ref(C,-20) +(N>21)*((N-37-6)/2)*Ref(C,-21) +(N>22)*((N-37-8)/2)*Ref(C,-22) +(N>23)*((N-37-10)/2)*Ref(C,-23) +(N>24)*((N-37-12)/2)*Ref(C,-24) +(N>25)*((N-37-14)/2)*Ref(C,-25) +(N>26)*((N-37-16)/2)*Ref(C,-26) +(N>27)*((N-37-18)/2)*Ref(C,-27) +(N>28)*((N-37-20)/2)*Ref(C,-28) +(N>29)*((N-37-22)/2)*Ref(C,-29) +(N>30)*((N-37-24)/2)*Ref(C,-30) +(N>31)*((N-37-26)/2)*Ref(C,-31) +(N>32)*((N-37-28)/2)*Ref(C,-32) +(N>33)*((N-37-30)/2)*Ref(C,-33) +(N>34)*((N-37-32)/2)*Ref(C,-34) +(N>35)*((N-37-34)/2)*Ref(C,-35) +(N>36)*((N-37-36)/2)*Ref(C,-36) +(N>37)*((N-37-37-1)/2)*Ref(C,-37) +(N>(37+1))*((N-37-37-3)/2)*Ref(C,-37-1) +(N>(37+2))*((N-37-37-5)/2)*Ref(C,-37-2); M+(6*X)/((N+1)*N);
|