3. Candlestick Patterns

30 minbeginner

3. Candlestick Patterns

Introduction: Reading Price Action Through Candlesticks

Candlestick patterns are among the most powerful tools in technical analysis, providing immediate visual feedback about market sentiment and potential reversals. Developed in Japan over 300 years ago for analyzing rice futures, candlestick patterns have become fundamental to modern technical analysis because they capture the psychology of market participants in a single visual representation.

The power of candlestick patterns lies in their ability to tell a story about the battle between buyers and sellers during each trading period. Each candlestick shows not just where price closed, but how it got there - the struggle between buyers and sellers, the rejection of certain price levels, and the final outcome of that period's trading. This rich information makes candlestick patterns particularly valuable for identifying potential reversals and continuation points.

Candlestick patterns work because they reflect consistent human psychology. When sellers push prices lower but buyers reject those lower prices (creating a long lower wick), it shows that buyers are stepping in at that level. This psychological pattern - fear of lower prices followed by buying interest - tends to repeat, making candlestick patterns reliable indicators of potential price reversals.

Understanding Candlestick Construction

Before we can identify and trade candlestick patterns, we must understand how candlesticks are constructed and what information they convey. Each element of a candlestick - the body, the wicks, the color - tells part of the story of market behavior during that period.

Body and Shadows

The body of a candlestick represents the range between the opening and closing prices. It's the thick part of the candle and is the most visually prominent element. The body size tells us about the strength of buying or selling pressure - a large body indicates strong directional movement, while a small body suggests indecision and weak directional movement.

The shadows (also called wicks or tails) are the thin lines extending above and below the body. They represent the price range beyond the open-close range - the high and low prices reached during the period. The upper shadow shows how high prices went before being rejected, while the lower shadow shows how low prices went before being rejected.

Long shadows are particularly significant because they show rejection of certain price levels. A long upper shadow indicates that buyers pushed prices higher, but sellers rejected those higher prices and pushed them back down. A long lower shadow indicates that sellers pushed prices lower, but buyers rejected those lower prices and pushed them back up. These rejections often signal support or resistance levels and potential reversal points.

Bullish vs. Bearish Candles

Candlesticks are color-coded to immediately convey whether buyers or sellers controlled the period. In most charting systems, a bullish candle (typically green or white) indicates that the closing price was higher than the opening price, meaning buyers were in control. A bearish candle (typically red or black) indicates that the closing price was lower than the opening price, meaning sellers were in control.

The color coding makes it easy to see at a glance the overall sentiment during each period. A series of green candles suggests strong buying pressure and an uptrend, while a series of red candles suggests strong selling pressure and a downtrend. However, the size and shape of the candles provide additional nuance - a small green candle with a long upper shadow suggests that while buyers closed the period in control, sellers rejected higher prices, which might signal weakening buying pressure.

Opening and Closing Prices

The relationship between the opening and closing prices determines the candle's color and provides insight into the period's trading dynamics. The opening price represents where trading began - the price at which the first trade occurred. The closing price represents where trading ended - the price at which the last trade occurred.

The relationship between these prices tells us about the battle between buyers and sellers. If the close is significantly above the open (a large green body), buyers dominated the period. If the close is significantly below the open (a large red body), sellers dominated. If the open and close are very close (a small body or doji), neither buyers nor sellers gained control, suggesting indecision and potential reversal.

Single Candlestick Patterns

Single candlestick patterns are formed by one candle and provide immediate signals about market sentiment and potential reversals. These patterns are particularly useful because they can be identified quickly and don't require waiting for multiple periods to confirm.

Doji

The doji is one of the most important single-candlestick patterns because it signals indecision and potential reversal. A doji forms when the opening and closing prices are essentially the same, creating a very small body (or no body at all).

Doji: A candlestick pattern where the opening and closing prices are essentially equal, creating a very small or nonexistent body. The doji signals indecision in the market and potential trend reversal, as neither buyers nor sellers gained control during the period.

The doji pattern is significant because it shows that despite price movement during the period (as evidenced by the wicks), buyers and sellers ended the period at essentially the same level. This balance suggests that the prevailing trend may be losing momentum and that a reversal might be imminent. The doji is particularly powerful when it appears after a strong directional move, as it suggests that the trend is exhausted.

There are several variations of the doji, each with slightly different implications. The standard doji has approximately equal upper and lower shadows, suggesting perfect balance. The long-legged doji has very long shadows on both sides, showing high volatility and strong rejection of both higher and lower prices. The gravestone doji has a long upper shadow and no lower shadow, suggesting that buyers pushed prices higher but sellers rejected them completely. The dragonfly doji has a long lower shadow and no upper shadow, suggesting that sellers pushed prices lower but buyers rejected them completely.

Hammer and Hanging Man

The hammer and hanging man are identical candlestick formations that have different meanings depending on their context. Both patterns have a small body at the top of the trading range, a long lower shadow, and little or no upper shadow.

Hammer: A bullish reversal pattern with a small body at the top of the trading range, a long lower shadow (at least twice the body size), and little or no upper shadow. The hammer appears after a downtrend and signals potential reversal to the upside.

The hammer pattern tells a story of rejection. During the period, sellers pushed prices significantly lower (creating the long lower shadow), but buyers stepped in and rejected those lower prices, pushing prices back up to close near the open. This rejection of lower prices, especially after a downtrend, suggests that buyers are gaining strength and that the downtrend may be reversing.

The hanging man is identical in appearance to the hammer but appears after an uptrend and signals potential reversal to the downside. The same price action - sellers pushing prices lower but buyers rejecting them - has different implications in an uptrend. In an uptrend, a hanging man suggests that while buyers still control the close, sellers are becoming more aggressive, which might signal the beginning of a reversal.

The key to distinguishing between a hammer and a hanging man is context. The same candlestick formation is a hammer if it appears after a downtrend (bullish reversal signal) and a hanging man if it appears after an uptrend (bearish reversal signal). This context-dependence is why understanding the prevailing trend is essential for candlestick pattern analysis.

Shooting Star and Inverted Hammer

The shooting star and inverted hammer are the mirror images of the hammer and hanging man. Both patterns have a small body at the bottom of the trading range, a long upper shadow, and little or no lower shadow.

Shooting Star: A bearish reversal pattern with a small body at the bottom of the trading range, a long upper shadow (at least twice the body size), and little or no lower shadow. The shooting star appears after an uptrend and signals potential reversal to the downside.

The shooting star tells a story of rejection at higher prices. During the period, buyers pushed prices significantly higher (creating the long upper shadow), but sellers stepped in and rejected those higher prices, pushing prices back down to close near the open. This rejection of higher prices, especially after an uptrend, suggests that sellers are gaining strength and that the uptrend may be reversing.

The inverted hammer is identical in appearance to the shooting star but appears after a downtrend and signals potential reversal to the upside. The same price action - buyers pushing prices higher but sellers rejecting them - has different implications in a downtrend. In a downtrend, an inverted hammer suggests that while sellers still control the close, buyers are becoming more aggressive, which might signal the beginning of a reversal.

Marubozu

The marubozu is a candlestick with no shadows - the body extends from the high to the low of the period. This pattern indicates strong directional movement with no rejection of prices at either extreme.

Marubozu: A candlestick pattern with no shadows, where the body extends from the high to the low of the trading period. A bullish marubozu (green) indicates strong buying pressure with no rejection of higher prices, while a bearish marubozu (red) indicates strong selling pressure with no rejection of lower prices.

The marubozu pattern is significant because it shows that one side (buyers or sellers) completely dominated the period without any rejection. A bullish marubozu shows that buyers were in complete control - prices opened at the low and closed at the high, with no rejection of higher prices. This suggests very strong buying pressure. A bearish marubozu shows the opposite - sellers were in complete control, with prices opening at the high and closing at the low.

Marubozu candles are particularly powerful when they appear in a series or at key support/resistance levels. A series of bullish marubozu candles suggests extremely strong buying pressure and a strong uptrend. A bullish marubozu at a support level suggests that buyers are strongly defending that level. However, marubozu candles can also signal exhaustion - after a series of marubozu candles, the trend may be due for a reversal.

Two-Candlestick Patterns

Two-candlestick patterns combine the information from two consecutive periods to provide stronger signals than single-candlestick patterns. These patterns show how the battle between buyers and sellers evolves over two periods, providing more reliable reversal and continuation signals.

Engulfing Patterns (Bullish and Bearish)

Engulfing patterns are among the most reliable two-candlestick reversal patterns. They occur when the body of the second candle completely engulfs (covers) the body of the first candle, signaling a strong shift in market sentiment.

Bullish Engulfing Pattern: A two-candlestick bullish reversal pattern where a bearish candle is followed by a larger bullish candle whose body completely engulfs the body of the first candle. The pattern signals that buyers have taken control and that a reversal to the upside is likely.

The bullish engulfing pattern tells a clear story of sentiment shift. The first candle (bearish) shows that sellers were in control - prices closed lower than they opened. However, the second candle (bullish) shows that buyers completely overwhelmed sellers - not only did prices recover from the first candle's decline, but they closed higher than the first candle opened. This complete reversal of the first candle's body shows that buying pressure has completely overwhelmed selling pressure.

The bearish engulfing pattern is the opposite - a bullish candle is followed by a larger bearish candle whose body completely engulfs the first candle's body. This signals that sellers have taken control and that a reversal to the downside is likely.

Engulfing patterns are particularly reliable when: (1) they occur after a strong trend (showing exhaustion), (2) the second candle's body is significantly larger than the first (showing strong reversal pressure), (3) volume is higher on the second candle (confirming the reversal), and (4) the pattern occurs at key support or resistance levels.

Python exercise

#| label: fig-engulfing-patterns
#| fig-cap: "Engulfing Patterns: Enhanced Analysis - Volume Confirmation, Pattern Strength, and Trading Signals"
#| fig-width: 18
#| fig-height: 12

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.patches import Rectangle
import numpy as np
from IPython.display import display
from datetime import datetime, timedelta

# Create 4-panel figure
fig = plt.figure(figsize=(18, 12))
gs = fig.add_gridspec(2, 2, hspace=0.35, wspace=0.3, height_ratios=[1.5, 1])
fig.suptitle('Engulfing Patterns: Enhanced Analysis - Volume Confirmation, Pattern Strength, and Trading Signals', 
             fontsize=17, fontweight='bold', y=0.98)

# Generate bullish engulfing pattern data with volume
np.random.seed(42)
dates_bull = [datetime(2024, 1, 1) + timedelta(days=i) for i in range(10)]
base_volume = 1000000

# Create downtrend leading to bullish engulfing
ohlc_bull = []
volumes_bull = []
for i in range(8):
    open_price = 100 - i * 1.5
    close_price = open_price - 1 - np.random.normal(0, 0.3)
    high_price = open_price + 0.5
    low_price = close_price - 1
    ohlc_bull.append((open_price, high_price, low_price, close_price))
    volumes_bull.append(base_volume * (0.9 + i * 0.05) + np.random.normal(0, 70000))

# Bullish engulfing pattern
# First candle (bearish) - lower volume
open1 = 88
close1 = 86
high1 = 88.5
low1 = 85
body1 = abs(close1 - open1)
ohlc_bull.append((open1, high1, low1, close1))
volumes_bull.append(base_volume * 0.8 + np.random.normal(0, 60000))

# Second candle (bullish, engulfs first) - high volume
open2 = 85.5
close2 = 90  # Engulfs first candle's open
high2 = 90.5
low2 = 85
body2 = abs(close2 - open2)
ohlc_bull.append((open2, high2, low2, close2))
volumes_bull.append(base_volume * 2.5 + np.random.normal(0, 150000))  # High volume confirmation

# Calculate pattern metrics
engulfing_ratio = body2 / body1
volume_ratio = volumes_bull[-1] / volumes_bull[-2]

# Panel 1: Bullish Engulfing Pattern
ax1 = fig.add_subplot(gs[0, 0])
for i, (date, (open_price, high, low, close_price)) in enumerate(zip(dates_bull, ohlc_bull)):
    wick_color = 'black'
    ax1.plot([date, date], [low, high], color=wick_color, linewidth=1.5, alpha=0.7)
    body_height = abs(close_price - open_price)
    body_bottom = min(open_price, close_price)
    color = '#2ecc71' if close_price > open_price else '#e74c3c'
    rect = Rectangle((mdates.date2num(date) - 0.35, body_bottom), 0.7, body_height, 
                     facecolor=color, edgecolor='black', linewidth=1.5, alpha=0.9)
    ax1.add_patch(rect)

# Highlight engulfing pattern
ax1.annotate('Bearish Candle\n(Sellers)', 
            xy=(dates_bull[-2], ohlc_bull[-2][3]), xytext=(-25, 30),
            textcoords='offset points', fontsize=9, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='red', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='black', lw=1.5))
ax1.annotate(f'Bullish Engulfing\n({engulfing_ratio:.1f}x size)', 
            xy=(dates_bull[-1], ohlc_bull[-1][3]), xytext=(25, 30),
            textcoords='offset points', fontsize=10, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='green', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='green', lw=2.5))

ax1.set_title('Panel 1: Bullish Engulfing Pattern (Bearish to Bullish Reversal)', 
              fontsize=13, fontweight='bold')
ax1.set_ylabel('Price ($)', fontsize=11, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--')
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))

# Panel 2: Bearish Engulfing Pattern
dates_bear = [datetime(2024, 1, 1) + timedelta(days=i) for i in range(10)]
ohlc_bear = []
volumes_bear = []

# Create uptrend leading to bearish engulfing
for i in range(8):
    open_price = 90 + i * 1.5
    close_price = open_price + 1 + np.random.normal(0, 0.3)
    high_price = close_price + 0.5
    low_price = open_price - 1
    ohlc_bear.append((open_price, high_price, low_price, close_price))
    volumes_bear.append(base_volume * (0.9 + i * 0.05) + np.random.normal(0, 70000))

# Bearish engulfing pattern
open1 = 102
close1 = 104
high1 = 104.5
low1 = 101.5
body1_bear = abs(close1 - open1)
ohlc_bear.append((open1, high1, low1, close1))
volumes_bear.append(base_volume * 0.8 + np.random.normal(0, 60000))

open2 = 103.5
close2 = 99
high2 = 103.5
low2 = 98.5
body2_bear = abs(close2 - open2)
ohlc_bear.append((open2, high2, low2, close2))
volumes_bear.append(base_volume * 2.5 + np.random.normal(0, 150000))

engulfing_ratio_bear = body2_bear / body1_bear
volume_ratio_bear = volumes_bear[-1] / volumes_bear[-2]

ax2 = fig.add_subplot(gs[0, 1])
for i, (date, (open_price, high, low, close_price)) in enumerate(zip(dates_bear, ohlc_bear)):
    ax2.plot([date, date], [low, high], color='black', linewidth=1.5, alpha=0.7)
    body_height = abs(close_price - open_price)
    body_bottom = min(open_price, close_price)
    color = '#2ecc71' if close_price > open_price else '#e74c3c'
    rect = Rectangle((mdates.date2num(date) - 0.35, body_bottom), 0.7, body_height, 
                     facecolor=color, edgecolor='black', linewidth=1.5, alpha=0.9)
    ax2.add_patch(rect)

ax2.annotate('Bullish Candle\n(Buyers)', 
            xy=(dates_bear[-2], ohlc_bear[-2][3]), xytext=(-25, -35),
            textcoords='offset points', fontsize=9, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='green', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='black', lw=1.5))
ax2.annotate(f'Bearish Engulfing\n({engulfing_ratio_bear:.1f}x size)', 
            xy=(dates_bear[-1], ohlc_bear[-1][3]), xytext=(25, -35),
            textcoords='offset points', fontsize=10, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='red', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='red', lw=2.5))

ax2.set_title('Panel 2: Bearish Engulfing Pattern (Bullish to Bearish Reversal)', 
              fontsize=13, fontweight='bold')
ax2.set_ylabel('Price ($)', fontsize=11, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))

# Panel 3: Volume Analysis
ax3 = fig.add_subplot(gs[1, 0])
pattern_types = ['Bullish\nEngulfing', 'Bearish\nEngulfing']
volume_ratios_plot = [volume_ratio, volume_ratio_bear]
body_ratios_plot = [engulfing_ratio, engulfing_ratio_bear]

x = np.arange(len(pattern_types))
width = 0.35

bars1 = ax3.bar(x - width/2, volume_ratios_plot, width, label='Volume Ratio', 
                color=['green', 'red'], alpha=0.7, edgecolor='black', linewidth=1.5)
bars2 = ax3.bar(x + width/2, body_ratios_plot, width, label='Body Size Ratio', 
                color=['lightgreen', 'lightcoral'], alpha=0.7, edgecolor='black', linewidth=1.5)

for bar, val in zip(bars1, volume_ratios_plot):
    height = bar.get_height()
    ax3.text(bar.get_x() + bar.get_width()/2., height + 0.1,
            f'{val:.2f}x', ha='center', va='bottom', fontsize=9, fontweight='bold')
for bar, val in zip(bars2, body_ratios_plot):
    height = bar.get_height()
    ax3.text(bar.get_x() + bar.get_width()/2., height + 0.1,
            f'{val:.2f}x', ha='center', va='bottom', fontsize=9, fontweight='bold')

ax3.set_title('Panel 3: Pattern Strength Metrics - Volume & Body Size Ratios', 
              fontsize=12, fontweight='bold')
ax3.set_ylabel('Ratio', fontsize=11, fontweight='bold')
ax3.set_xticks(x)
ax3.set_xticklabels(pattern_types, fontsize=10)
ax3.legend(loc='upper left', fontsize=9)
ax3.grid(True, alpha=0.3, linestyle='--', axis='y')

# Panel 4: Trading Guide and Formulas
ax4 = fig.add_subplot(gs[1, 1])
ax4.axis('off')

formula_text = f"""
Engulfing Pattern Analysis:

Pattern Requirements:
• Candle 1: Small body in trend direction
• Candle 2: Large body opposite direction
• Candle 2 body completely engulfs Candle 1 body
• Higher volume on Candle 2 (confirmation)

Pattern Metrics:
• Bullish Engulfing:
  - Body Ratio: {engulfing_ratio:.2f}x
  - Volume Ratio: {volume_ratio:.2f}x
  - Reliability: {'High' if volume_ratio > 2.0 and engulfing_ratio > 1.5 else 'Medium'}

• Bearish Engulfing:
  - Body Ratio: {engulfing_ratio_bear:.2f}x
  - Volume Ratio: {volume_ratio_bear:.2f}x
  - Reliability: {'High' if volume_ratio_bear > 2.0 and engulfing_ratio_bear > 1.5 else 'Medium'}

Trading Signals:
• Entry: On pattern completion (Candle 2 close)
• Stop Loss: Beyond opposite side of pattern
• Target: Pattern height projected
• Confirmation: High volume (2x+ average)

Pattern Strength Factors:
✓ Larger engulfing candle = stronger signal
✓ Higher volume = more reliable
✓ At support/resistance = stronger
✓ After strong trend = more reliable
✓ Multiple confirmations = stronger
"""

ax4.text(0.05, 0.95, formula_text, transform=ax4.transAxes, fontsize=10,
        verticalalignment='top', family='monospace',
        bbox=dict(boxstyle='round', facecolor='wheat', alpha=0.6))

plt.tight_layout()
display(fig)
plt.close(fig)

Harami Patterns

Harami patterns (from the Japanese word for "pregnant") are the opposite of engulfing patterns. They occur when a large candle is followed by a small candle whose body is completely contained within the body of the first candle.

Bullish Harami Pattern: A two-candlestick bullish reversal pattern where a large bearish candle is followed by a small candle (bullish or bearish) whose body is completely contained within the first candle's body. The pattern signals that selling pressure is weakening and that a reversal to the upside may be imminent.

The harami pattern shows a different type of sentiment shift than the engulfing pattern. While the engulfing pattern shows an immediate, strong reversal, the harami pattern shows a more gradual shift - the large first candle shows strong directional pressure, but the small second candle shows that this pressure is weakening. The small second candle, contained within the first, suggests that the market is pausing and that the prevailing trend may be losing momentum.

The bearish harami pattern is the opposite - a large bullish candle is followed by a small candle contained within it, signaling that buying pressure is weakening and that a reversal to the downside may be imminent.

Piercing Pattern and Dark Cloud Cover

The piercing pattern and dark cloud cover are two-candlestick patterns that show partial engulfing - the second candle doesn't completely engulf the first, but it shows a significant shift in sentiment.

Piercing Pattern: A bullish reversal pattern consisting of a bearish candle followed by a bullish candle that opens below the first candle's low but closes above the midpoint of the first candle's body. The pattern signals that buyers are recovering from selling pressure and that a reversal to the upside is likely.

The piercing pattern shows buyers recovering from selling pressure. The first candle (bearish) shows strong selling pressure. The second candle (bullish) opens even lower, suggesting continued selling, but then buyers step in and push prices up, closing above the midpoint of the first candle. This recovery shows that buyers are gaining strength and that the downtrend may be reversing.

Dark Cloud Cover is the bearish counterpart - a bullish candle is followed by a bearish candle that opens above the first candle's high but closes below the midpoint of the first candle's body. This shows that sellers are recovering from buying pressure and that the uptrend may be reversing.

Tweezers

Tweezer patterns occur when two consecutive candles have the same high (tweezer tops) or the same low (tweezer bottoms). These patterns signal rejection at specific price levels and potential reversal.

Tweezer Tops: A bearish reversal pattern consisting of two consecutive candles with the same high price. The pattern signals that buyers attempted to push prices higher but were rejected at the same level twice, suggesting that resistance is strong and that a reversal to the downside is likely.

Tweezer patterns are simple but effective - they show that the market tested a specific price level twice and was rejected both times. This double rejection suggests that the level is significant and that a reversal is likely. Tweezer tops are particularly powerful when they occur at resistance levels, and tweezer bottoms are powerful when they occur at support levels.

Three-Candlestick Patterns

Three-candlestick patterns provide even stronger signals than two-candlestick patterns because they show how sentiment evolves over three periods. These patterns are generally more reliable but take longer to form, making them better suited for longer-term trading decisions.

Morning Star and Evening Star

The morning star and evening star are among the most reliable three-candlestick reversal patterns. They consist of three candles that together tell a complete story of trend reversal.

Morning Star Pattern: A bullish reversal pattern consisting of three candles: (1) a large bearish candle showing strong selling pressure, (2) a small candle (often a doji or spinning top) that gaps down from the first candle, showing indecision, and (3) a large bullish candle that gaps up and closes well into the first candle's body, confirming the reversal.

The morning star pattern tells a complete reversal story. The first candle shows strong selling pressure in a downtrend. The second candle shows indecision - it gaps down (continuing the downtrend) but is small, suggesting that selling pressure is weakening. The third candle confirms the reversal by gapping up and closing well into the first candle's body, showing that buyers have taken control.

The evening star pattern is the bearish counterpart - a large bullish candle is followed by a small indecision candle that gaps up, which is then followed by a large bearish candle that gaps down and closes well into the first candle's body.

Python exercise

#| label: fig-morning-evening-star
#| fig-cap: "Morning Star and Evening Star Patterns: Enhanced Analysis - Volume Confirmation, Pattern Phases, and Trading Signals"
#| fig-width: 18
#| fig-height: 12

# Sandbox metadata (auto-generated from lesson.ts)
# libraries: numpy, matplotlib, pandas

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.patches import Rectangle
import numpy as np
from IPython.display import display
from datetime import datetime, timedelta

# Create 4-panel figure
fig = plt.figure(figsize=(18, 12))
gs = fig.add_gridspec(2, 2, hspace=0.35, wspace=0.3, height_ratios=[1.5, 1])
fig.suptitle('Morning Star and Evening Star Patterns: Enhanced Analysis - Volume Confirmation, Pattern Phases, and Trading Signals', 
             fontsize=17, fontweight='bold', y=0.98)

# Generate morning star pattern data with volume
np.random.seed(42)
dates_morning = [datetime(2024, 1, 1) + timedelta(days=i) for i in range(10)]
base_volume = 1000000

# Create downtrend leading to morning star
ohlc_morning = []
volumes_morning = []
for i in range(7):
    open_price = 100 - i * 2
    close_price = open_price - 1.5 - np.random.normal(0, 0.3)
    high_price = open_price + 0.5
    low_price = close_price - 1
    ohlc_morning.append((open_price, high_price, low_price, close_price))
    volumes_morning.append(base_volume * (1.0 + i * 0.1) + np.random.normal(0, 80000))

# Morning star pattern
# First candle (large bearish) - high volume
open1 = 86
close1 = 83
high1 = 86.5
low1 = 82
body1 = abs(close1 - open1)
ohlc_morning.append((open1, high1, low1, close1))
volumes_morning.append(base_volume * 1.5 + np.random.normal(0, 100000))

# Second candle (small, gaps down, doji-like) - low volume
open2 = 82.5  # Gap down
close2 = 82.7  # Small body (doji)
high2 = 83.5
low2 = 82.2
body2 = abs(close2 - open2)
ohlc_morning.append((open2, high2, low2, close2))
volumes_morning.append(base_volume * 0.6 + np.random.normal(0, 50000))  # Low volume indecision

# Third candle (large bullish, gaps up) - high volume
open3 = 84  # Gap up
close3 = 87  # Closes well into first candle's body
high3 = 87.5
low3 = 83.5
body3 = abs(close3 - open3)
ohlc_morning.append((open3, high3, low3, close3))
volumes_morning.append(base_volume * 2.2 + np.random.normal(0, 120000))  # High volume confirmation

# Calculate pattern metrics
gap1 = open2 - close1  # Gap down
gap2 = open3 - close2  # Gap up
penetration = (close3 - open1) / body1  # How much third candle penetrates first
volume_ratio_morning = volumes_morning[-1] / volumes_morning[-2]

# Panel 1: Morning Star Pattern
ax1 = fig.add_subplot(gs[0, 0])
for i, (date, (open_price, high, low, close_price)) in enumerate(zip(dates_morning, ohlc_morning)):
    ax1.plot([date, date], [low, high], color='black', linewidth=1.5, alpha=0.7)
    body_height = abs(close_price - open_price)
    body_bottom = min(open_price, close_price)
    color = '#2ecc71' if close_price > open_price else '#e74c3c'
    rect = Rectangle((mdates.date2num(date) - 0.35, body_bottom), 0.7, body_height, 
                     facecolor=color, edgecolor='black', linewidth=1.5, alpha=0.9)
    ax1.add_patch(rect)

# Annotate pattern phases
ax1.annotate('Phase 1: Large Bearish\n(Strong Selling)', 
            xy=(dates_morning[-3], ohlc_morning[-3][3]), xytext=(-25, -35),
            textcoords='offset points', fontsize=9, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='red', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='black', lw=1.5))
ax1.annotate('Phase 2: Small Doji\n(Indecision, Gap Down)', 
            xy=(dates_morning[-2], ohlc_morning[-2][3]), xytext=(25, 20),
            textcoords='offset points', fontsize=9, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='yellow', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='black', lw=1.5))
ax1.annotate('Phase 3: Large Bullish\n(Reversal, Gap Up)', 
            xy=(dates_morning[-1], ohlc_morning[-1][3]), xytext=(25, 30),
            textcoords='offset points', fontsize=10, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='green', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='green', lw=2.5))

ax1.set_title('Panel 1: Morning Star Pattern (Bullish Reversal)', fontsize=13, fontweight='bold')
ax1.set_ylabel('Price ($)', fontsize=11, fontweight='bold')
ax1.grid(True, alpha=0.3, linestyle='--')
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))

# Generate evening star pattern data with volume
dates_evening = [datetime(2024, 1, 1) + timedelta(days=i) for i in range(10)]
ohlc_evening = []
volumes_evening = []

# Create uptrend leading to evening star
for i in range(7):
    open_price = 90 + i * 2
    close_price = open_price + 1.5 + np.random.normal(0, 0.3)
    high_price = close_price + 0.5
    low_price = open_price - 1
    ohlc_evening.append((open_price, high_price, low_price, close_price))
    volumes_evening.append(base_volume * (1.0 + i * 0.1) + np.random.normal(0, 80000))

# Evening star pattern
open1 = 104
close1 = 107
high1 = 107.5
low1 = 103.5
body1_evening = abs(close1 - open1)
ohlc_evening.append((open1, high1, low1, close1))
volumes_evening.append(base_volume * 1.5 + np.random.normal(0, 100000))

open2 = 107.5  # Gap up
close2 = 107.3  # Small body (doji)
high2 = 108
low2 = 106.8
body2_evening = abs(close2 - open2)
ohlc_evening.append((open2, high2, low2, close2))
volumes_evening.append(base_volume * 0.6 + np.random.normal(0, 50000))

open3 = 106  # Gap down
close3 = 103  # Closes well into first candle's body
high3 = 106.5
low3 = 102.5
body3_evening = abs(close3 - open3)
ohlc_evening.append((open3, high3, low3, close3))
volumes_evening.append(base_volume * 2.2 + np.random.normal(0, 120000))

gap1_evening = open2 - close1
gap2_evening = open3 - close2
penetration_evening = (open1 - close3) / body1_evening
volume_ratio_evening = volumes_evening[-1] / volumes_evening[-2]

# Panel 2: Evening Star Pattern
ax2 = fig.add_subplot(gs[0, 1])
for i, (date, (open_price, high, low, close_price)) in enumerate(zip(dates_evening, ohlc_evening)):
    ax2.plot([date, date], [low, high], color='black', linewidth=1.5, alpha=0.7)
    body_height = abs(close_price - open_price)
    body_bottom = min(open_price, close_price)
    color = '#2ecc71' if close_price > open_price else '#e74c3c'
    rect = Rectangle((mdates.date2num(date) - 0.35, body_bottom), 0.7, body_height, 
                     facecolor=color, edgecolor='black', linewidth=1.5, alpha=0.9)
    ax2.add_patch(rect)

ax2.annotate('Phase 1: Large Bullish\n(Strong Buying)', 
            xy=(dates_evening[-3], ohlc_evening[-3][3]), xytext=(-25, 35),
            textcoords='offset points', fontsize=9, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='green', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='black', lw=1.5))
ax2.annotate('Phase 2: Small Doji\n(Indecision, Gap Up)', 
            xy=(dates_evening[-2], ohlc_evening[-2][3]), xytext=(25, -25),
            textcoords='offset points', fontsize=9, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='yellow', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='black', lw=1.5))
ax2.annotate('Phase 3: Large Bearish\n(Reversal, Gap Down)', 
            xy=(dates_evening[-1], ohlc_evening[-1][3]), xytext=(25, -35),
            textcoords='offset points', fontsize=10, fontweight='bold',
            bbox=dict(boxstyle='round', facecolor='red', alpha=0.8),
            arrowprops=dict(arrowstyle='->', color='red', lw=2.5))

ax2.set_title('Panel 2: Evening Star Pattern (Bearish Reversal)', fontsize=13, fontweight='bold')
ax2.set_ylabel('Price ($)', fontsize=11, fontweight='bold')
ax2.grid(True, alpha=0.3, linestyle='--')
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d'))

# Panel 3: Volume Analysis
ax3 = fig.add_subplot(gs[1, 0])
pattern_phases = ['Phase 1\n(Large)', 'Phase 2\n(Doji)', 'Phase 3\n(Reversal)']
volumes_morning_norm = [v / max(volumes_morning) * 100 for v in volumes_morning[-3:]]
volumes_evening_norm = [v / max(volumes_evening) * 100 for v in volumes_evening[-3:]]

x = np.arange(len(pattern_phases))
width = 0.35

bars1 = ax3.bar(x - width/2, volumes_morning_norm, width, label='Morning Star', 
                color='green', alpha=0.7, edgecolor='black', linewidth=1.5)
bars2 = ax3.bar(x + width/2, volumes_evening_norm, width, label='Evening Star', 
                color='red', alpha=0.7, edgecolor='black', linewidth=1.5)

for bar, val in zip(bars1, volumes_morning_norm):
    height = bar.get_height()
    ax3.text(bar.get_x() + bar.get_width()/2., height + 2,
            f'{val:.0f}%', ha='center', va='bottom', fontsize=8, fontweight='bold')
for bar, val in zip(bars2, volumes_evening_norm):
    height = bar.get_height()
    ax3.text(bar.get_x() + bar.get_width()/2., height + 2,
            f'{val:.0f}%', ha='center', va='bottom', fontsize=8, fontweight='bold')

ax3.set_title('Panel 3: Volume Pattern - High Volume on Phase 1 & 3, Low on Phase 2', 
              fontsize=12, fontweight='bold')
ax3.set_ylabel('Normalized Volume (%)', fontsize=11, fontweight='bold')
ax3.set_xticks(x)
ax3.set_xticklabels(pattern_phases, fontsize=10)
ax3.legend(loc='upper left', fontsize=9)
ax3.grid(True, alpha=0.3, linestyle='--', axis='y')

# Panel 4: Pattern Analysis and Trading Guide
ax4 = fig.add_subplot(gs[1, 1])
ax4.axis('off')

formula_text = f"""
Morning/Evening Star Pattern Analysis:

Pattern Structure:
• Phase 1: Large candle in trend direction
• Phase 2: Small doji (gaps from Phase 1)
• Phase 3: Large candle opposite direction (gaps from Phase 2)

Morning Star Metrics:
• Gap 1 (Down): ${abs(gap1):.2f}
• Gap 2 (Up): ${gap2:.2f}
• Penetration: {penetration*100:.1f}% into Phase 1 body
• Volume Ratio: {volume_ratio_morning:.2f}x (Phase 3 vs Phase 2)
• Reliability: {'High' if volume_ratio_morning > 2.0 and penetration > 0.5 else 'Medium'}

Evening Star Metrics:
• Gap 1 (Up): ${gap1_evening:.2f}
• Gap 2 (Down): ${abs(gap2_evening):.2f}
• Penetration: {penetration_evening*100:.1f}% into Phase 1 body
• Volume Ratio: {volume_ratio_evening:.2f}x (Phase 3 vs Phase 2)
• Reliability: {'High' if volume_ratio_evening > 2.0 and penetration_evening > 0.5 else 'Medium'}

Trading Signals:
• Entry: On Phase 3 completion (close)
• Stop Loss: Below Phase 2 low (Morning) / Above Phase 2 high (Evening)
• Target: Pattern height projected
• Confirmation: High volume on Phase 3

Pattern Strength Factors:
✓ Larger Phase 1 & 3 = stronger signal
✓ Clear gaps between phases = stronger
✓ Higher volume on Phase 3 = more reliable
✓ Phase 3 penetrates >50% into Phase 1 = stronger
✓ At support/resistance = more reliable
"""

ax4.text(0.05, 0.95, formula_text, transform=ax4.transAxes, fontsize=10,
        verticalalignment='top', family='monospace',
        bbox=dict(boxstyle='round', facecolor='wheat', alpha=0.6))

plt.tight_layout()
display(fig)
plt.close(fig)

Three White Soldiers and Three Black Crows

The three white soldiers and three black crows are continuation patterns that show strong directional momentum over three consecutive periods.

Three White Soldiers: A bullish continuation pattern consisting of three consecutive bullish candles, each closing higher than the previous, with each candle opening within or near the previous candle's body. The pattern signals strong buying pressure and continuation of an uptrend.

The three white soldiers pattern shows strong, consistent buying pressure. Each candle closes higher than the previous, showing that buyers are in control and that the trend is strong. The pattern is particularly powerful when each candle opens within the previous candle's body (showing no gaps or rejection), when the candles have small or no shadows (showing no rejection of prices), and when volume increases on each candle (confirming buying interest).

Three Black Crows is the bearish counterpart - three consecutive bearish candles, each closing lower than the previous, signaling strong selling pressure and continuation of a downtrend.

Candlestick Pattern Reliability

Not all candlestick patterns are equally reliable. Understanding the factors that affect pattern reliability helps you focus on the most trustworthy signals and avoid false patterns.

Context is Critical: The same candlestick formation can have different meanings depending on the context. A hammer after a downtrend is a bullish reversal signal, but the same formation after an uptrend (a hanging man) is a bearish reversal signal. Understanding the prevailing trend and market context is essential for accurate pattern interpretation.

Volume Confirmation: Candlestick patterns are more reliable when confirmed by volume. A bullish engulfing pattern with high volume on the second candle is more reliable than one with low volume. Volume confirms that the pattern represents genuine market participation rather than random price movement.

Pattern Location: Patterns at key support or resistance levels are more reliable than patterns in the middle of a range. A hammer at a support level is more likely to signal a reversal than a hammer in the middle of a downtrend where support might not exist.

Multiple Pattern Confirmation: When multiple candlestick patterns confirm each other, reliability increases. For example, a doji followed by a bullish engulfing pattern provides stronger confirmation than either pattern alone.

Timeframe Considerations: Candlestick patterns on longer timeframes (daily, weekly) are generally more reliable than those on shorter timeframes (minutes, hours). However, patterns on shorter timeframes can provide valuable entry and exit points when confirmed by longer-term patterns.

Knowledge Check 8.2

A candlestick pattern appears after a strong downtrend. It has a small body at the top of the trading range, a long lower shadow (at least twice the body size), and little or no upper shadow. What pattern is this, and what does it signal?

A. Shooting star - bearish reversal
B. Hammer - bullish reversal
C. Hanging man - bearish reversal
D. Inverted hammer - bullish continuation

Click to reveal answer

B. Hammer - bullish reversal

The description matches a hammer pattern: small body at the top, long lower shadow, little or no upper shadow. When this pattern appears after a downtrend (the context), it's a hammer and signals a potential bullish reversal. If the same pattern appeared after an uptrend, it would be a hanging man (bearish reversal).

Practice Problem 8.2: Candlestick Pattern Analysis

A stock in a downtrend forms the following three-candlestick pattern:

  • First candle: Large bearish candle (opens $100, closes $95)
  • Second candle: Small candle with body at $94.50 (gaps down from first, opens $94, closes $94.50)
  • Third candle: Large bullish candle (opens $95, closes $98, gaps up from second)
  1. What pattern is this?
  2. What does it signal?
  3. What volume pattern would confirm this pattern?
  4. At what price level would you place a stop loss?
Click to reveal solution

Solution:

1. Pattern Identification:
This is a Morning Star pattern - a three-candlestick bullish reversal pattern.

2. Signal:
The pattern signals a potential reversal from bearish to bullish. The large bearish first candle shows strong selling pressure, the small second candle shows indecision and weakening selling pressure, and the large bullish third candle confirms that buyers have taken control.

3. Volume Confirmation:
The pattern would be confirmed by:

  • High volume on the first candle (strong selling pressure)
  • Lower volume on the second candle (indecision, weakening pressure)
  • High volume on the third candle (strong buying pressure confirming reversal)

4. Stop Loss Placement:
The stop loss should be placed below the low of the second candle (the small indecision candle), which would be around $94. This protects against the pattern failing if price breaks below the indecision level.


In Module 8: Technical Analysis for Equities

  1. Introduction
  2. 1. Introduction to Technical Analysis
  3. 2. Chart Patterns
  4. 3. Candlestick Patterns
  5. 4. Technical Indicators
  6. 5. Support and Resistance
  7. 6. Trend Analysis
  8. 7. Volume Analysis
  9. Advanced Technical Analysis
  10. End-of-Module Assessment