Beruflich Dokumente
Kultur Dokumente
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).
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.
or,
G(a, n)[i] = (1 a)^i
for i = 0 to i = n.
= 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.
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
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
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]
for i =0 to i = n - 1.
for i = 0 to n k + 1.
For example,
B.close [i] = B[i].close
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
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
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
for all i.
for all i.
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
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.
19