You are on page 1of 9

Winner Winner...

MetaStock D/C • Winner • Trading Software $500 - $1000


Bollinger Band System • Winner • Plug-ins
Metastock R/T •1st Runner Up • Software over $1,000
XENITH • Finalist • Real-Time Market Data
Dr. Elders Trading Room • Finalist • Plug-ins
Bollinger Band Toolkit • Honorable Mention • Plug-ins

Get a FREE trial of MetaStock with Market Data!*


Visit MetaStock.com/TASC.
*restrictions apply. See metastock.com/tasc for details.
The trading platform you’d build
(if you built trading platforms).
Customize your view of the market so you can focus on what’s important to you with thinkorswim®.
Create your own indicators with thinkScript®, visualize the market with custom charting, and use
personal predictions to forecast the values of stocks you care about with the Company Profile tool.
And, this award-winning investing experience is now commission-free.*
See what customization can do for your trades at tdameritrade.com/thinkorswim

*Applies to U.S. exchange-listed stocks, ETFs, and options. A $0.65 per contract fee applies for options trades.
Company Profile forecasts are hypothetical, based on user-defined assumptions, and not guaranteed. All investing involves risks, including loss of
principal. TD Ameritrade, Inc., member FINRA/SIPC. © 2019 TD Ameritrade.
Stocks & Commodities V. 28:6 (16-20): Fractal Dimension As A Market Mode Sensor by John F. Ehlers and Ric Way
TRADING SYSTEMS

Cycle Or Trend?

Fractal Dimension As
A Market Mode Sensor
You can use the fractal dimension as a natural way be defined by the fractal dimension that describes
to sense whether the market is in a cycle mode or sparseness at all magnification levels.
trend mode. To determine the fractal dimension of a generalized
pattern, we cover the pattern with a number N of small

Is
objects of several various sizes S. The relationship
the market trending or cycling? What in- of the number of objects in two sets of sizes is:
tuitively seems like an easy question to
answer is perhaps one of the most vexing in N2 S1 D
=
N1 S2
all technical analysis. If a trader knows the market
mode, then a straightforward approach could be log
N2
taken to adapt a trading strategy to that mode. We N1
D=
would apply a swing trading technique such as an S1
log
S2
overbought/oversold oscillator in cycle mode and a
trend-following technique such as a moving average As an example, we can start with a pattern that is a
crossing in trend mode. In this article, we address the line segment 10 meters long. We chose the two small
cycle/trend problem using the fractal dimension. dimensions as S1 = one meter and S2 = 0.1 meter.
A number of tools have been developed to differ- Placing boxes along the line, we can fit 10 one-meter
entiate between cycle and trend modes. For example, boxes on the segment, and therefore N1 = 10. Simi-
we can compare the trend slope over a full cycle larly, we can fit 100 0.1-meter boxes on the same 10
period to the amplitude swing of the cycle and use one-meter line segment, and therefore, N2 = 100. The
the ratio. More recently, we developed empirical fractal dimension of the line then computes to:
mode decomposition to separate the market into cycle
and trend mode components. In this article, we will 100
log
10
consider the fractal dimension as a natural way to D= = 1.0
1
determine whether the market is in a cycle mode or log
0.1
trend mode.
As a second example, we will use the pattern as a
Fractal dimension square that is 10 meters on a side instead of a line seg-
There is no argument that market prices are fractal. ment. Retaining the same sizes of our small boxes as
Price charts look similar regardless of time frame. If one meter and 0.1 meter on a side, respectively, we get
you remove the labels from a five-minute chart, a daily N1 = 100 and N2 = 10,000. When the square is our pat-
chart, and a weekly chart, you would have difficulty tern, the fractal dimension therefore computes to be:
telling them apart. Fractal shapes are self-similar be-
10000
cause they have the same roughness and sparseness log
100
regardless of time interval. This self-similarity can D= = 2.0
1
log
0.1

by John F. Ehlers and Ric Way
Copyright (c) Technical Analysis Inc.
WILLIAM L BROWN
Stocks & Commodities V. 28:6 (16-20): Fractal Dimension As A Market Mode Sensor by John F. Ehlers and Ric Way

Copyright (c) Technical Analysis Inc.


Stocks & Commodities V. 28:6 (16-20): Fractal Dimension As A Market Mode Sensor by John F. Ehlers and Ric Way
TRADING SYSTEMS
FRACTAL DIMENSION INDICATOR IN EASYLANGUAGE
Inputs: Price((H + L)/2),
N(30); {N must be an even number} T, divided by T. Similarly, N2 = (HighestPrice – LowestPrice)
is over the interval from T to 2T, divided by T. We also define
Vars: Smooth(0), a N3 = (HighestPrice – LowestPrice) over the entire interval
count(0), from zero to 2T, divided by 2T. Since we are looking backward
N1(0),
in time, the slope computation of the fractal dimension is:
N2(0),
N3(0),
HH(0), log N1 + N2 – log N3
LL(0), D=
Ratio(0), log 2
Dimen(0);
The fractal dimension varies over the range from D = 1 to
Smooth = (Price + 2*Price[1] + 2*Price[2] + Price[3]) / 6;
D = 2. When D = 1 prices are in a straight line — that is, the
N3 = (Highest(Smooth, N) - Lowest(Smooth, N)) / N;
HH = Smooth;
market is in a trend mode — the trend can be up, down, or
LL = Smooth; sideways because the fractal dimension has no sense of slope.
For count = 0 to N / 2 - 1 begin When D = 2, the prices are swinging up and down within the
If Smooth[count] > HH then HH = Smooth[count]; box over the observation period; in other words, the market is
If Smooth[count] < LL then LL = Smooth[count]; in a cycle mode. When D = 1.5, we have the boundary between
End; being in a trend mode or cycle mode. Since the measurement of
N1 = (HH - LL) / (N / 2); the fractal dimension is only an estimate, there is no clear-cut,
HH = Smooth[N / 2]; black & white distinction between trend mode or cycle mode
LL = Smooth[N / 2];
at the boundary. Thus, we choose to plot a “fuzzy” boundary
For count = N / 2 to N - 1 begin
If Smooth[count] > HH then HH = Smooth[count];
extending from D = 1.4 to D = 1.6 within that range.
If Smooth[count] < LL then LL = Smooth[count];
End;
N2 = (HH - LL)/(N / 2); The fractal dimension indicator
If N1 > 0 and N2 > 0 and N3 > 0 then Ratio = .5*((Log(N1 The EasyLanguage code to compute the fractal dimension indi-
+ N2) - Log(N3)) / Log(2) + Dimen[1]); cator is given in the sidebar “Fractal Dimension Indicator.” We
Dimen = Average(Ratio, 20); choose to use the average of the high and low prices to compute
Plot1(Dimen); a line indicator (price) because this average is smoother than the
Plot2(1.6, “1.6”, Blue);
closing price alone with respect to high-frequency components.
Plot3(1.4, “1.4”, Blue);
We then smooth price using a four-tap finite impulse response
(Fir) filter to entirely notch out the two- and three-bar cycle
A perfect square represents an idealized geometry not found components. A Fir filter is similar to a moving average except
in nature. Natural fractals like that of a seashore lack the true that the selected coefficients enable the elimination of the un-
regularity of an algorithmic structure but are self-similar in a desired two- and three-bar period cycle components.
statistical sense. Thus, in order to determine the fractal dimen- The computation of N1, N2, and N3 are as previously
sion of natural shapes, we must average the measured fractal described. We then smooth the ratio using a 20-bar moving
dimension made over different scales. average to create the resulting fractal dimension indicator. The
We could measure the fractal dimension of prices by cover- length of the moving average is somewhat arbitrary, with 20
ing the curve with a series of small boxes. This is burdensome, being a good match for the default input setting of N = 30. The
but if we take into account that the price samples are uniformly indicator is plotted as Plot1, with the fuzzy boundaries plotted
spaced, the box count is approximately the average slope of as Plot2 and Plot3.
the curve. Therefore, we can estimate the box count as the
highest price during an interval minus the lowest price during The fractal dimension in action
that interval, divided by the length of the interval itself. The The fractal dimension indicator is applied to approximately one
equation for the number of boxes is then: year of data of Microsoft Corp. (Msft) in Figure 1. The indicator
shows that Msft is in a trend from mid-July 2008 until January
HighestPrice – LowestPrice 2009. From the slope of the data, this is clearly a downtrend.
N1 = Between January and mid-April 2009, the indicator is in the
Length
fuzzy region and from mid-April it begins another trend. This
time the trend is up, as determined by the slope of the data.
We compute the fractal dimension by computing N over It may be instructive to describe the action of the fractal
two equal intervals to get the averaging over each interval. dimension indicator from a theoretical perspective. In Figure
Interval 1 covers the period from zero to T bars ago. Interval 2, this indicator is applied to a sine wave the period of which is
2 covers the period from T to 2T bars ago. Therefore, N1 = continuously increasing from left to right. The period has been
(HighestPrice – LowestPrice) over the interval from zero to

Copyright (c) Technical Analysis Inc.


Stocks & Commodities V. 28:6 (16-20): Fractal Dimension As A Market Mode Sensor by John F. Ehlers and Ric Way
TRADING SYSTEMS

measured in the bottom subgraph, and


the period is indicated on its vertical
axis. In this case, we have set the input
N = 20. When the cycle period is less
than N, the cycle swings fill the box and
a cycle mode indication results. When
the cycle period is greater than N, the
indicator reads segments of the longer
cycles as trends. This is a reasonable
interpretation of a trend. However,
the prices tend to fill the box near the
peaks and valleys of the longer cycles.
The moving average in the indicator
reduces the excursions of these swings
to improve interpretation of the trend
mode.
MESA SOFTWARE


Trend or cycle?
By its very design, the fractal dimen-
Figure 1: fractal dimension indicator in action. Here you see the fractal dimension indicator applied on the sion is a natural descriptor of trend
chart of Microsoft (MSFT). The indicator shows that MSFT is in a trend from mid-July 2008 until January 2009. From the modes and cycle modes in the market.
slope of the data, this is clearly a downtrend. Between January and mid-April 2009, the indicator is in the fuzzy region,
Its use provides you with another tool
and from mid-April begins another trend. This time the trend is up, as determined by the slope of the data.
to better apply your strategies for ei-
ther swing trading or trend-following
trading.

John Ehlers is a pioneer in the use of


cycles and Dsp techniques in techni-
cal analysis. He is the author of the
Mesa8 program and is the chief sci-
entist for www.isignals.com. Ric Way
is an independent software developer
specializing in programming algorith-
mic trading systems in C#. He may be
reached at ricway@taosgroup.org.

Suggested reading
Ehlers, John F., and Ric Way [2010].
“Empirical Mode Decomposition,”
Technical Analysis of S tocks
& C ommodities , Volume 28:
March.
‡EasyLanguage (TradeStation)
‡Mesa Software

See our Traders’ Tips section beginning on


page 70 for program code implementing
John Ehlers’ technique.
Figure 2: fractal dimension indicator applied to a theoretical sine wave. The period of the sine
wave continuously increases from left to right. The period has been measured in the bottom subgraph, and the period
is indicated on its vertical axis. In this case, we have set the input N = 20. When the cycle period is less than N, the
cycle swings “fill the box” and a cycle mode indication results. When the cycle period is greater than N, the indicator
reads segments of the longer cycles as trends.

Copyright (c) Technical Analysis Inc.


IBKR MARGIN LOAN 1

0.75%
Amount > $1 million
IBKR
and not much higher charges
for smaller amounts
margin loan rates 1

from 0.75% to 1.59%

Start Investing Today! ibkr.com/iwantmore


Interactive Brokers Rated #1
Best Online Broker 2020 by Barron’s*

Trading
Trading on
on margin
margin is
is only
only for
for sophisticated
sophisticated investors
investors with
with
high risk tolerance. You may lose more than your initial investment.
high risk tolerance. You may lose more than your initial investment.
Member - NYSE, FINRA, SIPC – *Interactive Brokers rated #1, Best Online Broker according to Barron’s Best Online Brokers Survey of 2020:
February 21, 2020. For more information see, ibkr.com/info - Barron’s is a registered trademark of Dow Jones & Co. Inc. [1] Margin Loan rate as
of 07/08/2020. IB calculates the interest charged on margin loans using the applicable rates for each interest rate tier listed on its website. Rates
shown apply to IBKR Pro clients only. Rates subject to change. For additional information on margin loan rates, see ibkr.com/interest
10-IB20-1374CH1358
We are honored to be recognized as a
top trading software provider in the
2020 Readers’ Choice Awards.

WINNER: Trading Software > $1000


WINNER: Trading Software < $500
Thank you to all who voted for NinjaTrader’s industry
leading platform & brokerage services.
Futures, foreign currency and options trading contains substantial risk and is not for every
investor. Only risk capital should be used for trading and only those with sufficient risk capital
should consider trading.

ninjatrader.com
subscribe or renew today!
Every Stocks & Commodities subscription
(regular and digital) includes:
• Full access to our Digital Edition
The complete magazine as a PDF you can download.
• Full access to our Digital Archives 8999
1 year.................
$
That’s 35 years’ worth of content!

2 years............ 149
• Complete access to WorkingMoney.com $ 99
The information you need to invest smartly and successfully.

3 years............ 199
• Access to Traders.com Advantage $ 99
Insights, tips and techniques that can help you trade smarter.

PROFESSIONAL TRADERS’ STARTER KIT


A 5-year subscription to S&C magazine that includes
everything above PLUS a free* book, Charting The Stock
Market: The Wyckoff Method, all for a price that saves
you $150 off the year-by-year price! *Shipping & han-
dling charges apply for foreign orders.

5 years..........
$
29999
That’s around $5 a month!

Visit www.Traders.com to find out more!


Email: Circ@Traders.com • Phone: 206-938-0570 facebook.com/STOCKSandCOMMODITIES @STOCKSandCOMM

You might also like