Sub topic 2
Peaks, Troughs, and Trends
Assumed background
This chapter assumes you know what a stock market index is, as covered in the previous chapter. It also assumes you can work with percentages. The code is optional, but it runs as written in any recent Python 3.
The terms bull market, correction, and bear market all describe movements between turning points in a price series. To use those terms precisely, you first need a clear definition of a turning point and a trend.
Peaks and troughs
A peak is a local high. It is a price that is higher than the prices around it. A trough is a local low, a price lower than the prices around it. A price series rarely moves in a straight line. It rises to a peak, falls to a trough, then rises again, and so on.
Two points about this definition matter in practice.
- "Around it" needs a size. A price can be the highest in the last 3 days, the last 3 months, or the last 3 years. Each choice gives a different set of peaks. There is no single correct set.
- The label depends on the price you use. Daily closing prices are the usual choice for index charts. Intraday highs and lows give slightly different peaks and troughs. Indexes also differ on whether dividends are included. Say which series you use before comparing results.
An all-time high is the highest value a series has ever reached. It is a peak by definition, but most peaks are not all-time highs.
What a trend is
A trend is the general direction of prices over a stretch of time. Analysts use two common ways to describe one.
- Sequence of peaks and troughs. An uptrend has higher highs and higher lows. Each peak is above the last one, and each pullback stops above the previous trough. A downtrend has lower highs and lower lows. This is the core idea of Dow theory, an older school of market analysis.
- Moving averages. A moving average replaces each price with the average of the last N prices, which smooths out day-to-day noise. Two widely watched versions use 50 and 200 trading days. Prices above a rising 200-day average are often called an uptrend. Prices below a falling one are often called a downtrend.
Trends exist at several scales at once. A market can be in a multi-year uptrend, a three-month downtrend inside it, and a one-week bounce inside that. When someone says "the trend," ask which time scale they mean.
A trend describes the past. A rising series is not guaranteed to keep rising. The terms bull market and bear market are built on this idea of trend, but they add specific size and duration conventions. Later chapters cover those.
The zigzag view of a price series
If you ignore small moves and keep only the large swings, a price series becomes a zigzag of rises and falls. The following diagram shows the logic for building that zigzag. The series is always in one of three states, and a reversal of at least a chosen size moves it between them.
The key rule is that a turning point is confirmed only after price has moved away from it by the threshold. The peak itself happened earlier, on the day of the high. You only know it was a peak later.
Finding turning points in code
The function below follows the diagram. It returns each confirmed peak or trough, along with the index of the day on which it was confirmed.
def find_turning_points(prices, threshold=0.10):
"""Return (index, kind, confirmed_at) for each confirmed peak or trough.
A turning point is confirmed once price reverses by `threshold`
(a fraction, 0.10 = 10%) from the extreme.
"""
points = []
direction = None # None, "up", or "down"
hi_i = lo_i = 0 # index of the highest / lowest price seen in the current leg
for i in range(1, len(prices)):
p = prices[i]
if direction is None:
if p > prices[hi_i]:
hi_i = i
if p < prices[lo_i]:
lo_i = i
if p <= prices[hi_i] * (1 - threshold):
points.append((hi_i, "peak", i))
direction, lo_i = "down", i
elif p >= prices[lo_i] * (1 + threshold):
points.append((lo_i, "trough", i))
direction, hi_i = "up", i
elif direction == "up":
if p > prices[hi_i]:
hi_i = i
elif p <= prices[hi_i] * (1 - threshold):
points.append((hi_i, "peak", i))
direction, lo_i = "down", i
else:
if p < prices[lo_i]:
lo_i = i
elif p >= prices[lo_i] * (1 + threshold):
points.append((lo_i, "trough", i))
direction, hi_i = "up", i
return points
prices = [100, 104, 112, 108, 98, 94, 99, 106, 115, 121, 113, 109, 111]
for idx, kind, seen in find_turning_points(prices, 0.10):
print(f"{kind:6} at day {idx:2} (price {prices[idx]}), confirmed on day {seen}")
print("highest price so far:", max(prices), "on day", prices.index(max(prices)))Running it prints:
trough at day 0 (price 100), confirmed on day 2
peak at day 2 (price 112), confirmed on day 4
trough at day 5 (price 94), confirmed on day 7
highest price so far: 121 on day 9Read the output carefully.
- The first "trough" is only the starting price. With no earlier data, the function treats the first low as a trough once a 10% rise confirms it.
- The peak at 112 happened on day 2 but was not confirmed until day 4. The delay is two days here. In real markets it can be weeks or months.
- The price of 121 on day 9 is the highest in the series, but it is not reported as a peak. Prices fell to 109, which is only 9.9% below 121, short of the 10% threshold. The function cannot yet say whether day 9 was a peak or just a pause in a continuing rise.
That last point is the main lesson of this chapter.
The cost of the threshold
The reversal threshold controls how many swings you see. It is a trade-off between noise and delay.
| Threshold | Turning points found | Delay before each is confirmed | Main risk |
|---|---|---|---|
| Small (about 3%) | Many | Short | Noise: ordinary daily wobble counts as a swing |
| Medium (about 10%) | Fewer | Moderate | Misses smaller reversals |
| Large (about 20%) | Few | Long | Confirms a turn only after much of the move is over |
No threshold removes the trade-off. A small one gives early signals that are often false. A large one gives reliable signals that arrive late. This is why the 10% and 20% conventions you will meet in later chapters are conventions, not natural boundaries.
Hindsight and confirmation lag
On a finished chart, peaks and troughs look obvious. Live, they are not. The highest price so far is only a candidate. It becomes a peak when prices later fall, and how far they must fall depends on your rule. The same holds for troughs.
Two consequences follow.
- Any rule that depends on turning points is delayed. To say a peak occurred, you need data that arrives after the peak. Statements such as "the market peaked in month X" are made afterward.
- Different rules disagree. Two analysts using different thresholds or time windows can label the same day differently, and both can be internally consistent.
Common errors
- Reading a chart on a linear scale for long periods. A move from 1,000 to 2,000 and a move from 2,000 to 4,000 are both a 100% gain, but a linear axis shows the second as twice as tall. A logarithmic scale draws equal percentage moves as equal heights. Use it for multi-year charts.
- Mixing time scales. Calling a three-day drop "a downtrend" and a ten-year rise "an uptrend" in the same sentence describes different things.
- Treating a trend as a forecast. A trend summarizes what has happened. Streaks do end, and the series offers no signal of when.
- Counting from the wrong peak. The size of a decline depends on which peak you measure from. The next chapter uses the running peak, the highest price seen so far, as the reference.
- Comparing results across different price series. Price-only and total-return indexes have different peaks and troughs, and so do closing and intraday prices.
Where this leads
Once you can identify peaks and troughs, you can measure the distance between them. The next chapter turns that into drawdown, the percentage fall from a peak, and shows why recovering from a decline takes a larger gain than the loss itself. The labels bull market, correction, and bear market then become thresholds applied to those measurements.
Exercise
A price series is [50, 56, 52, 47, 51, 58] and the reversal threshold is 10%. After the first rise confirms an uptrend, on which day (counting the first price as day 0) is the peak at 56 confirmed, and what is the fall from 56 on that day? Why is it not confirmed on day 2?
Show answer
The peak is confirmed on day 3. The price that day is 47, and 47 / 56 - 1 is about -16.1%, which is beyond the 10% threshold. On day 2 the price is 52, only about 7.1% below 56 (52 / 56 - 1), so the fall is too small to confirm a peak.
Exercise
Why does lowering the threshold from 10% to 3% produce earlier signals but make them less trustworthy?
Show answer
A 3% reversal happens after only a small move, so it is confirmed sooner. Ordinary day-to-day fluctuations also reach 3% often, so many of these reversals are noise and the price carries on in its original direction. A 10% threshold filters out more noise but confirms a turn later.