Technical Analysis & Candlestick Patterns: Reading the Market's Body Language
OHLC data, candlestick anatomy, classic patterns like doji and engulfing, support and resistance levels, moving averages, Bollinger Bands, and why technical analysis remains controversial yet widely practiced.
Terminology
| Term | Definition |
|---|---|
| OHLC | Open, High, Low, Close: the four prices recorded for each trading period. Together they summarize all price action within that interval |
| Candlestick | A visual representation of one OHLC period. The thick "body" spans open to close, and thin "wicks" (shadows) extend to the high and low |
| Support Level | A price floor where buying pressure historically prevents further decline. Prices tend to "bounce" off support |
| Resistance Level | A price ceiling where selling pressure historically prevents further advance. Prices tend to stall or reverse at resistance |
| Term | Definition |
|---|---|
| SMA (Simple Moving Average) | The unweighted arithmetic mean of the last $n$ closing prices: $\text{SMA}_n = \frac{1}{n}\sum_{i=0}^{n-1} C_{t-i}$ |
| EMA (Exponential Moving Average) | A weighted moving average that gives more weight to recent prices using a smoothing factor $\alpha = \frac{2}{n+1}$: $\text{EMA}_t = \alpha \cdot C_t + (1-\alpha) \cdot \text{EMA}_{t-1}$ |
| Bollinger Bands | A volatility envelope: a middle SMA band plus upper and lower bands at $\pm k$ standard deviations (typically $k=2$). Bands widen during volatile periods and narrow during calm ones |
| Doji | A candlestick where open and close are nearly equal, producing a very thin body. Signals indecision between buyers and sellers |
| Engulfing Pattern | A two-candle reversal pattern where the second candle's body completely "engulfs" the first. Bullish engulfing: red then larger green. Bearish engulfing: green then larger red |
| Hammer | A single-candle bullish reversal pattern with a small body near the top and a long lower wick (at least 2x the body length), indicating sellers pushed prices down but buyers recovered |
What & Why
Technical analysis is the practice of forecasting future price movements by studying historical price and volume data. Unlike fundamental analysis, which asks "what is this asset worth?", technical analysis asks "where is the price going next?" It treats the market itself as the primary source of information, operating on three assumptions: the market discounts everything, prices move in trends, and history tends to repeat itself.
The core data structure is the OHLC bar. For each trading period (minute, hour, day, week), four prices are recorded: the opening price when the period began, the highest price reached, the lowest price reached, and the closing price when the period ended. A single OHLC bar compresses thousands of individual trades into four numbers that capture the period's full price range and directional outcome.
Candlestick charts transform OHLC data into a visual language. Japanese rice traders developed this system in the 1700s, centuries before Western bar charts. Each candlestick encodes the same four prices but makes patterns immediately visible: the thick body shows the open-to-close range (green if close > open, red if close < open), while thin wicks extend to the high and low. Sequences of candlesticks form recognizable patterns that traders use as signals.
Technical analysis is controversial in academic finance. The Efficient Market Hypothesis (EMH) argues that all available information is already reflected in prices, making past price patterns useless for prediction. Empirical evidence is mixed: some patterns show statistically significant predictive power in certain markets and timeframes, while others perform no better than random chance. Despite this debate, technical analysis remains one of the most widely used tools in professional trading, and understanding it is essential for anyone working with financial data.
How It Works
Candlestick Anatomy
Every candlestick is built from four data points. The body represents the range between open and close. The upper wick (shadow) extends from the top of the body to the period high. The lower wick extends from the bottom of the body to the period low.
For a bullish candle, the close is above the open, so the body is green and the close marks the top of the body. For a bearish candle, the close is below the open, so the body is red and the open marks the top. The wick lengths reveal intra-period volatility: long wicks mean the price traveled far beyond the open-close range before being pulled back.
Interactive Candlestick Chart
The chart below shows 20 days of simulated OHLC price data with a 5-day SMA and a 10-day EMA overlaid. Green candles are up days (close above open), red candles are down days.
Classic Candlestick Patterns
Traders have catalogued dozens of candlestick patterns over centuries. Here are the most commonly referenced ones:
A doji forms when the open and close are nearly identical, creating a cross-shaped candle. It signals that neither buyers nor sellers won the period, often appearing at trend reversals. A hammer has a small body near the top with a long lower wick (at least twice the body length), indicating that sellers drove the price down but buyers pushed it back up. It is a bullish reversal signal when it appears after a downtrend. A shooting star is the inverse: small body near the bottom with a long upper wick, signaling bearish reversal. An engulfing pattern is a two-candle formation where the second candle's body completely contains the first, suggesting a shift in momentum.
Support and Resistance
Support and resistance levels are horizontal price zones where buying or selling pressure has historically concentrated. Support is a floor: when prices fall to this level, demand increases and the decline slows or reverses. Resistance is a ceiling: when prices rise to this level, supply increases and the advance stalls.
These levels emerge from market psychology. Traders remember prices where they previously bought or sold, creating self-reinforcing zones. A support level that is broken often becomes resistance (and vice versa), because traders who bought at support and are now underwater will sell to break even when prices return to that level.
Moving Averages
Moving averages smooth out price noise to reveal the underlying trend. The two most common types are:
Simple Moving Average (SMA): The arithmetic mean of the last $n$ closing prices.
$$\text{SMA}t(n) = \frac{1}{n}\sum{i=0}^{n-1} C_{t-i}$$
Every data point in the window receives equal weight. The SMA is easy to compute but reacts slowly to recent price changes because old data has the same influence as new data.
Exponential Moving Average (EMA): A recursive weighted average that gives exponentially more weight to recent prices.
$$\text{EMA}t = \alpha \cdot C_t + (1 - \alpha) \cdot \text{EMA}{t-1}$$
where the smoothing factor is $\alpha = \frac{2}{n+1}$. The EMA responds faster to price changes than the SMA of the same period, making it preferred for short-term trading signals.
A common trading signal is the crossover: when a short-period moving average crosses above a long-period one (a "golden cross," considered bullish) or below it (a "death cross," considered bearish).
Bollinger Bands
Bollinger Bands wrap a volatility envelope around a moving average. The three components are:
$$\text{Middle Band} = \text{SMA}_n$$
$$\text{Upper Band} = \text{SMA}_n + k \cdot \sigma_n$$
$$\text{Lower Band} = \text{SMA}_n - k \cdot \sigma_n$$
where $\sigma_n$ is the standard deviation of the last $n$ closing prices and $k$ is typically 2. The bands automatically widen during high-volatility periods and contract during low-volatility periods. Prices touching or exceeding the upper band suggest the asset may be overbought; touching the lower band suggests it may be oversold. A "squeeze" (bands narrowing sharply) often precedes a large price move.
Bollinger Bands Visualization
The chart below shows the same price data with 10-day Bollinger Bands ($k=2$). The middle band is the 10-day SMA, and the upper and lower bands are two standard deviations away.
Notice how the close price on Day 20 ($116) nearly touches the upper Bollinger Band ($116.1), suggesting the asset may be approaching overbought territory.
Complexity Analysis
Technical analysis computations are straightforward from an algorithmic perspective. The key operations and their complexities:
| Operation | Time | Space | Notes |
|---|---|---|---|
| SMA (single point) | $O(n)$ | $O(1)$ | Sum last $n$ prices |
| SMA (sliding, $T$ points) | $O(T)$ | $O(n)$ | Sliding window: subtract oldest, add newest |
| EMA (single point) | $O(1)$ | $O(1)$ | Recursive: only needs previous EMA |
| EMA (full series, $T$ points) | $O(T)$ | $O(1)$ | Single pass through data |
| Bollinger Bands (single point) | $O(n)$ | $O(n)$ | SMA + standard deviation over window |
| Bollinger Bands (sliding, $T$ points) | $O(T)$ | $O(n)$ | Sliding window with running variance |
| Pattern detection (scan) | $O(T)$ | $O(1)$ | Single pass checking fixed-size windows |
The key insight is that the EMA is more efficient than the SMA for streaming data. The SMA requires maintaining a window buffer of $n$ values and recomputing the sum each step (or using a sliding window trick). The EMA needs only the previous EMA value, making it $O(1)$ per update with $O(1)$ space:
$$\text{EMA}t = \alpha \cdot C_t + (1 - \alpha) \cdot \text{EMA}{t-1}$$
For Bollinger Bands, the standard deviation can be computed incrementally using Welford's online algorithm, maintaining running sums of $\sum C_i$ and $\sum C_i^2$ over the sliding window:
$$\sigma_n = \sqrt{\frac{\sum C_i^2}{n} - \left(\frac{\sum C_i}{n}\right)^2}$$
This avoids recomputing the full standard deviation from scratch at each step.
Implementation
Computing SMA with a Sliding Window
ALGORITHM SlidingSMA(prices, n)
INPUT: prices: array of closing prices (length T), n: window size
OUTPUT: sma: array of SMA values (length T, first n-1 entries are NULL)
BEGIN
sma ← array of size T, initialized to NULL
windowSum ← 0
FOR i ← 0 TO T - 1 DO
windowSum ← windowSum + prices[i]
IF i >= n THEN
windowSum ← windowSum - prices[i - n]
END IF
IF i >= n - 1 THEN
sma[i] ← windowSum / n
END IF
END FOR
RETURN sma
END
Computing EMA
ALGORITHM ComputeEMA(prices, n)
INPUT: prices: array of closing prices (length T), n: period
OUTPUT: ema: array of EMA values (length T)
BEGIN
alpha ← 2 / (n + 1)
ema ← array of size T
// Seed with SMA of first n prices
sum ← 0
FOR i ← 0 TO n - 1 DO
sum ← sum + prices[i]
ema[i] ← NULL
END FOR
ema[n - 1] ← sum / n
// Recursive computation
FOR i ← n TO T - 1 DO
ema[i] ← alpha * prices[i] + (1 - alpha) * ema[i - 1]
END FOR
RETURN ema
END
Computing Bollinger Bands
ALGORITHM BollingerBands(prices, n, k)
INPUT: prices: array of closing prices (length T),
n: SMA window size, k: number of standard deviations
OUTPUT: middle, upper, lower: arrays of band values
BEGIN
middle ← SlidingSMA(prices, n)
upper ← array of size T, initialized to NULL
lower ← array of size T, initialized to NULL
FOR i ← n - 1 TO T - 1 DO
// Compute standard deviation over window
sumSq ← 0
FOR j ← i - n + 1 TO i DO
diff ← prices[j] - middle[i]
sumSq ← sumSq + diff * diff
END FOR
sigma ← SQRT(sumSq / n)
upper[i] ← middle[i] + k * sigma
lower[i] ← middle[i] - k * sigma
END FOR
RETURN middle, upper, lower
END
Detecting Candlestick Patterns
ALGORITHM DetectPatterns(candles)
INPUT: candles: array of OHLC records
OUTPUT: signals: array of {index, pattern, direction}
BEGIN
signals ← empty list
FOR i ← 0 TO LENGTH(candles) - 1 DO
c ← candles[i]
bodySize ← ABS(c.close - c.open)
upperWick ← c.high - MAX(c.open, c.close)
lowerWick ← MIN(c.open, c.close) - c.low
totalRange ← c.high - c.low
// Doji: body is less than 10% of total range
IF totalRange > 0 AND bodySize / totalRange < 0.1 THEN
APPEND {i, "doji", "neutral"} TO signals
END IF
// Hammer: small body near top, lower wick >= 2x body
IF bodySize > 0 AND lowerWick >= 2 * bodySize
AND upperWick < bodySize THEN
APPEND {i, "hammer", "bullish"} TO signals
END IF
// Shooting Star: small body near bottom, upper wick >= 2x body
IF bodySize > 0 AND upperWick >= 2 * bodySize
AND lowerWick < bodySize THEN
APPEND {i, "shooting_star", "bearish"} TO signals
END IF
// Engulfing (requires previous candle)
IF i > 0 THEN
prev ← candles[i - 1]
prevBody ← ABS(prev.close - prev.open)
// Bullish engulfing: prev is red, current is green and engulfs
IF prev.close < prev.open AND c.close > c.open
AND c.open <= prev.close AND c.close >= prev.open THEN
APPEND {i, "bullish_engulfing", "bullish"} TO signals
END IF
// Bearish engulfing: prev is green, current is red and engulfs
IF prev.close > prev.open AND c.close < c.open
AND c.open >= prev.close AND c.close <= prev.open THEN
APPEND {i, "bearish_engulfing", "bearish"} TO signals
END IF
END IF
END FOR
RETURN signals
END
Real-World Applications
Algorithmic trading systems use moving average crossovers, Bollinger Band breakouts, and pattern detection as components in automated trading strategies. These signals are rarely used in isolation but are combined with volume analysis, momentum indicators, and risk management rules.
Charting platforms like TradingView, Bloomberg Terminal, and MetaTrader render candlestick charts with dozens of overlaid indicators. The OHLC data model and candlestick rendering logic described here is the foundation of every charting library.
Quantitative backtesting frameworks (Zipline, Backtrader, QuantConnect) compute technical indicators over historical data to evaluate whether a strategy would have been profitable. The sliding window and EMA algorithms above are the building blocks of these systems.
Risk management uses Bollinger Bands and volatility measures to set stop-loss levels and position sizes. When bands widen (high volatility), risk managers reduce position sizes; when bands narrow, they may increase exposure in anticipation of a breakout.
Market microstructure research studies how candlestick patterns emerge from the interaction of limit orders, market orders, and algorithmic traders. The patterns are not magic: they reflect the aggregate behavior of market participants responding to price levels.
Key Takeaways
-
OHLC data compresses all trades in a period into four prices: open, high, low, close. Candlestick charts make this data visually intuitive, with bodies showing the open-close range and wicks showing the full price range.
-
Classic patterns (doji, hammer, engulfing, shooting star) encode market psychology into visual signals. They are heuristics, not guarantees, and work best when confirmed by volume and context.
-
Moving averages (SMA and EMA) smooth price noise to reveal trends. The EMA is computationally cheaper for streaming data ($O(1)$ per update) and more responsive to recent prices than the SMA.
-
Bollinger Bands create a dynamic volatility envelope around a moving average. Band width reflects current volatility, and price touching the bands suggests potential overbought or oversold conditions.
-
Technical analysis is controversial: the Efficient Market Hypothesis argues past prices cannot predict future prices. Empirical evidence is mixed, but the tools remain widely used in practice because they provide a structured framework for reading price action.
Read More
2025-09-06
Reading Charts in Finance: A Visual Toolkit
A survey of the major chart types used in quantitative finance, covering candlestick, line, area, bar, scatter, radar, and waterfall charts, with guidance on what each shows, when to use it, and common misreadings.
2025-09-06
Reading Charts in Finance: A Visual Toolkit
A survey of the major chart types used in quantitative finance, covering candlestick, line, area, bar, scatter, radar, and waterfall charts, with guidance on what each shows, when to use it, and common misreadings.
2025-08-22
Time Value of Money: Why a Dollar Today Beats a Dollar Tomorrow
Present value, future value, discounting, continuous compounding, why Euler's number shows up in finance, and NPV for engineering decisions.