STAY IN PHASE
by
John
Ehlers
Source: MESA Software Technical Papers
INTRODUCTION
A Cycle is the one market
characteristic that can be scientifically measured. Although they can be measured they are maddening because they are
ephemeral - they come and go. Our
recent research shows there is a fundamental cycle parameter that leads us to
the correct trading strategy for any current market mode. We start by defining two possible market
modes. These modes are the Trend Mode
and the Cycle Mode. In the Trend Mode
the correct strategy is to buy (or sell, for down trends) and hold. In the Cycle Mode the correct strategy is to
buy and sell on the cyclic valleys and peaks.
The parameter we use is the phase of
the cycle. The measured phase tells us
with great sensitivity when we are in the Trend Mode, enabling the capture of a
large fraction of the trend movement.
This capture range is typically far larger than can be obtained with
crossing moving average or other typical trend identification techniques. In the Cycle Mode the measured phase
pinpoints the cyclic turns IN ADVANCE, with the further advantage that the
false whipsaw signals of typical "oscillator" type signals are avoided.
THE NATURE OF PHASE
To use phase, we must first understand
what it is. It, quite simply, is a
description of where we are in the cycle.
Are we at the beginning, middle, or end of the cycle? Phase is a quantitative description of that
location. Each cycle passes through 360
degrees to complete the cycle. One
basic definition of a cycle is that it consists of an action having a uniform
rate-change of phase. For example, a 10
day cycle passes through 360 degrees every 10 days. For a perfect cycle it must change phase at the rate of 36
degrees per day each day throughout the cycle.
How does this help us see a Trend
Mode? Easy. By reverse logic. In a
Trend Mode there is no cycle, or at least a very weak one. Therefore there is no rate change of
phase. So, if we compare the rate
change of measured phase to the theoretical rate change of phase of the weak
dominant cycle present in the Trend Mode, we get a correlation failure. This failure to correlate the two cases of
the rate change of phase enables us to define the presence of a trend. Knowing we have a trend, it is easy to set
our strategy to a simple buy-and-hold until the trend disappears.
Figure
1. Phase describes the location within
a cycle
Figure 2. A sinewave in the time domain can be
generated by placing a pen on the arrowhead and drawing the paper along at a
uniform rate, just like a seismograph.
Figure
3. Phase varies uniformly throughout
the cycle, and is drawn as reset to show the beginning of a new cycle
One easy way to picture a cycle is as
an indicator arrow bolted to a rotating shaft as shown in the phasor diagram of
Figure 1. Each time the arrowhead
sweeps through one complete rotation a cycle is completed. The phase increases uniformly throughout the
cycle as shown in Figure 2. The phase
continues on for the next cycle, but is usually drawn as being reset to zero to
start the next cycle. If we
additionally place a pen on the arrowhead and draw a sheet of paper below the arrowhead at a uniform rate, like
they do for seismographs, the pen draws a theoretical sinewave. The relationship between the phasor diagram
and the theoretical sinewave is shown in Figure 3. The sinewave is the typical cycle waveform we recognize in the
time domain on our charts. The phase
angle of the arrow uniquely describes where we are in the time domain waveform.
The position of the tip of the arrow
in Figure 1 can be described in terms of the length of the arrow, L, and the
phase angle, q.
If we let the arrow be the hypotenuse of a right triangle we can convert
the description of the arrow from length and angle to two orthogonal components
- the other two legs of the right triangle.
The vertical component is L*Sin(q) and the
horizontal component is L*Cos(q).
The ratio of these two components is the tangent of the phase
angle. So, if we know the two
components, all we have to do to find the phase angle is to take the arctangent
of their ratio. This is something that
may be tough for you, but it's a piece of cake for your computer.
We measure the phase of the dominant
cycle by establishing the average lengths of the two orthogonal
components. This is done by correlating
the data over one fully cycle period against the sine and cosine functions. Once the two orthogonal components are
measured, the phase angle is established by taking the tangent of their
ratio. A simple test is to assume the
price function is a perfect sinewave, or Sin(q). The vertical component would be Sin2(q)
= .5*(1-Cos(2q)) taken over the full cycle. The Cos(2q) term
averages to zero, with the result that the correlation has an amplitude of
Pi. The horizontal component is Sin(q)*Cos(q)
= .5*Sin(2q).
This term averages to zero over the full cycle, with the result that
there is no horizontal component. The
ratio of the two components goes to infinity because we are dividing by zero,
and the arctangent is therefore 90 degrees.
This means the arrow is pointing straight up, right at the peak of the
sinewave.
One additional step in our
calculations is required to clear the ambiguity of the tangent function. In the first quadrant both the sine and
cosine have positive polarity. In the second
quadrant the sine is positive and the cosine is negative. In the third quadrant both are
negative. Finally, in the fourth
quadrant the sine is negative and the cosine is positive. The phase angle is obtained regardless of
the amplitude of the cycle. Given that
we know the dominant cycle, the BASIC program in the sidebar shows how we can
compute the phase angle.
PUTTING THE PHASE TO WORK
Figure 4a. Plotting the sine of the measured
phase angle
Figure 4b. Sinewave Indicator is created by
advancing the measured phase by 45 degrees.
We can make an outstanding cyclic
indicator simply by plotting the Sine of the measured phase angle. When we are in a Cycle Mode this indicator
looks very much like a sinewave. When
we are in a Trend Mode the Sine of the measured phase angle tends to wander
around slowly because there is only an incidental rate change of phase. A clear, unequivocal indicator can be
generated by plotting the Sine of the measured phase angle advanced by 45 degrees. This case is depicted for the phasor diagram
and the time domain in Figure 4b. The
two lines cross SHORTLY BEFORE the peaks and valleys of the cyclic turning
points, enabling you to make your trading decision in time to profit from the
entire amplitude swing of the cycle. A
significant additional advantage is that the two indicator lines don't cross
except at cyclic turning points, avoiding the false whipsaw signals of most
"oscillators" when the market is in a Trend Mode. The two lines don't cross because the phase rate of change is
nearly zero in a trend mode. Since the
phase is not changing, the two lines separated by 45 degrees in phase never get
the opportunity to cross.
If the rate of change of the measured
phase does not correlate with the theoretical phase rate-change of the dominant
cycle, then a Trend must be in force. A
workable definition is a Trend exists when the measured phase rate of change is
less than 67% of the theoretical phase rate of the dominant cycle. This is a very sensitive detector for the
Trend Mode, enabling you to capture high percentages of the Trend movement.
REAL WORLD EXAMPLES
Theory is nice, and is always how I
initially attack each trading problem.
It is possible for theory to be a laboratory curiosity with no practical
application. Happily, this is not the
case for the use of phase in trading.
Figure 5. Cycle and Phase Response of
September 1996 Deutschemark
Figure 5 is a MESA96 display for the
September 96 Deutschemark contract. The
price bars are displayed in the top segment with two adaptive moving average
overlays. The second segment is the
Sinewave Indicator, plots of the Sine of the measured phase angle and the phase
angle advanced by 45 degrees. The
measured phase is displayed below the Sinewave Indicator, and the measured
dominant cycle and spectrum are displayed in the bottom segment.
From the way the phase varied
uniformly in March, it is clear that DM was in the Cycle Mode during that
month. As a result, the Sinewave
Indicator looks like a sinewave and gives two buy and one sell signal where the
Sinewave Indicator lines cross.
The phase stopped changing at a
uniform rate in April and May because two cycles identified by the spectrum
display were present simultaneously.
Since the phase hardly changed from day to day, DM went into a Trend Mode
during these two months. The trend mode
is identified, in TradeStation lingo, by "PaintBars", where the price bars are
violet. The correct trading strategy
during April and May was to hold a short position (a move worth over $2500 per
contract) because the faster adaptive moving average was below the slower
one. Another way to identify the
downtrend is that the phase remained near zero degrees (or near 360 degrees)
during these two months. Notice that
the Sinewave Indicator does not give false whipsaw signals during April and
May. Whipsaws in the Trend Mode are
common for "oscillator" indicators such as the Stochastic and RSI.
The phase resumed its uniform rate of
change during June and into July because the dominant cycle settled down to a
relatively stationary value. As a
result, the Cycle Mode appeared, the Sinewave Indicator again looks like a
sinewave, and four excellent sell signals and three excellent buy signals
resulted.
Figure
6. Cycle and Phase Response of
September 1996 Treasury Bonds
Figure 6, showing the cycle and phase
response of the September contract of US Treasury Bonds, is another example of
how phase can be used to sharpen your trading.
In February and March, Bonds were in a decline. The phase hovered near zero degrees, clearly
identifying the downtrend. The correct
trading strategy during this period was to hold a short position until the
first cyclic buy signal given by the Sinewave Indicator early in April. From that first cyclic buy signal there were
three more cyclic buy signals and three cyclic sell signals in the ensuing
three months. Bonds didn't stay
exclusively in the Cycle Mode during all that time because the cycle length
tended to wander around. However, the
cycle wandering only introduced distortions in the shape of the Sinewave
Indicator. The crossover signals it
produced unequivocal and would have produced substantial profits in every case.
CONCLUSION
Phase is an exciting new parameter to
help technicians analyze the market. It
can help in several regards. First, it
enables you to establish your trading strategy to fit the Trend Mode in the
Cycle Mode. If you are not comfortable
trading the Cycle Mode, you can always stand aside for a while until a new
Trend Mode is established. If you want
to trade the Cycle Mode, the Sinewave Indicator, created by plotting the Sine
of the phase angle and the Sine of the phase angle advanced by 45 degrees,
gives clear buy and sell signals in advance of each cyclic turn. Getting the signal in advance enables you to
make your entry and exit right at the cyclic turning point without giving up a
piece of the market movement. The
measured phase, Trend Mode identification, and Sinewave Indicator are all part
of the MESA96 trading software program.
SIDEBAR
BASIC
Code for Phase Calculation
This BASIC code finds the real part of
the phasor (the horizontal component) and the imaginary part of the phasor (the
vertical component) by summing the product of the price and the two sinusoids
over one full cycle of the dominant cycle.
The arctangent function locates the phase to be in the first or fourth
quadrant. The quadrant ambiguity is
removed by adding p to the phase angle is the real part is
negative. A value of p/2
is arbitrarily added to the computed phase so the start of the cycle is
referenced to a Sine wave. The computed
phase angle is then tested to fall within the range from 0 to 2p. The phase is then converted to degrees from
radian measure.
An interesting observation is that if
the price is a linear slope, summing the product of the price and a sine over a
cycle is the discrete equivalent of the integral ò x
Sin(x) dx. Correspondingly, the real
part is the equivalent of the integral ò x Cos(x)
dx. Working through these theoretical
examples, we find that the phase is 180 degrees for a trending upslope and is
zero degrees for a trending downslope.
Thus, phase can be a sensitive way to detect a Trend.
Pi=3.1415926
TwoPi=2*Pi
For I=FirstRecord to LastRecord
RealPart = 0
ImagPart = 0
For J = 0 To DominantCycle(I) - 1
If I > DominantCycle(I) Then Weight = Close(I - J)
RealPart = RealPart + Cos(TwoPi * J / DominantCycle(I)) * Weight
ImagPart = ImagPart + Sin(TwoPi * J / DominantCycle(I)) * Weight
Next
If Abs(RealPart) > .001 Then
Phase(I) = Atn(ImagPart / RealPart)
Else
Phase(I) = Pi / 2 * Sgn(ImagPart)
End If
If RealPart < 0 Then Phase(I) = Phase(I) + Pi
Phase(I) = Phase(I) + Pi / 2
If Phase(I) < 0 Then Phase(I) = Phase(I) + TwoPi
If Phase(I) > TwoPi Then Phase(I) = Phase(I) - TwoPi
Phase(I) = 180 * Phase(I) / Pi
Next