[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Building Blocks - MetaStock Tests - 01_R2,S/C,MFI (Vol Required)



PureBytes Links

Trading Reference Links

All,
     This week I'm going to go back and discuss my first MetaStock profit
system test.  The RSquared, S/C,MFI test is based on linear regression.
RSquared is a linear regression function that measures how strong a data
array of given length is trending.  It's really based on correlation.  A
return of one correlates to a very strong trend in either direction that
raises or falls one point per day.  A return of zero correlates to no trend.
     I'm using RSquared to tell me when there is no trend over the last 21
days, or that RSquared(C,21) is less than 0.15.  Now that we have no trend,
we would expect one to start in the next 5 to 13 days.  If one does start we
want to determine the direction and get in early.  Therefore I use RSquared
as my trigger, combining it with the ALERT function.  With the ALERT given
by RSquared being less then 0.15, then we will get a buy signal if all my
other conditions are met within a 13 day period which I also set with the
ALERT function.  For the other conditions, I'm using S/C, MFI, and the 55
day Variable Moving Average (vma) to determine trend start and direction.
      S/C is nothing more than the normalized 34 day LinRegSlope of the
close.  I normalize it by dividing it by the close so charts are more
directly comparable.  I also multiply by 10000 just to get numbers between 0
and a few hundred.  Finally I apply Tema smoothing to get a smoother plot.
Therefore my formula for Tema S/C becomes:
         Tema S/C
            Periods := Input("Enter Periods",1,233,34);
            Tema(10000*LinRegSlope(C,Periods)/C,Periods)
     The theory is that if Tema S/C is rising then a up trend is in
progress.  If Tema S/C is falling a down trend is in progress.  I check this
by making sure that tema(S/C) is larger than an optimized value (opt1) and
is rising.  I use the function HHV(X,5) = HHV(X,13) to check that it is
really rising.  This is just a quick way to determine if the most reason
values of X have been rising.  If the condition is met, then S/C is rising.
Similarly if it met the condition LLV(X,5) = LLV(C,13) it would be falling.
     I double check the result by also making sure that both the MFI and the
55 day vma are also rising.  I use a Tema MFI formula which is just the tema
smoothed MFI - 50 so it can be plotted as a histogram.  The formula is:
        Tema MFI
            Periods := Input("Enter Tema Smoothing Periods",13,55,55);
             Tema(MFI(Periods),Periods) - 50
     When all conditions are met within 13 days of the alert, we get a buy
signal.  The converse is true for a sell signal.  Since the market is biased
upwards, I use an additional check for the short - Tema MFI less then 0.  I
close the positions when the trend has stopped.  For the long position I
check that the Tema(MFI) is below 0, the Tema(S/C) is below opt 1 and that
both are falling.  Short positions tend to move faster, so I only look for
the Tema MFI to be greater than zero and the 55 day vma to begin rising to
close that position.  The complete test follows:

ENTER LONG:
Alert(RSquared(C,21) < 0.15,13) AND
 Tema(10000*LinRegSlope(C,34)/C,34) > opt1 AND
    HHV(Tema(10000*LinRegSlope(C,34)/C,34),5) =
    HHV(Tema(10000*LinRegSlope(C,34)/C,34),13) AND
      HHV(Tema(MFI(55),55),5) = HHV(Tema(MFI(55),55),13))

CLOSE LONG:

Tema(MFI(55),55) - 50 < 0 AND
  Tema(10000*LinRegSlope(C,34)/C,34) < opt1 AND
    LLV(Tema(10000*LinRegSlope(C,34)/C,34),5) =
    LLV(Tema(10000*LinRegSlope(C,34)/C,34),13) AND
      LLV(Tema(MFI(55),55),5) = LLV(Tema(MFI(55),55),1

ENTER SHORT

Alert(RSquared(C,21) < 0.15,13)  AND
 Tema(10000*LinRegSlope(C,34)/C,34) < opt2 AND
   LLV(Tema(10000*LinRegSlope(C,34)/C,34),5) =
    LLV(Tema(10000*LinRegSlope(C,34)/C,34),13) AND
      LLV(Tema(MFI(55),55),5) = LLV(Tema(MFI(55),55),13) AND
        Tema(MFI(55),55) - 50 < 0 AND
           LLV(Mov(C,55,VAR),5) = LLV(Mov(C,55,VAR),13)

CLOSE SHORT

HHV(Mov(C,55,VAR),5) = HHV(Mov(C,55,VAR),13) AND
 Tema(MFI(55),55) - 50 > 0

OPTIMIZATION:

OPT1:  Min=-34 Max=-8 Step=13
OPT2:  Min=-55 Max=-21 Step=34

     Although I have Tema S/C and Tema MFI defined as custom formulas so I
can plot them as indicators on my charts, I don't call the custom formulas
in the tests.  Instead I use the actual formulas.  The reason I do this, is
that the test will run faster when the formulas are used direct instead of
calling for the custom formulas.
     That's it.  Any comments or suggestions would be appreciated.

JimG