Sie sind auf Seite 1von 19

Trading Strategies from Technical Analysis

1. Strategies and Probability


The prediction of the future course of prices has been an elusive quest of traders for as
long as there has been trading. Broadly speaking there are two types of information used
from which to infer this. These are fundamental data and trading data (like price, volume,
etc.). There is general agreement that over a long period of time, fundamentals rule. For
short term trading, there is much anecdotal evidence that technical analysis works better.
This does not mean that technical analysts dont also try for long term trades or that
fundamental analysts never close positions quickly, but it is a good general rule.
Using mathematical or statistical tools always depends on the assumption that something
in the future correlates somehow with something in the past. Is that vague enough? No
matter how much testing one does, at some level you have to believe in that principle.
Qualitative principles are useful for basic understanding, but only quantitative principles
can be used in actual trading.
It is simpler to analyze the trading of a single instrument priced in terms of a single
currency, say dollars. The same principles should apply no matter which two assets are
being exchanged. Nobody expects to predict anything with certainty. The best one can
hope for is to have an idea of what the probability of some future event is, given the
information we have from the past. There is a very effective mathematical notation for
abstract theory, but the only idea used here will be the notion of conditional probability.
If S is some set of information (typically Boolean expression, describing some aspect of
the past) and T is a Boolean expression which will be known at some future time, then
Prob(T | S) means the probability of T being true, given that S is true.
Often the word given is replaced by conditioned on or conditional on.
The first guess as to how to use probability is that if the probability of the price being,
say, higher at some future time is greater than 50%, a buy signal occurs. The problem
with this is that the higher price may lead to a tiny profit while the loss when the price is
lower is larger. To take this into account, the idea of expectation is introduced. For each
possible price at some future time, multiply the probability that it is the actual price at
that future time by the price itself. Add these up over all possible prices. That is called the
expected price or the expectation of the price, or even the expected value of the
price. All are perfectly acceptable. If P(t) is the price at time t (known for past t;
unknown for future t, often called a random variable for each future time t and a
stochastic process when viewed as a function of t), the notation for the expectation is
E(P(t)),
or,
E(P(t) | S),

for the expected value of P(t) conditioned on S being true.


Probability theory alone is not enough. The only way to make money trading is by
following some strategy. What is meant by strategy? Informally, a strategy is a set of
instructions on when and how much to trade. There are only three things a trader can do
at a given instant of time: buy, sell or do nothing. That is a slight oversimplification,
since a buy or sell can be for one unit or many units. This leads to the definition that a
strategy is a rule that at every future time t gives an integer representing how much to
buy. A sale would be a negative number. Doing nothing would be a zero. Of course, the
vast majority of the time the strategy gives a zero. Thats pretty straightforward. The only
subtlety, the elephant in the room, is that at any time t, in computing the value of that
integer, the strategy can use all information that is available at or before time t. Note that
at a given time the strategy can add or subtract from a current position. There is an
elegant mathematical formulation, but it is too abstract for this discussion. Because of its
central role, it is worthwhile to formally state the definition of strategy.
Definition 1: A trading Strategy is a rule or set of rules for trading one or more
instruments which describes at every time, the exact trade to be executed, if the
market permits.
Is the expected profit of a strategy adequate for trading? The short answer is no. The long
answer is also no. Even if the odds are way in ones favor it is unwise to bet ones whole
net worth on a single trade. This often called money management but I prefer risk
management or risk control. There is no single ideal measure of risk. A lot depends on
the nature of the probability distribution of future prices. Indeed with full knowledge of
these distributions, it would be easy to either find a winning strategy or to know that there
is no winning strategy. The mathematics of this is rich and beautiful. It attracts many
marriage proposals (sorrycouldnt resist). But not to worry, the exact distribution is
unknowable. Even with complete knowledge of the past, the most that can be shown
empirically about a candidate distribution for some past period is that it is consistent
with all tests so far at some confidence level. Even confidence level calculations depend
on certain assumptions about the distribution. This is the dirty little secret underlying
ALL statistical studies. Getting back to risk, the most common measure of risk is the socalled standard deviation, or its square, the variance of a test of the strategy. This gives a
pretty good idea of the risk. A popular calculation is to take the ratio of the expected
profit to the standard deviation. That is often called the Sharpe ratio. It is a unitless
quantity. Unitless quantities are essential to nearly all advanced mathematical techniques,
since for example, you cant take the natural logarithm or the inverse tangent of a price or
other quantity that has a unit attached to it. Authors of articles on technical analysis
would do well to take this into account.
When trading in the real world, an important consideration for any trading strategy is the
dreaded drawdown. This is either the dollar or percent loss that a strategy loses during
some time period. No matter how high the expectation or how low the standard deviation,
no trader can sustain unlimited drawdowns. Because of this most strategies come
equipped with some kind of stop-loss feature so that no single trade can lose more than a
certain amount. Risk tolerance is up to individual choice. Still, traders should at least

consider basing their drawdown protection for a single trade on the size of the whole
account rather than focusing on that one trade, or even that one day.
Technical traders often use a number known as the profit factor to measure performance
of a strategy. The idea is to run the strategy many times, calculate the average total profit
for the profitable instances and the average total loss from the losing instances. The ratio
of the profit average to the loss average is called the profit factor. Clearly, other things
being equal, the bigger the better. Theoretically, these individual profit factors provide
statistical estimates of the ratio of the expected gain to the expected loss. To distinguish
between these two concepts, call the first the profit factor of the trades, and call the
second the profit factor of the strategy. If these terms are used, it is important to
emphasize that the profit factor of the strategy depends on the (usually unknown)
probability distribution, while the profit factor of the trades does not and is easy to
calculate. Again, the latter is a statistical estimator for thee former.
The preceding paragraphs discussed a few risk management techniques. There is much
more to say on the subject, but for now concentrate on the most popular category.
Namely the case of strategies with positive profit expectation and built in maximum loss
per trade, usually in the form of a stop-loss order.
Some simple mathematical calculations using only high school algebra shed light on the
role of probability theory in analyzing this family of strategies.
Suppose we have a strategy with a fixed target of t ticks and a fixed stop-loss of s ticks.
Suppose the probability of being up t ticks before being down s ticks is p.
Assuming we can always trade at the stop, the expected return of this strategy is
E = p*t - (1-p)*s.
Equivalently,
E = (s+t) * (p (s/(s+t))
The strategy works over time if and only if E > 0. Solving for p, we see that amounts to
p > s/(s+t)
For example, if s =5 and t = 2, we need p > 5/7, or approximately p > 70%.
In practice we never know exactly what p actually is. But SOMEHOW we are signaling that
p > 70%. That is a prediction of future behavior. If it is important to emphasize the
dependency of p on s and t, the notation p(s, t) will denote the probability of a position
being up t ticks before being down s ticks. If it is also important to explicitly show the
dependency of p on the position x, and the current price y, use the notation:
p(x, y, s, t)
It is also useful to define
q(s, t) = s/(s+t).

The formula for E can then be written as


E = (s+t)*(p(s, t) q(s, t)).
The profit factor F of the strategy (using p = p(s, t)) is
F = p*t/(1 p)*s = (p/(1-p)) * (t/s).
A little more algebra relates E and F:
E = (1 p)*s*(F 1).
It is worth noting that we have three equivalent criteria for a strategy to be break-even.
a. E = 0
b. F = 1
c. p(s ,t) = q(s, t)
This leads to the description of q(s, t) as the break-even probability, and the strategy as a
martingale strategy. It is remarkable but true that all other probabilities lead to strategies
which have a positive or negative expectation. If a strategy has a negative expectation, its
associated negative strategy has positive expectation. It seems almost impossible that out
of all the possible probability distributions, a given strategy just happens to have its
probability distribution be p(s, t) = q(s, t) for all choices of s and t. If only it was possible
to actually discover p(s, t) for some such strategy, it would yield a winning strategy. The
problem is that p(s, t) depends on future events and can never be known precisely.
Reliable statistical predictions for p(s, t) are difficult to come by. The author has never
actually seen one.

A common situation in technical analysis is to get a signal to buy or sell. But just
opening a new position is only part of a strategy. There must be an exit rule too. There
are at least as many exit rules as there are possible signals. But for some reason, the most
popular exit strategy is the one described above.
The importance of this example cannot easily be overstated. If the function p(s, t) were
known for every time and starting value of the price, then even for more complicated
strategies the expectation and standard deviation of the strategy could be computed. At
the very least, only strategies with positive expectation should be considered for opening
a new position. For closing trades, or any trade when there is an open position at the time
of the trade, it is possible to trade rationally even if the expectation of that trade is
negative. That can only happen if it is desired to reduce the risk of the position.
Technical analysts sometimes debate whether to use actual price changes or percent
changes to analyze the probabilities and expectations. In practice the choice is made to
lead to the simplest mathematical formulation. One popular assumption is that prices
follow a log-normal distribution. For now, it is easier to stick with the current
formulation.

2. Vectors and Sequences


Nearly all the information of interest is expressible in terms of vectors
A vector is any function v defined on a set of integers from 0 to N-1, where N
is a fixed non-negative integer.
In this case, Length(v) or v.length is defined to be N, and the value of v at an
integer i is denoted by v[i]. These are familiar notations used in computer
science for a zero based array or vector.
Some useful vector operations are coordinate-wise arithmetic and sum.
If u and v are two vectors of the same length, and if c is a scalar (vector of length 1),
For i = 0 to (v. length 1):
(u v)[i] = u[i] v[i]
(c*v)[i] = c*v[i]
(u*v)[i] = u[i]*v[i]
(v c) [i] = v[i] c
v.sum (or sum(v)) is the sum of the values v[i]
v.max (or max(v)) is the maximum of the values v[i]
v.min (or min(v)) is the maximum of the values v[i]
If w is a vector, w >= 0 means w[i] >= 0 for i = 0 to (v. length 1).
If v and w are vectors of the same dimension and w >= 0, define operators average
and weightedAverage(w) by
v.average = v.sum/ v. length.
v.weightedAverage(w) = (w*v).sum/w.sum
Note: The word mean is synonymous with average and they can be used
interchangeably.
If a is a number between 0 and 1 inclusive and n is a positive integer, denote by
G(a, n) the n-dimensional vector
G(a, n) = (1, 1 a, (1 a)^2, , (1 a)^(n 1))

or,
G(a, n)[i] = (1 a)^i

for i = 0 to i = n.

The geometric average v.geometricAverage(a, n) is defined by


v.geometricAverage(a, n) = v.weightedAverage(G(a, n)).
Frequently, some measure of how close the averages are to the data is needed. The
usual measures of this are the variance and the standard deviation. These are easy to
define, but the notation is getting out of hand. Unfortunately, it is necessary, in
order to distinguish among the various types of averages which are used.
The variance and standard deviation of a vector v from its mean are defined as
v.variance = sum ((v v.average) *(v v.average))/v.length
v. standardDeviation = squareRoot(v.Variance)
v.weightedVariance(w) = Sum (w**(v v.average )*(v v.average )/w.length
v. weightedStandardDeviation(w) = squareRoot(v.weightedVariance)
So far these various averages have been defined for a single numerical vector. In the
applications to trading, it is necessary to average various subsequences of a sequence
called a time series. These averages are themselves sequences, called moving averages,
or moving whatevers.
Let s[i] for i= 0, 1, 2, be a numerical sequence (finite, but the length is usually
irrelevant). If n and k are positive integer, kth term of the n-period moving
subsequence is the vector (or subsequence) s.sub(k, n) of length n defined by
s.subseq(k,n)[i] = s(k + i) for i = 0 to n 1.
Note that it is the index k that moves.
If n is a positive integer, the n period simple moving average of s is the sequence
s.SMA(p) defined by
s.SMA(n) [k] = s.subseq(k, n).average,
Similarly, for example, if w is a weighting vector of length n, the n period weighted
moving average of s is the sequence s.SMA(w, n)) defined by
s.WMA(w, n) [k]

= s.subseq(k,n).weightedAverage(w)

s.WMSD(w, n) [k]

= s.subseq(k,n).weightedStandardDeviation (w)

s.GMA(a, n) [k]

= s.subseq(k,n).geometricAverage(a, n)

Finally, there is the idea of exponential smoothing, which leads to the Exponential
Moving Average (EMA).
The exponential moving average (EMA) is defined quite generally for any sequence
x[i] by the following recursive scheme: For each positive integer k,
x.EMA(a)[k] = a*x[k] + (1 a)*x.EMA(a)[k + 1] for n > 0
A bit of high school algebra shows that for all positive integers n,
x.EMA(a)[k] = (1 (1 a)^n)*x.GMA(a,n)[ k] + (1 a)^n* x.EMA(a)[k + n]
or, rearranging terms,
x.EMA(a)[k] = x.GMA(a,n)[k] + (1 a)^n*(x.EMA(a)[k +n ] x.GMA(a,n)[k]).
If 0 < a < 1, then (1 a)^n approaches 0 as gets large, while the averages generally
remain bounded. This means that the EMA and GMA are pretty much measuring
the same thing. Indeed, going to the limit and using an infinite series,
x.EMA(a)[k] = x.GMA(a, )[k].
This shows that in fact, the EMA depends, at least slightly, on every past value of a
time series. Since all time series of prices in fact have only a finite past, there is a
phantom past which must be specified and the final EMA depends on this
specification. To make matters worse, most authorities recommend using a simple
average of the some number of the most recent terms, to seed the recursion.
Fortunately, none of the usual choices seems to do any harm. It is just a question of
which smoothing you want. The choice of smoothing factor is more important than
how you approximate the true values. Unfortunately, a whole mystique has
developed around these choices, with little justification beyond gut feelings.
In most of the literature on technical trading, the smoothing factor a is chosen to be
a =2/(N + 1),
where N is called the number of periods.
The reason for this choice is a bit obscure, but it is said to relate the smoothing
factor to the number of periods used to approximate the EMA. In fact it seems to
have nothing to do with that. Since the recursive formula used to define EMA
doesnt terminate naturally, initial values must be specified. None of the usual
choices seem very compelling. The language of number of periods as opposed to the
decay factor is used almost universally in the literature, so no attempt to change that
point of view is suggested here.

The use of vectors and sequences increases the level of abstraction, allowing for a more
compact notation that emphasizes the similarities in the definitions of indicators.
This much abstract notation is not usually found in articles or even treatises on technical
analysis. One reason is probably the lack of mathematical sophistication on the part of
most potential readers. Another reason is that there is no natural dimension for bar
vectors. In fact there are whole families of indicators which compare results obtained
from different choices of dimension. Once a choice of the types of bars to be studied has
been made, there is a potentially infinite sequence of bars going backward in time, from
which bar vectors of various dimensions can be extracted. Of course for any given
instrument, there was a starting time, before which nothing traded. This means that any
sequence of bars terminates at some point in the past. Nevertheless, there are typically a
large number of bars in the full sequence, so the termination point is rarely an issue.

3. Ticks and Bars


Analysis of trading data is the essence of technical trading. The word tick has at least two
useful meanings. The first is as a unit used to measure prices changes, as in a move of 5
ticks up. Each tick represents a fixed amount of money. The other use is as a fixed length
vector v of information describing a trade or the state of the market.
v[0] = Time Stamp
v[1] = Price
v[2] = Size (volume)
v[3] = Bid price
v[4] = Ask price
v[5] = Bid size
v[6] = Ask size
Usually, only the first three are used. The last four give a snapshot of supply and demand,
but have never really caught on. It is difficult to even find historical data on bids and
offers. Just for clarity, if only the first three are available, call it a tick, but if all seven are
available, call it an expanded tick. So ticks are 3 dimensional vectors; expanded ticks are
7 dimensional vectors.
The vector notation for tick here and bars later is cumbersome. In object based
programming, ticks are considered to be objects of a class of ticks. The notation is
intuitive, clear, and easy to use once you get used to it. The data in a tick are then
described as properties of the tick object and dot notation is used to retrieve them.
If T is a Tick object, its properties are given by:
T.timeStamp
T.price
T.size
Etc.
In nearly all technical studies, ticks are grouped into sequences of consecutive ticks.
Certain information from them is collected into objects called bars. Bars contain far less
information than the original sequence of ticks, which will be referred to as the tick
sequence of the bar. There are several frequently used types of bars. It is not possible to
access the data in the tick sequence. The most common data preserved by a bar b are
b.open
b.high
b.low
b.close
b.openTime
b.closeTime
b.numTicks
b.volume

Price of first tick in the bar


Highest price of any tick in the bar
Lowest price of any tick in the bar
Price of last tick in the bar
Time stamp of first tick in the bar
Time stamp of last tick in the bar
Number of ticks in the bar
Sum of all the volumes of the ticks in the bar

There are two more pieces of information which could easily be preserved, but for some
reason, seems not to be in most systems. They are the so-called UWAP and VWAP
b.UWAP
b.VWAP

Un-weighted average price of all ticks in the bar.


Volume weighted average price of the ticks in the bar

One of the most important observations about the above ten pieces of data is that if you
know them for two consecutive bars, then you can easily calculate them for the union of
those two bars. To keep the notation simple, no distinction is made between bars with all
ten and bars with just the first eight. However if we actually want to use them in a
program, we could distinguish SmallTick objects and LargeTick objects
Two bars, b1 and b2 are said to be consecutive or adjacent. If there are no ticks between
them and the ticks of b2 precede those of b1. Single bars are of little value, but when a
large number of consecutive bars are studied, it is possible to gather information about
the sequences of data from the bars. There are many ways to choose the bars to be
preserved and studied. If the entire tick stream is preserved, obviously every conceivable
bar can be described. However, usually only the bar information is preserved, so it is
important to have rules for constructing the bars. The two most common are
Constant size
Constant time

All bars contain the same number of ticks


All bars contain the ticks from constant length time intervals

There are other possibilities, but these are the main ones used.
As noted there is other information which could easily and usefully be preserved for each
bar. One important one would be the standard deviation from the mean of the tick prices.
Other measures of volatility could be used like the standard deviation of the natural
logarithms of consecutive price ratios within the bar.
It is rare that a single bar is of any intrinsic interest. It is only when a sequence of
consecutive bars is studied, that useful information can be derived. Strangely, there seems
to be no standard name in technical analysis for such a sequence.
To remedy the defect of not having a name for a sequence of consecutive bars, define
A bar sequence is a sequence of consecutive bars going backwards in time. If
B denotes a bar sequence, the notation B[i] is used to select the bar which is i
units before the most recent bars. The bars B[i] and B[i + 1] are consecutive
bars with B[i] more recent than B[i + 1].
A bar vector of dimension n is an n-dimensional vector of consecutive bars
from a bar sequence. If B is a bar sequence, let B(k) be the bar sequence
starting with B[k] and let B(k, n) be the n-dimensional bar vector starting at
B[k]. In other words,

10

B[k][i]

= B[i + k] for all i,

B(k, n)[i] = B[i+ k]

for i =0 to i = n - 1.

It is important to remember that bar vectors are defined relative to a starting


time, and that must always be taken into account. It is easy to reference
earlier bar vectors as B(k + m, n).
The notation B(n) can be used to denote the overlapping sequence of bar
vectors whose kth element, B(n)[k], is B(k, n).
The notation for bar sequences is a bit odd. It would seem more natural to
write B[-i] rather than B[i], so that the indices went in the same direction as
time. But the overwhelming majority of practitioners use the notation as
defined above. The most widely used charting packages also use it.
The whole point of technical analysis is to peer into the future probability
distributions of price and various other quantities. Since the current bar is
always B[0], it is natural to refer to the next bar in the future as B[-1], then
B[-2], etc.
It is convenient (an understatement) to extend the high, low, open close, etc to bar
sequences and vectors. If B is a bar sequence or vector, and if f is any function defined on
bars (f is usually a property or method of the bar class), extend f to the bar sequence or
bar vectors in the obvious way:
B.f [i] = B[i].f
In particular, for the vectors B(k, n),
B(k, n).f [i] = B(k, n)[i].f = B(k + i).f

for i = 0 to n k + 1.

For example,
B.close [i] = B[i].close

price of last tick in bar i

Other examples would be to choose f as open, high, low, openTime, closeTime,


numTicks, volume, UWAP, VWAP. These are built in properties of bars and now, of bar
sequences and bar vectors. This extension of a function is also useful if f is any function
defined on bars in terms of these built-in properties.
In many situations the bar sequence or vector B is known implicitly and, for example, f[i]
can be used in place of B.f [i]. This abuse of notation really isnt such a good idea, but it
is in widespread use by technical analysts and computer programs they use. For example,

11

close[i] or C[i] is the close of the ith bar in the bar sequence, but if there are several bar
sequences in use simultaneously, this notation becomes ambiguous or worse.
While it is useful to be able to apply a single indicator to each bar in a bar vector, there
are other times when it is better to combine the bars in the vector into a single bar before
applying the indicator. Naturally this loses still more information, but perhaps it adds
clarity. To this end define an operator collate which combines the bars in a bar vector
into a single bar. This is a place were the object oriented approach really shines. All that
is necessary is to define the properties which characterize a bar. Recall that there are up
to ten such properties. All of them have obvious extensions to the union of the adjacent
bars. For completeness they are listed below. Let BarV be any bar vector.
BarV.collate.openTime

= BarV[BarV.length 1].openTime

BarV.collate.closeTime

= BarV[0].closeTime

BarV.collate.open

= BarV[BarV.length 1].open

BarV.collate.high

= BarV.high.max

BarV.collate.low

= BarV.low.min

BarV.collate.close

= BarV[0].close

BarV.collate.numTicks

= BarV.numTicks.sum

BarV.collate.volume

= BarV.volume.sum

BarV.collate.UWAP

= BarV.UWAP.average

BarV.collate.VWAP
= BarV.VWAP.weightedAverage(w),
where w[i] = BarV[i].volume for i = 0 to BarV.length 1

12

4. Indicators: Basics
If bars are the building blocks of technical analysis, then indicators are the tools used to
study them. The most general definition is
An indicator is any numerical function of bar sequences or bar vectors. The notation
was explained in the previous section. Care must be taken to keep the units straight
and, wherever possible, indicators should be unitless combinations of the data. For
example, a ratio of two prices is preferable to a single price or a difference of two
prices. If multiple indicators should be grouped together, they can be regarde as a
vector of indicators, but allowing more arbitrary ranges stretches the usefulness of
the concept. Taking the narrow view, the definition above requires that indicators
must be numerical valued functions defined on bar sequences.
If the only data used are from ticks and bars, there are only a few units to worry
about. These are

Price (Typically in currency/instrument)


Volume (Number of units of an instrument or currency being traded)
Time (Time differences are preferable)
Number of bars (A proxy for time, but different enough to matter)
Number of ticks (A proxy for time, but best thought of as a unit on its own)

It is no exaggeration to say that there are dozens, maybe hundreds of popular indicators.
Many or most of them use various parameters in addition to the bar information. Since
the open time and close time are part of that information, pretty much any time-series of
data can be used. That leaves a lot of flexibility.
When using bars, most of the information in the original sequence of ticks is lost.
Probably, the original reason for using bars was to facilitate saving data and graphing it
by hand. Nowadays, with fast computers, that is not necessarily an issue. One reason for
the continued popularity of bars is that old habits die hard. But beyond that, it is common
when analyzing data, to cut down the dimension of information studied. There is a strong
belief among practitioners that choosing the right size bars to use as input to various
indicators is critical to success. There is a thriving cottage industry in the normalization
or shaping of data trying to discover this right size for use in various indicators, to give
maximal predictive value. This topic will be discussed in more depth later.
The notation used in most lists or treatments of indicators is haphazard at best, and often
confusing. By using a bit more abstraction, the definitions should seem clearer, but may
require a bit more effort to understand. One of the main reasons for the abstractions is to
unify the definitions and show that many seemingly diverse indicators are really special
cases of a few general indicators with extra parameters.

13

5. Moving Averages, Standard Deviations, and True Ranges


Surely the most important and widely used indicators are the various moving averages.
Before even defining them, it is worth noting that virtually all indicators are moving.
The whole notion of bar sequences and bar vectors was designed to facilitate the
description of indicators as time series or vectors going back in time. Yet, of all the
indicators, the moving averages are among the few to use the word moving explicitly.
There must be a historical reason, but it is not apparent what it is.
The two most important moving averages are the simple moving average (SMA) and the
exponential moving average (EMA). They both smooth out the data, but the EMA is
more flexible. It is important to remember that the moving averages require other
indicators as input.
Let B be a bar sequence and f a function defined on B. Define the n period simple
moving average B.SMA(f, n) of B to be the sequence defined by
B.SMA(f, n)[k] = ((B(k, n).f). average
If you are not comfortable with this level of abstraction, what happens is that the kth bar
in the n-dimensional bar vector B(n) is B(n)[k] = B(k, n). Apply f to each bar of B(k, n).
and average the values.
Perhaps the most popular type of smoothing is the EMA. It was defined above for
arbitrary sequences.
Extend this notation to a function f on a bar sequence B via
B.EMA(f, a, n)[k] = B(k, n).f.EMA(a)[0]
Often, it is useful to have some measure of how closely the data are approximated by the
various moving averages. The most common and useful measure is the moving standard
deviation.
If w >= 0 is a positive of dimension n, and B is a bar sequence, define the n-period
weighted moving standard deviation WMSD(w, f) of f on B to be the vectors defined by
B.WMSD(f, w, n)[k] = B(k, n).f.WMSD(w)
When indicators are graphed, moving averages of various kinds are usually displayed. It
is often helpful to also graph parallel curves above and below the moving averages. The
most popular by far, are the so-called Bollinger Bands, named around 40 years ago after
the technical analyst who popularized them. They are simply the parallel curves a fixed
number of standard deviations above and below the moving average. That concept has
been around in statistics for a long time.

14

Because of the way bars are defined, there can be a difference between the opening price
of a bar and the close of the previous bar. In extreme cases the closing price of the
previous bar is outside the range of prices of the current bar. In that case moving a single
tick from one bar to the next could result in very different values for many indicators.
This is bad, since one doesnt expect minor changes like that to have a major impact.
With that in mind define, for any bar sequence B, and i= 0, 1, 2
B.trueHigh[i] = Max(B.high[i], B.close[i+1])
B.trueLow [i] = Min(B.low[i], B.close[i+1])
B.trueRange[i] = B.trueHigh[i] - B.trueLow[i]
Another popular indicator is the average true range or ATR. It is the moving
average over a fixed number of bars of the trueRanges. The default average to use is
the simple average, but obviously any of the averages will do.

15

6. Oscillators
Oscillators are among the most popular technical indicators. .It is hard to find a precise
general definition of oscillator, but there do seem to be some characteristics shared by the
majority of indicators which are called oscillators.
1. True to the name, oscillators should go back and forth between two extremes,
although not all have an actual maximum or minimum value.
2. The back and forth moves should plausibly have something to do with changes in
supply and demand, whatever that means.
3. It is highly desirable for an oscillator to be unitless, and most are.
4. Many oscillators are expressed as a percent, requiring that some fraction be
multiplied by 100.
This motivates a few more definitions.
An indicator is said to be bounded if its values are constrained to be between two
predetermined values. Otherwise it is said to be unbounded. The distinction is not very
important. It is easy to take any indicator and change its range from unbounded to
bounded or vice versa, and even to specify the range to be a particular interval like 0 to 1,
or 0 to 100, or -1 to +1. This is usually done with so-called linear fractional
transformations, which are ratios of linear functions, like (ax + b)/(cx + d).
Various intervals are useful for graphical display, but here is one vote against converting
fractions to percents. In nearly every calculation, it is necessary to convert back to the
fraction anyway, and it can only lead to confusion. Admittedly, that is a minority opinion.
The preceding paragraphs are important because much of indicator construction is
devoted to just such range changes. That is not a criticism. It can lead to greater visual
clarity and intuitive feel.
What a range change cannot do is change an indicator of little predictive
value to one with greater predictive value.
Once an indicator has been transformed to a specific finite range, it pretty much meets the
informal characteristics for oscillators given above, with the possible exception of having
something to do with supply and demand. However, that is vague enough to have little
real effect. The question is, are there any unitless indicators which are not classified as
oscillators?
Some popular oscillators are defined below. They may differ slightly from standard
definitions in that they are expressed as fractions instead of percents. In all cases they are
regarded as being functions of a bar sequence B. Most of them are based on some other
indicator or indicators, usually denoted by f, g, h, etc. and various numerical parameters.

16

Rate of Change (ROC) Oscillator:


ROC(f, n):

B[i].ROC(f, n) = (B[i].f /B[ i+ n].f )- 1

for all i.

f is usually a price, and most common is f = close. Of course f must always be


positive.
For those who prefer their indicators as percents, there is
ROC%(f, n): B[i].ROC%(f, n) = 100*(B[i].f /B[ i+ n].f 1)

for all i.

MACD and PPO:


MACD stands for Moving Average Convergence Divergence. It is simply the
difference between two moving averages of different lengths of an indicator. Usually
exponential moving averages are used but this seems arbitrary.
If f is a numerical indicator, and m and n are positive integers, with m < n, define
f.MACD(m, n) = f.EMA(2/(m + 1)) - f.EMA(2/(n + 1))
and
f.PPO(m,n)

(f.EMA(2/(m + 1))/ f.EMA(2/(n + 1)) 1

This looks similar to the ROC indicators and it is. If we were to introduce enough
new notation, they would both be special cases of a more general indicator.
Stochastic Oscillators:
Let f1, f2, f3 be indicators on a bar sequence B, whose ranges are the same. In
particular they have the same units. Suppose that f1 <= f2 <= f3 and f1 < f3.
Define a unitless indicator STO(f1, f2, f3) on a bar sequence B, with values between
0 and 1, inclusive, by
STO(f1, f2, f3) = (f2 f1)/(f3 f1).
In case the meaning is not clear, if B is a bar sequence,
B.STO(f1, f2, f3)[i] = (B.f2[i] - B.f1[i])/ (B.f3[i] - B.f1[i]) for all i.
The most common stochastic oscillator uses
f2 = close, f1 = low, f3 = high,

on B(0, n).collate

17

The use of B(0, n).collate means that the oscillator is based on the high, low and
close of the whole n-bar range, as opposed to a single bar from the vector.
For some reason, the usual choice of n is n = 14, with daily bars. Even without any
study, it is almost impossible to believe that this choice is ever optimal, let alone
often optimal. In keeping with the notation used by nearly all authors in the field,
and the originator of this indicator (George Lane, I believe), use K(n) for this
sequence of indicators and call it the fast oscillator. Use one of the moving
averages to smooth the fast oscillator, smooth it a second time and call the result
D, the slow oscillator. Signals are generated by comparing the behavior of K and
D. It should be noted that K and D are usually multiplied by 100, and called %K
and %D.
K(n)[i] = B(i, n).collate.STO(low, close, high)
D(n) = K(n).EMA(a).EMA(b)

for all i

(For example)

Since three moving averages are used, there are many choices of how to weight the
averages. No doubt each choice has its detractors as well as avid supporters.
RSI:
Another popular type of indicator is the relative strength indicator. For this, one
first tabulates the number of bars in some range where the indicator f increases and
the number where it decreases. Count the number of bars for which f is higher than
for the previous bar, and the number where it is lower. The ratio of the number up
to number down is called RS (relative strength). In order to bring it into a standard
range, define the relative strength index (RSI) by
RSI = 1/(RS + 1).
The usual definition is 100 times that in order to use a percent rather than a
decimal.
Trend Indicators
Finding trends is probably the most important goal for indicators. Yet there seems to be
no standard notation or name for even identifying trends. Here is a simple suggestion.
For any numerical sequence x[i], define (recursively)
x.trend[i] = x.trend[i + 1] + 1 if x.trend[i + 1] > 0 and x[i] >= x[i+1]
x.trend[i] = -1 if x.trend[i + 1] > 0 and x[i] < = x[i+1]

18

x.trend[i] = x.trend[i + 1] - 1 if x.trend[i + 1] < 0 and x[i] <= x[i+1]


x.trend[i] = 1 if x.trend[i + 1] < 0 and x[i] > = x[i+1]
To complete the recursion, just assume for some N that x[N] = 1 or anything. (It
doesnt matter.)
Informally, x.trend[i] is the length of the longest non-decreasing subsequence ending at i
or the negative of the length of the longest non-increasing subsequence ending at i.
Now, if f is any numerical indicator on a bar sequence B, and b is a bar from B, the
usual definition applies, so that
b.f.trend[i] = b[i].f.trend

for all i.

The reason this is useful is that one frequently wants to express the idea that some
indicator f has not decreased (or not increased) for n consecutive bars, but no more than
n. Just write
b.f.trend[0] = n for non-increasing and b.f.trend[0] = -n for non-decreasing.

7. Charts and Visual Display of Information

19

Das könnte Ihnen auch gefallen