Intro to Data Visualization
  • Introduction
  • Getting started
    • Introduction to Pandas
    • Accessing Files on Colab
    • Reviewing Data
      • Understanding type(data) in Pandas
    • Data Types
      • Categorical Data
      • Numeric Data
      • Temporal Data
      • Geographic Data
    • How to Check Data Type
    • Slicing and Subsetting DataFrames
    • Aggregating Data
  • Visualization Types
    • Exploratory Process
    • Explanatory Process
  • data exploration
    • Exploration Overview
    • Exploration with Plotly
      • Exploring Distributions
      • Exploring Relationships
      • Exploring with Regression Plots
      • Exploring Correlations
      • Exploring Categories
      • Exploring Time Series
      • Exploring Stocks with Candlestick
      • Exploring with Facets
      • Exploring with Subplots
    • Exploring with AI
  • Data Explanation
    • Data Explanation with Plotly
      • Using Text
      • Using Annotations
      • Using Color
      • Using Shape
      • Accessibility
      • Using Animations
    • Use Cases
  • Exercises and examples
    • Stock Market
      • Loading Yahoo! Finance Data
      • Use Cases for YF
      • Exploring YF Data
      • Understanding Boeing Data Over Time
      • Polishing the visualization
      • Analyzing with AI
      • Comparisons
    • The Gapminder Dataset
      • Loading the Gapminder Data
      • Use Cases
      • Exploring the Data
      • Exporting a Static Image
Powered by GitBook
On this page
  1. data exploration
  2. Exploration with Plotly

Exploring Stocks with Candlestick

Candlestick charts are a popular tool in financial markets for analyzing price movements and trends in stocks, currencies, and commodities. Unlike simple line or bar charts, candlestick charts display four key data points for a specific time period: the opening price, closing price, highest price, and lowest price. This additional detail allows traders to better understand market sentiment and potential price reversals. Each candlestick consists of a body, which represents the range between the opening and closing prices, and wicks (or shadows) that show the high and low price extremes. The color of the candlestick body (commonly green for upward movement and red for downward movement) provides a visual indication of whether the price closed higher or lower than it opened, making it easier to identify bullish or bearish trends.

To interpret candlestick charts effectively, traders analyze both individual candlestick patterns and sequences of candlesticks. Single candlesticks, such as "doji," "hammer," or "inverted hammer," can signal indecision, reversals, or support/resistance levels. Meanwhile, patterns like "bullish engulfing," "morning star," or "head and shoulders" often indicate larger market trends and potential breakouts. For instance, a "hammer" candlestick with a small body and long lower wick at the end of a downtrend may suggest a reversal to the upside, as buyers have regained control. Conversely, a "shooting star" with a long upper wick at the end of an uptrend could indicate a bearish reversal. By combining candlestick patterns with other technical indicators, such as moving averages or RSI (Relative Strength Index), traders can make more informed decisions about entry and exit points in the market.

Let's get started with candlestick plots. Here is the code to create a candlestick chart of Apple stock prices in Jan 2017.

import plotly.graph_objects as go
import pandas as pd

# Download Apple Stock Prices in 2015-2017
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')

# Restrict the data to January 2017
df = df[df['Date'] >= '2017-01-01']
df = df[df['Date'] <= '2017-02-01']

# Plot the Candlestick chart
fig = go.Figure(data=[go.Candlestick(x=df['Date'],
                open=df['AAPL.Open'], high=df['AAPL.High'],
                low=df['AAPL.Low'], close=df['AAPL.Close'])
                     ])

# Update the layout. The xaxis_rangeslider_visible is the option to 
# remove the range chart at the bottom of the candlestick chart.
fig.update_layout(xaxis_rangeslider_visible=False,
                  title='Apple Stock: January 2017')
fig.show()
PreviousExploring Time SeriesNextExploring with Facets

Last updated 3 months ago

For additional information, go to the Plotly documentation on candlestick charts:

https://plotly.com/python/candlestick-charts/