MetaStock Explorer Usage Tips
MetaStock Explorer Usage Tips
Explorer Pitfalls 1
Exponential Moving Averages 4
Questions and Answers 6
Developing Explorations – Part 2 7
Tip of the Month 12
Thanks For The Memory – Part 1 13
Coming Next Month 18
System Tester Part 2 – Held over until February
EXPLORER PITFALLS
I t’s been said before, probably more than once, that the Explorer is a
potentially very powerful tool. It can be used for everything from
quite mundane scans to very sophisticated data mining. Let’s take a
look at the various small traps that frustrate many MetaStock users. It’s
important that you know how to use this tool properly even if your
coding skills are not that hot.
Tools For Explorer problems fall into these four main areas; structure, user
settings, data and code.
MetaStock
Structure
Filter. The filter is just a seventh column. It can’t use the Input()
function or report a visible value, but it can access the last-bar results
of other columns. It can also calculate a result from its own code and
use that with the results of other columns in performing its filtering
role. The filter is processed after columns A through F.
User Settings
Changing the exploration date allows you to test for a signal on any
given date, not just the most recent one. That effectively hides all
subsequent data from the exploration. If you change this setting for
some reason, remember to restore it to "Most Recent Date" afterwards.
Data
Explorations use the same data as charts, but explorations usually load
fewer bars. This is to be expected since an exploration is usually just a
snapshot recording of current market activity. Unfortunately, reducing
the amount of data for explorations also increases the risk of inaccurate
results. The following article on exponential moving averages explains
the major reason why this happens.
Code
The crux of the matter is that old data is never completely purged. I
came across the following comment under Wilders Smoothing in the
user manual – "similar to the exponential method in that it retains a
decreasingly smaller percentage of all historical data in the series".
That comment encapsulates the essence of an EMA.
The "periods" value is used to decide how much new data to add and
how much old data to drop out. An exponential moving average uses
the ratio expressed by "2/(1+n)", where "n" is the "periods" value of
the Mov() function. Look at the following expressions and see how a
"periods" value of 9 is converted into a percentage for a conventional
exponential moving average.
This tells us that a 9-period EMA adds 20% of each new bar’s data into
the EMA. That 20% is added to 80% of the previous bar’s EMA value
(PREV). Keeping 80% of the old data is the same as dropping out
20% – the two percentages are complimentary and add up to 100%.
The 20% of new data added replaces the 20% of old data dropped out. Figure 4.
9 period exponential
The term "new data" refers to the data array being smoothed. This is moving average.
Wilders
{Exponential Moving Average}
Smoothing is Periods:=Input("Periods",1,99,9);
less responsive
Prcent:=2 / (1 + Periods);
If(Cum(1)=1, C, PREV * (1-Prcent) + C * Prcent);
than an EMA. Wilders Smoothing is another form of EMA, and it differs from a
conventional EMA in two ways. The biggest difference is the "ratio
calculation", and this is expressed as "(1/n)". Look at the following
expressions to see how a "periods" parameter of 9 is converted into a
percentage for Wilders Smoothing.
It’s clear from this example that Wilders Smoothing adds less new data
than an EMA for any given "periods" parameter. This makes it less
responsive to data changes. You can use an EMA to replace Wilders
Smoothing by adjusting the "periods" parameter to suit. Let’s work
backwards to find out how many periods an EMA needs to match a 9-
periods Wilders Smoothing.
This can be formalized as "(n*2)-1", being one less than twice the
Wilders Smoothing periods. Try some of your own examples to check
this out. You can use MetaStock’s drop-down indicators to compare
the results of your experiments.
The functions listed in Figure 6 are among those needing extra care.
These may use exponential smoothing, or may display similar
symptoms when used with too few records. Don’t regard this list as
complete – it’s not. It’s provided here as a rough guide only, and you
should do your own research if you suspect your exploration reports
are inaccurate.
A number of
functions use
Wilders
QUESTIONS AND ANSWERS Smoothing
internally.
Q"period
When plotting the Q & B indicators I often get an error message
value out of range in Mov() function". This error often
necessitates closing MetaStock. What’s the minimum bar count, and
can the code be altered to use fewer bars and still remain relevant?
Adding the following code line just before the "noise" variable should
mean you don't get the problem, because the periods used by the Mov()
function is reduced automatically when there aren’t enough bars to
Qsecurity
Is it possible to include an indicator for an index in the normal
smart chart? If so, how do I do it?
A Yes, you can do this if you have access to the Security() function.
Remember that the Security() function requires the full path name
of the index when it’s in a different folder to any of your securities.
DEVELOPING EXPLORATIONS - 2
T he subject of explorations is complex. Most people see
explorations as a way to find stocks that meet some criteria that
they have decided defines a good entry. This is probably the most
popular use for explorations.
In addition, explorations are often used for defining trading rules and
testing systems. For example, a systems test might lead to the
conclusion that a specific signal has a good probability of being
profitable. However, the systems test is only one part of the total
process of determining the effectiveness and success probability of a
trading model. A system should be studied across a variety of dates to
determine the number, types and quality of trades it generates under
different market conditions. In my case, I know that I’m not going to
trade any system mechanically, so I want to establish the trading rules
I’m going to use with a specific signal. To do that, I have to look at a
lot of charts. I want to see charts having the signals when the market is
moving down and when the market is moving up.
I have a general rule that I use when developing and testing systems. I
look at a long only or short only system, not both combined together. I
evaluate each within the conditions it was designed to trade under. For
example, if the 5, 15 and 40 period SMA on a weekly chart is in an up-
trend, then my trading bias is to take long trades and only consider
short trades when the daily charts tell me the market is in a pull back
stage. I evaluate the short-term daily trends using a 4, 9, 18 period
EMA. On both charts, I use the DCF filter set to 27.
As I study the charts, I can adjust my trading rules to maximize for the
best entries. Later I review the entry signals I would have taken against
their performance across time. This is a sophisticated system of paper
trading without the paper. I use another set of programs to track the
trades into the future, which helps me to establish the exit criteria and
the ratio of winning trades to losing trades. The systems tester makes
me use a set of fixed rules that often don’t allow me to easily do staged
entries and exits, timed holding periods or use mixed time frames to
make trading decisions. The historical explorations, with my electronic
paper trading methods, let me see how all of that works in a simulated
trading manner. It’s not perfect, but it’s pretty good. Often I can
increase the number of profitable trades a system generates in the tester
from 1 to 3, or 1 to 1, up to 3 to 1 and sometimes 4 to 1.
When I am exploring for stocks to trade, one trick I’ve learned is not to
explore using a specific entry criteria. For example, the John Clayburg
book, Four Steps to Trading Success, has been mentioned many times
on the MS boards. It’s an excellent book with an excellent indicator
system that combines extremely well with the B & Q indicators
discussed in previous MSTT articles. However, it is not a system that
was designed for mechanical trading, even though some people keep
trying to make it one.
Col B
BarsSince(Cross(Mov(C,9,E),Mov(C,18,E)))<=3;
Filter
ColA and ColB;
If you don’t know what a Clayburg chart looks like, you can look
Clayburg settings in the files section of either MS board and find one. Here in the
side-bar are the settings to create your own. See Figure 7.
Will %R Green and Black on the chart.
If I write my exploration using the BarsSince function, I will find
%R 50 thresholds -10 & -90 green charts that have just recently triggered, or are close to triggering a
Clayburg buy signal. If the market is in a strong up-trend I prefer
%R 75 thresholds -20 & -80 black
to enter stocks that are already in an established up-trend
RSI Black and Red on the chart themselves. I don’t want to take a specific entry signal because
that is a lower probability trade than riding a stock that’s moving
RSI 7 and RSI 14 threshold up in an established pattern. To find those stocks, I’m going to
the same for both +30 & +70 increase my BarsSince width and use a statement or two to make
sure that during the BarsSince period, the stock has not dropped
Stoch Red and Green on the chart
below a specific moving average like the 10 bar EMA or 20 bar
Stoch (7,3) green threshold 10 and 90 EMA.
Stoch (45,5) red threshold 20 and 80 In addition, I would look at the Clayburg’s, the B & Q indicators
and the uRSC (URSC from Jose) to make sure the stock is strong
Figure 7. and that the up-trend I think I’m seeing is real.
Clayburg settings
One or two more things I might do include looking to see if the
particular stocks that are in an up-trend have traversed a short-term
pull back in the market. I like stocks strong enough to avoid downturns
that match the market. Those kind of up-trends usually run for long
periods of time. Additionally, I would look to see when the next
earnings announcement is scheduled. During earnings announcements,
I set very tight stops. You can find earnings announcement information
at Yahoo Finance.
In general, I’ve found that the code to make a good expert or trading
system is not very good code for plugging into an exploration that will
find charts with stocks triggering the trade entry conditions that I’m
looking for. However, I have found code that yields groups of stocks
that are about to trigger almost any indicator signal you can think of.
Eight is the default value and the threshold for buy is –0.5, and for sell
it’s 0.5. When you plot it on a chart with your favorite system you will
see that, with a minor adjustment or two in the default value of the
RSI, it matches up closely with entries from your system. Explorations
are interested only in entries. However, if you desire, you can always
use two plots, one set to identify entries and one set to identify exits.
(Remember, this is if your system is based on indicators and not
patterns. I will discuss patterned entries later.)
Once you have adjusted the RSI period to match up to your desired
results, it’s easy to plug this code into an exploration with the uRSC
Adobe tools
code, or whatever else you might want to use as a value generator or
filtering criteria. For example, I only trade high volume, higher priced
stocks because I’m a big block trader. Some people want only low
priced stocks, so they might screen out all of the stocks over $10 a
allow text from
share. this document
If the exploration finds 50 potential trades, perhaps 10 of them will fit to be selected
and copied.
your desired entry signal with your trading rules. Yes, you may have to
look at 100 or more charts to find the best entries. (We’re talking about
your money here, so buckle up and do the work! )
The IFT of the RSI can be used as a crossover indicator, with the
BarsSince function, the alert function, or as a binary indicator. This
makes it versatile.
Here are a few more points to consider. The uRSC value is not in itself
a screening tool, unless you want to measure the strength of stocks
already in what looks like a trend. In general, just as many stocks move
up from a uRSC value above zero as do those below zero. In the next
article I will explain how to do explorations that use the uRSC very
effectively. The uRSC can be used to develop very profitable systems
for trading ETFs, mutual funds and stocks in general.
So how do you define that strategy? Well, you can use something like
the uRSC to find the best performing sectors, search those sectors for
tech stocks that are in an up-trend and that have had an entry signal
within X bars ago. Another alternative that I have tested and traded
successfully is finding stocks generating long or short entry signals
based on option pricing. You have to use a specialized program like
PowerStrike and combine it with a filtering system to identify which
trades are likely to be good trades. PowerStrike code provides the
explorations and chart information, but simply taking every possible
trade that PowerStrike identifies is a bad strategy. You have to build a
system around it because it’s not a system right out of the box.
So what’s my reward for all of this work? It’s hard to put numbers on
things because everyone is different and none of my systems are
mechanical. I know what you’re thinking – stop hedging and just tell
us!
Okay, I will, but remember, it’s hard to answer because there are
thousands of ways to trade, many thousands of risk profiles, and
varying degrees of laziness. Using what is comfortable for me, the type
of capital account I trade, what I trade and the market conditions I’ve
seen in my lifetime, I expect to make 20% to 60% a year. I caution you
not to pick the bigger number and assume you can average 60% a year.
You can’t. If you think you can, there’s nothing in these articles that
can help you. You are going to be toast, so I recommend buying a big
supply of burn cream before you run out of money.
Think about all the hedge funds, private money managers, mutual
funds and little guy traders out there. None of them average 60% a year
for more than a year or two. If you can average 20% a year for 10
years running, you’re at the top of the heap, and it’s a pretty lofty pile.
Jim
Before changing any indicator, print out a hard copy. If the worst
comes to the worst you can at least get back to the point where you
started (not recommended, but better than no backup at all).
A latch is a
at all. For my part I really didn’t need the number of tea-breaks that
PREV offered. I eventually stumbled onto the code structure that I now
memory device call a simple latch. Back then it was called a flag, and that confused
almost everyone. Eventually I settled on calling it a latch, and it works
in the same manner as a mechanical or electronic latch.
Definition
I’ve divided the subject of latches into two parts, Simple and PREV-
based. Except for exercise 1, this month’s article only looks at simple
latches. PREV-based latches feature next month in the second of this
two-part series.
A simple latch is binary in nature. This means that its result can only
have one of two states – usually zero or one. Other values can be
assigned, and I’ll show you how to do that with one of the exercises.
PREV-based latches are more flexible than their simple cousins. They
are not restricted to just two values and can store almost any value you
might wish. The disadvantage of PREV-based latches is large amount
the computer resources needed to drive the PREV function.
It’s important that you appreciate what the simple latch is a substitute
for, so I’m taking a moment to show you the code that first triggered
my search for a simple latch. The construction of a PREV-based latch
Figure 8. is examined in more detail next month. All you need to know for now
Exercise 1. Plotting a is that the code contains PREV, and it executes much more slowly for
PREV-based latch. that reason. An exploration that completes in 1 minute using the PREV
If the set signal occurred most recently the latch will be in the set (true)
state, and if the reset signal occurred most recently the latch will be in
the reset (false) state. MetaStock processes a chart from the first bar on
the left to the last bar on the right – from earliest to latest data. The
state of the latch is checked and updated as each new bar is processed,
moving from left to right across the chart or data series. The essence of
a simple latch is in deciding which of two events occurred most
recently. See Figure 9.
This article uses the crossover of two moving averages to create set
and reset signals for each exercise. These signals have no significance
other than that of creating generic set and reset signals.
The set and reset signals both become valid on the same bar – the 26th.
The Cross() function adds another invalid bar to the 25 already forced
by the longer EMA. The total number may be much higher on some
charts. This latch won’t function until there has been a moving average
cross in both directions. One BarsSince() function will not be triggered
until the second cross takes place. The invalid plot for the latch extends
until that cross occurs.
The "Init" variable in exercise 3 is used to simulate initial set and reset
signals. These signals give a clear reference point from which the
BarsSince() functions in the latch can begin to operate. If you compare
plots between exercises 2 and 3 you’ll see that 3 has an N/A plot of
just 26 bars. Exercise 2, however, has an N/A plot that extends until
exercise 3 sets for the first time. An extended N/A plot may seem like
a minor detail, and sometimes that’s all it is. The real problem is that it
can make a sizable portion of data unavailable for testing, and thereby
fudge the data starting point and any test results. The use of an "Init"
variable in a simple latch has no downside that I’m aware of.
The construction of an "Init" signal is not about the actual values of the
signals it’s made from, but whether or not these signals are valid. The
sum of the two inputs, "Set" and "Reset", cannot be greater than –1
until both variables plot a valid value, i.e. "Set" and "Reset" are binary
signals. By definition, neither signal can ever be less than zero. The
test for a cumulative count of 1 ensures that this signal is only true for
the first valid bar, then false for every subsequent bar. That’s OK
because the whole purpose of "Init" is to generate a true only on the
initial bar. This signal being true for one bar tells us that the set and
reset signals are both now valid.
As I mentioned earlier, it’s possible to assign values other than one and
zero to a latch. The If() function can be used to alternate a latch output
between any two constant values.
You also need to know that some ways of putting the "Trade" variable
together give bad results at the left side of a chart. Of the following
four latch constructions, only two are logically correct 100% of the
time. The first two are the correct versions.
{a} Trade:=If(BarsSince(Init+Set)<BarsSince(Init+Reset),1,0);
Is functionally identical to
{b} Trade:=If(BarsSince(Init+Set)>=BarsSince(Init+Reset),0,1); Figure 12.
An inverted initial plot caused by
Neither of the above examples are functionally the same as the use of "<="instead of "<"
{c} Trade:=If(BarsSince(Init+Set)> between the BarsSince() functions.
BarsSince(Init+Reset),0,1); {wrong}
The difference is in the use of "=" with the ">" and "<" symbols. When
written incorrectly the polarity of the latch before the first set signal is
reversed (inverted). This may be only a small point, but for those
leading bars it is still wrong. Testing of historical data requires that
signals be as accurate as possible for all data in the test. Whatever you
use the simple latch for, take care to avoid these traps. The correct
construction when not using an If() function is demonstrated in {f} and
{g} as seen below.
Figure 13.
An inverted plot caused by the use {f} Trade:=BarsSince(Init+Set)<BarsSince(Init+Reset);
of ">="instead of "<" between the {g} Trade:=(BarsSince(Init+Set)>=BarsSince(Init+Reset))=0;
BarsSince() functions.
{h} Trade:=(BarsSince(Init+Set)>BarsSince(Init+Reset))=0; {wrong}
{i} Trade:=BarsSince(Init+Set)<=BarsSince(Init+Reset); {wrong}
The timing charts, see below and Figure 14, are my attempt to show
the timing relationships between the different variables of a simple
latch. Exercise 6 can be used to show the same relationships on any
MetaStock chart. Obviously the signals are going to vary from chart to
chart, but the intrinsic relationships remain the same. A timing chart
like this is not unlike the stock or commodities chart that you are so
familiar with. Both plot a value in relation to time. Timing charts plot
binary values, and security charts plot prices.
__ _
_____/ \_____/\_______________/ \______ Set
__
N/A ___/\____________/ \________/\__ Reset
into a comment. You can then make changes to the original variable
and not worry about corrupting it. When you’re finished testing and
happy with the result you can restore the original code, or just delete it.
Disclaimer: There are significant risks associated with securities trading. Nothing in this newsletter should be considered investment
advice, trading advice or recommendations as to investment management. I am not an investment advisor, and the information
provided in this newsletter is for educational purposes only. Each subscriber uses the information published in MetaStock Tips &
Tricks at their own discretion and bears all risk associated with the application of that information to their trading or investment
decisions. Nothing in this newsletter implies that any formula, method or strategy is in fact correct, or reliable in all circumstances.