Back to Algo Days
2
Fundamentals12 min read

Market Data
& OHLCV

Before you can trade algorithmically, you need to understand the language of markets. Learn how price data is structured and how to read candlestick charts.

What is OHLCV Data?

OHLCV stands for Open, High, Low, Close, Volume - the five essential pieces of information that describe trading activity over a specific time period.

Whether you're looking at a 1-minute chart or a weekly chart, each "candle" or "bar" represents these five data points for that timeframe.

O

Open

The first traded price when the period began

H

High

The highest price reached during the period

L

Low

The lowest price during the period

C

Close

The last traded price before period ended

V

Volume

Total quantity of shares/contracts traded

Anatomy of a Candlestick

Candlestick charts visualize OHLCV data. Each candle tells a story about the battle between buyers and sellers.

Bullish Candle (Green)

CloseOpen
High
Low
  • • Close is higher than Open
  • • Shows buyers dominated the period
  • • Body represents price gain
  • • Upper wick: High − Close
  • • Lower wick: Open − Low

Bearish Candle (Red)

OpenClose
High
Low
  • • Close is lower than Open
  • • Shows sellers dominated the period
  • • Body represents price drop
  • • Upper wick: High − Open
  • • Lower wick: Close − Low

Pro Tip

The size of the body shows the strength of the move. A long body = strong conviction. A short body = indecision. Long wicks show rejection at those price levels.

Timeframes Explained

OHLCV data is available in many timeframes. Each timeframe serves different trading styles:

TimeframeUse CaseTrading Style
1m, 5m, 15mIntraday moves, quick entriesScalping / Day Trading
1H, 4HIntraday trends, key levelsDay / Swing Trading
DailyOverall trend directionSwing Trading
Weekly, MonthlyLong-term trends, major levelsPosition Trading

Why Volume Matters

Volume is the most underrated piece of OHLCV data. It tells you the conviction behind price moves.

High Volume + Price Up

Strong bullish signal. Many buyers are entering. Trend likely to continue.

High Volume + Price Down

Strong bearish signal. Selling pressure is high. Trend likely to continue.

Low Volume + Price Up

Weak rally. Few participants. Move may reverse or lack follow-through.

Low Volume + Price Down

Weak selling. Could be profit-taking. Not a strong bearish signal.

Golden Rule

Volume confirms price. A big price move on low volume is suspicious. A big price move on high volume is significant.

Fetching OHLCV Data with Python

Let's write real Python code to fetch and visualize OHLCV data using the popular yfinance library.

python|fetch_ohlcv.py
# Install: pip install yfinance pandas matplotlib

import yfinance as yf
import pandas as pd

# Fetch historical data for Reliance Industries
ticker = "RELIANCE.NS"  # .NS for NSE stocks
df = yf.download(ticker, period="3mo", interval="1d")

# Display the OHLCV data
print("\n📊 OHLCV Data for RELIANCE")
print("=" * 50)
print(df.head(10))

# Basic statistics
print("\n📈 Quick Stats:")
print(f"Highest Price: ₹{df['High'].max():.2f}")
print(f"Lowest Price:  ₹{df['Low'].min():.2f}")
print(f"Avg Volume:    {df['Volume'].mean():,.0f} shares/day")

Here's the output you'll see:

output|Output
📊 OHLCV Data for RELIANCE
==================================================
                 Open       High        Low      Close  Adj Close     Volume
Date                                                                        
2024-09-24  2961.0000  2974.8999  2938.1001  2971.3000  2971.3000   10234567
2024-09-25  2975.0000  2989.0000  2960.0000  2982.5000  2982.5000    8765432
2024-09-26  2980.0000  3010.0000  2975.0000  3005.2000  3005.2000   12345678
...

📈 Quick Stats:
Highest Price: ₹3045.80
Lowest Price:  ₹2875.00
Avg Volume:    9,876,543 shares/day

Plotting Candlestick Charts

Now let's create a professional candlestick chart using mplfinance:

python|plot_candlestick.py
# Install: pip install mplfinance

import yfinance as yf
import mplfinance as mpf

# Fetch data
ticker = "RELIANCE.NS"
df = yf.download(ticker, period="2mo", interval="1d")

# Create candlestick chart with volume
mpf.plot(
    df,
    type='candle',           # Candlestick chart
    style='nightclouds',     # Dark theme
    title=f'{ticker} - Daily Chart',
    ylabel='Price (₹)',
    ylabel_lower='Volume',
    volume=True,             # Show volume bars
    figsize=(12, 8),
    mav=(20, 50),            # 20 & 50-day moving averages
    savefig='reliance_chart.png'  # Save the chart
)

print("✅ Chart saved as reliance_chart.png")

What This Code Creates

  • • Professional candlestick chart with OHLC data
  • • Volume bars at the bottom
  • • 20-day and 50-day moving averages overlaid
  • • Dark theme for easy reading

Working with OHLCV in Code

Here's how to access and manipulate OHLCV data programmatically:

python|ohlcv_operations.py
import yfinance as yf
import pandas as pd

# Fetch data
df = yf.download("RELIANCE.NS", period="1mo")

# Access today's data (last row)
latest = df.iloc[-1]
print(f"Today's Open:  ₹{latest['Open']:.2f}")
print(f"Today's High:  ₹{latest['High']:.2f}")
print(f"Today's Low:   ₹{latest['Low']:.2f}")
print(f"Today's Close: ₹{latest['Close']:.2f}")
print(f"Today's Volume: {latest['Volume']:,.0f}")

# Calculate daily returns
df['Returns'] = df['Close'].pct_change() * 100
print(f"\nAverage Daily Return: {df['Returns'].mean():.2f}%")

# Find biggest up day
biggest_gain = df['Returns'].idxmax()
print(f"Biggest Up Day: {biggest_gain.strftime('%Y-%m-%d')} (+{df.loc[biggest_gain, 'Returns']:.2f}%)")

# Calculate daily range (volatility indicator)
df['Range'] = df['High'] - df['Low']
print(f"Average Daily Range: ₹{df['Range'].mean():.2f}")

# Identify high-volume days (2x average)
avg_volume = df['Volume'].mean()
high_vol_days = df[df['Volume'] > avg_volume * 2]
print(f"\nHigh Volume Days: {len(high_vol_days)}")

Key Takeaways

  • OHLCV = Open, High, Low, Close, Volume - the 5 pillars of price data
  • Candlesticks visualize OHLCV - green (bullish) vs red (bearish)
  • Body shows open/close range; wicks show high/low extremes
  • Volume confirms price - high volume = strong conviction
  • Use yfinance (Python) to fetch real market data for free
  • Use mplfinance to create professional candlestick charts