Just about any book on technical analysis you open will have a number of charts showing the usual peaks and valleys of a instrument's trading range. Many trading strategies are designed around the specific arrangement of peaks and valleys. I thought, up till now, that these peaks and valleys could only be determined through studies through the use of the good old Mark I Eyeball.
However, after reading Bollinger's book entitled Bollinger on Bollinger Bands, in which he
discusses
computer aided determination of those peaks and valleys, I set out to work on an algorithm to do
the same.
The C# PeakMatch Code Segment is
my first attempt at peak and valley pattern matching.
It is implemented as a state machine in order to make it easy to determine, during live streams,
whether the stream is going up or down. You can use various summary statistics from quotes, trades,
or even bars as input values.
The variable dblPatternDelta is the grey zone used for determining when the pattern flips. This
variable will need to be adjusted on an instrument by instrument basis. In addition, further tuning
is necessary if you wish to capture small nuances or just large swings in the trading value. As
such, determining the peak is a problem of lag. Sigh, so much for having a magical realtime
signal for
determining when the top or bottom of a range. The variable dtPatternPt1 holds the DateTime of
the last
determined peak. When a change of direction of determined, then that peak/valley attribute is
stored in dsPattern.
dsPattern can then be used within a sliding window of pattern analysis. I'll show an
implementation of
Arthur Merrill's patterns in another article.
Further information on choosing a good value for dblPatternDelta can be found in Bollinger's
book.