0% found this document useful (0 votes)
39 views26 pages

Algorithmic Technical Analysis

The document discusses algorithmic technical analysis and different types of indicators used in technical analysis. It describes trend following indicators like moving averages and MACD that are useful in trending markets but can provide misleading signals in sideways markets. It also provides examples and explanations of simple, weighted, and exponential moving averages.

Uploaded by

f.lariccia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views26 pages

Algorithmic Technical Analysis

The document discusses algorithmic technical analysis and different types of indicators used in technical analysis. It describes trend following indicators like moving averages and MACD that are useful in trending markets but can provide misleading signals in sideways markets. It also provides examples and explanations of simple, weighted, and exponential moving averages.

Uploaded by

f.lariccia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algorithmic technical analysis

Università Milano-Bicocca, 14th of March 2024

Alessandro Angeli, MFTA


[email protected]
Introduction

Algorithmic Technical Analysis is based on the concept of reworking the


price values ​published by the stock exchanges from a mathematical and
quantitative point of view. These quantitative reworkings give rise to a
series of indicators whose purpose is to draw, through the study of their
charts, indications that will help to evaluate purchase and sales on a
given market.

The prices officially publishes by the stock exchange in Italy are the
following:

Open - High - Low – Close - Volume


An easy example - Price-Rate Of Change
The chart of an algorithmic indicator can be displayed directly on the
price chart using the same scale, or in a dedicated window above or
below the price chart using a dedicated scale.

Each indicator has its interpretative rules and one or more parameters to
be set by the analyst. These parameters are often temporal variables.

A simple example of an algorithmic indicator is that provided by the so-


called Price-Rate Of Change (P-ROC). Its formula calculates the
difference between the most recent closing price and that of (n) days
before:

P-ROC or D-Momentumt: Pt – Pt-n

The P-ROC is generally displayed in a dedicated window below the price


chart as in the example shown in figure 1 in which we have represented
two other indicators, a Moving Average and the MACD. The P-ROC has
been set to 10 periods.
Examples of algorithmic indicators
MACD 400
300
200
100
0
-100
Price chart and 20 periods Exponential moving average
28000
27500
27000
26500
B 26000
25500
25000
A 24500
24000

1000
500
0
-500
P-ROC -1000
-1500
July August September October November December2004 February

Figure 1
A method to classify the indicators
Algorithmic technical analysis presents a multitude of indicators created
or introduced by researchers mostly in the 1970s. Among the best known
there is the Relative Strength Index (RSI) and the Average True Range
(ATR) developed by Welles Wilder.
However, for the most part of the indicators, including Moving Averages,
MACD and P-ROC, there is not an official developer.
In other cases, technical analysis uses formulas coming from other
disciplines such as the Stochastic indicator, the series of the medieval
mathematician Fibonacci or the Standard Deviaton, which the reader will
already know as a statistical tool for measuring the risk of an equity
investment.

In this document we will classify the main technical analysis indicators


according to their function, identifying in which market situation they are
more helpful. So we ordered them, from the point of view of their most
common interpretation, by answering the following question: what kind of
information does this indicator communicate to us and in what kind of
market is it able to really give added value?
Trend following indicators (lagging indicators)
The indicators defined as trend following or also lagging indicators
(literally it means they come in delay) are of great help when the
price moves in a well-defined trend, bullish or bearish. In these
situations they communicate very valuable information with very
interesting buy and sell signals.

However their indications become misleading when the price


moves sideways in a trading range. Understanding why is very simple.
The trend following indicators signal the beginning of a possible trend
(bullish or bearish) when the movement has already started because
they act with some delay.

If, after the buy or sell signal the trend is confirmed, the indication will
prove to be correct and our position will soon start to generate profits.

Instead, if the market is moving sideways, the trend following indicator


will give the signal when the price is already very close to the high or low
band of the trading range and the price will soon start to move in the
opposite direction of our position and it will start generating losses.
Moving Averages
There is a large number of trend following indicators. In this document
we will speak about two.

Moving averages

Moving Average Convergence Divergence (MACD)

Moving averages are the simplest and most common technical


indicators. A moving average is a continuous series of price averages
calculated on a set of data which are updated periodically through the
elimination of the oldest data and the introduction of the most recent one.
The calculation is usually made on the close price.

The calculation of the average can be done in different ways; the most
used are the simple one, the weighted one and the exponential one.
Moving Averages
It is important to notice that with the simple calculation, each data is
equally weighed while in the weighted and exponential calculation, the
most recent data are more relevant.
Simple moving average:

Σ Pt-i / n where:

Pt-i = close price at t-1

n = number of periods

Simple moving averages are the most widely used due to their easy
calculation. However, from a practical point of view, the weighted and
exponential ones give superior results.
Moving Averages
FTSEMIB daily

28500
Simple moving average
Weighted moving average 28000

Exponential moving average 27500

n = 65 27000

26500

26000

25500

25000

24500

September October November December 2004 February

Figure 2
Moving Averages
A moving average is by construction below the prices when they
rise and above them when they decline and tends to act as a bullish
or bearish trendline.

The most used trading rule is to buy when the close price crosses
the moving average coming from below and to sell when the close
price crosses the moving average coming from above.
The rationale behind this operating methodology is quite simple. In case
of a purchase, if the prices continue to rise, the average will remain
below, and our position will continue to generate profits until an opposite
signal occurs.
The analyst has also to set the periodicity of the average.
The lower the periodicity (5, 7, 10), the closer the average will be to the
price chart and the higher will be the number of signals as the probability
of intersections is very high.
The higher the periodicity (65, 120, 200), the farther the average will be
to the price chart and the lower will be the number of signals as the
probability of intersections is very low.
The greater the number of signals, the greater the probability that they
are incorrect.
Moving Averages
S&P500 weekly

20 periods Exponential moving average 1350

1300

1250
Trading Range
1200

1150
Uptrend
1100

1050

1000

950
Downtrend

900

850

800
Trading Range
750

A S O N D 2002 A M J J A S O N D 2003 M A M J J A S O N D 2004 M A

Figure 3
Moving Average Convergence Divergence
The Moving Average Convergence Divergence (MACD) is an extremely
interesting trend indicator that refers, as its name also suggests, to
moving averages.

The basic idea is to try to improve the indications of moving averages


trying to reduce false or wrong signals as much as possible.

What do we mean with reducing false or wrong signals?

Avoid as much as possible signals during trading ranges, but also avoid
those signals that occur during trends that bring to a loss simply because
the moving average is too close to the price chart. At this regard, please
have a look at the points indicated with the letters A and B of figure 1 of
this presentation.

The idea of the MACD is to use two moving averages instead of the price
and one moving average to generate buy and sell signals.
Moving Average Convergence Divergence
This is the same chart of figure 1 but the price has been
replaced with another moving average.
27500

12 periods exponential moving average


B 27000

20 periods exponential moving average


26500

26000

25500

A
25000

August September October November December 2004 February


Figure 4
Moving Average Convergence Divergence
The calculation of the MACD is simply the difference in each period
between the faster moving average and the slower.
Exponential moving average 1 (with n periodicity) minus Exponential
moving average 2 (with m periodicity)
Where n < m
The MACD is usually displayed in a dedicated window below the price
chart as it requires a dedicated scale. The MACD will assume positive or
negative values ​depending on the position of the two averages. When
the MACD moves from negative to positive values, the faster average is
crossing the slower one from below and therefore a buy signal occurs.
Similarly, when the MACD goes from positive to negative values, the
faster average is crossing the slower one from above and therefore a sell
signal occurs.
The choice of (n) and (m) is at the discretion of the analyst. The most
used values ​are (n) = 12 and (m) = 26 but there are many other
combinations that work very well. The MACD is a very famous indicator
which in the long run gives good results even if always with great delay,
a characteristic which however is typical of all trend following indicators.
Moving Average Convergence Divergence
MIBTEL weekly
12 periods exponential moving average
SELL 26 periods exponential moving average 35000

30000
Wrong or false signal
25000

BUY 20000

15000

2500
2000
1500
Wrong or false signal
1000
500
0
-500
-1000
-1500
MACD
-2000
2000 2001 2002 2003 2004
Figure 5
Momentum Oscillators (Leading Indicators)
Momentum oscillators are, differently from trend following indicators,
instruments that work very well during trading ranges when prices move
sideways providing instead incorrect signals during bullish or bearish
trends.

Momentum oscillators usually generate signals very near to the most


recent low (in case of a buy signal) or high (in case of a sell signal) and
for this reason are also called Leading indicators.

In addition to the above there is another very important thing to


remember when using momentum oscillators instead of trend following
indicators. At each buy signal do not necessary correspond a
subsequent sell signal as these algorithms can generate consecutive buy
and sell signals.
The Momentum Oscillators we will discuss in this document are:

Stochastic Oscillator

Moving Average Convergence Divergence Trading Method (MACDTM)


Stochastic - definition

The Stochastic process was created by George Lane many years ago
but only in the 1980s was considered in the context of the Algorithmic
technical analysis. A very easy definition of the Stochastic oscillator
is the following; it measures, on a percentage basis from 0 to 100,
the relation of the last close price with the price range of a past
number of periods.

The calculation is the following:

Stochastict (%Kt) : 100 • [ ( Pt – LL ) / ( HHt – LLt ) where:

Pt = last close

HHt = Higher High of the last n periods

LLt = Lowest Low of the last n periods


Stochastic - calculation
How to calculate a 5 periods Stochastic:
Date High Low Close
1 21.5 20.0 20.6
2 21.1 20.4 21.1
3 22.7 22.2 22.3
4 22.4 21.6 21.8
5 21.7 20.6 20.9 Stocastico : 100 • [ ( 20.9 – 20.0 ) / ( 22.7 – 20.0 ) = 33.33
6 21.8 21.3 21.5 Stocastico : 100 • [ ( 21.5 – 20.4 ) / ( 22.7 – 20.4 ) = 47.82
7 21.4 20.8 21.2 Stocastico : 100 • [ ( 21.2 – 20.6 ) / ( 22.7 – 20.6 ) = 28.57
8 22.0 21.2 22 Stocastico : 100 • [ ( 22.0 – 20.6 ) / ( 22.4 – 20.6 ) = 77.77

The Stochastic calculated in this way is called %K and is a very


volatile oscillator that moves quickly up and down within its
oscillation range (0-100). Even calculated over higher periods such as
10 or 20, his behavior remains always “erratic". We can therefore
consider the %K as the fastest among the Leading Indicators, but very
often brings the analyst to wrong indications.
Stochastic - %K
Stoxx50 weekly
5 periods %K 2750
10 periods %K 2700
20 periods %K 2650
2600
2550
2500
2450

2400

2350

50

50

50

July August September October November December 2004 February

Figure 6
Stochastic – from %K to %D

In order to reduce the erratic behavior of the %K, it’s considered a good
idea to slow down the movement of %K elaborating a new algorithm that
could simply be a moving average of the %K.

This slower version of the Stochastic is called %D. In general, when


technical analysts speak about the Stochastic oscillator, they refer to the
%D.

The choice of the period to calculate the average is at the discretion of


the analyst as well as the choice of the periods to be used in the formula
of the %K. With reference to the average, the most used value is 3. As
regards the second variable, the value most frequently used is 10 or 14.
Stochastic – interpretation

When we speak about the stochastic oscillator it is important to


understand what overbought and oversold areas are. The overbought
area is an area placed at high values ​on the stochastic chart (above
70/80). In the same way, the oversold area is an area placed at low
values ​on the indicator chart (below 20/30).

When the stochastic enters one of these areas, the price is subject to a
possible reversal, bearish if it is in the overbought area and bullish if it is
in the oversold area.

However, since the stochastic can remain in the overbought or oversold


area even for several periods, a buy signal occurs only when the
stochastic leaves the oversold area and a sell signal occurs only when
the stochastic leaves the overbought area.
Stochastic – overbought and oversold areas
100

Overbought area Sell signal

80

%D

20

Oversold area
Buy signals
0
Figure 7
Stochastic – divergences
When analyzing the chart of the Stochastic oscillator in overbought or
oversold areas, it can be useful to detect possible divergences with the
price chart.

A negative divergence occurs when the price chart is in an uptrend


generating increasing highs with the Stochastic which instead presents
decreasing highs. On the contrary, there is a positive divergence when
the price chart is in a downtrend, generating decreasing lows with the
indicator which instead presents increasing lows.

In these cases, the correct interpretation is the following:

liquidate bullish positions (and evaluate the opening of bearish positions)


in the presence of a negative divergence;

liquidate bearish positions (and evaluate the opening of bullish positions)


in the presence of a positive divergence.
Stochastic – divergences
Stoxx50 daily
%K 10 2750
%D 10, 3 2700
%D Slow 10, 3, 3 2650
2600
2550
2500
2450
2400
2350

50

50

50

July August September October November December 2004 February

Figure 8
Momentum Oscillators – The MACDTM
When we speak about Moving Average Convergence Divergence
Trading Method (MACDTM) we are referring not to a real indicator but to
a different interpretation of the MACD, already discussed in the section
dedicated to Trend Following indicators.

The MACD chart is in this case enriched with a second slower line which
is a (n) period average of the MACD itself. Usually (n) takes the value of
9. This second line is called Trigger Line

The trading rule behind the MACDTM is very simple. A buy signal occurs
when the MACD breaks the Trigger Line from the bottom and a sell
signal occurs when the MACD breaks it from the top.

Using this type of interpretation, the signal is significantly speeded up


and therefore the MACD becomes from a Trend Following Indicator, or
Lagging Indicator, a real Leading Indicator, or Momentum Indicator. What
are the benefits of using MACDTM instead of other Momentum
indicators? Every buy signal always corresponds a subsequent sell
signal which is a characteristic of signals based on moving averages.
Momentum Oscillators – The MACDTM

Sell Signal 35000

30000
Buy Signal
25000

20000

15000

2500
2000
1500
1000
500
0
-500
MACD -1000
-1500
Trigger Line -2000

2000 2001 2002 2003 2004


Figure 9

You might also like