Smart Money Concepts (SMC) technical analysis in Python — Market structure, order blocks, fair value gaps, BOS/CHoCH detection, visualization, and CLI support using yfinance.
📈 Smart Money Concepts (SMC) in Python
A Python package for performing Smart Money Concepts (SMC) technical analysis using historical stock data from yfinance. This framework helps traders and analysts detect market structure, order blocks, fair value gaps, BOS/CHoCH, and visualize them with matplotlib.
📊 Example Visualization
🚀 Features
✅ Market Structure Analysis — Break of Structure (BOS) & Change of Character (CHoCH) ✅ Order Blocks — Bullish & Bearish institutional zones ✅ Fair Value Gaps (FVG) — Detection with mitigation logic ✅ Equal Highs & Lows (EQH/EQL) — Potential reversal points ✅ Premium & Discount Zones — Dynamic equilibrium mapping ✅ Visualization — Candlestick charts with SMC overlays ✅ Real-time Data — Fetches from Yahoo Finance ✅ CLI Support — Batch run multiple stocks⚙️ Installation
From PyPI:
pip install smart-money-concept
From Source:
git clone https://github.com/Prasad1612/smart-money-concept.git cd smart-money-concept
Install dependencies
pip install -r requirements.txt
Install locally
pip install .
🧑💻 Usage
Python Script Example
import asyncio
from typing import List, Dict
from smartmoneyconcepts import SmartMoneyConcepts
async def main(stockcodes: List[str], period: str = "max", interval: str = "1d", batchsize: int = 10, delay: float = 2.0, visualize: bool = True): if not stock_codes: stock_codes = ["RELIANCE.NS"] # Default to NSE-listed Reliance
for i, stockcode in enumerate(stockcodes): print(f"\n==============================") print(f"🔍 Analyzing stock: {stock_code}") print(f"==============================")
smc = SmartMoneyConcepts(stockcode=stockcode, period=period, interval=interval) # Retry logic for fetching data max_retries = 3 for attempt in range(max_retries): try: success = await smc.fetch_ohlcv() if success: smc.prepare_data() smc.runsmcanalysis() if visualize: smc.visualizesmc(barsto_show=250) else: smc.printanalysissummary() # Print summary even if visualization is skipped break else: print(f"❌ Analysis failed for {stock_code}!") break except Exception as e: if "429" in str(e): # Check for rate limit error print(f"Rate limit hit for {stockcode}. Retrying ({attempt + 1}/{maxretries}) after delay...") await asyncio.sleep(5) # Wait longer for rate limit errors else: print(f"Error for {stock_code}: {e}") break if attempt == max_retries - 1: print(f"❌ Failed to fetch data for {stockcode} after {maxretries} attempts.")
# Add delay after every batch_size stocks if (i + 1) % batchsize == 0 and i + 1 < len(stockcodes): print(f"Pausing for {delay} seconds after processing {batch_size} stocks...") await asyncio.sleep(delay)
if name == "main": # Example stock list (use .NS for NSE-listed stocks, .BO for BSE, or others as needed)
# Stocks stock_codes = ["RELIANCE.NS", "TCS.NS", "INFY.NS", "HDFCBANK.NS", "ICICIBANK.NS"] # Index # stock_codes = ["^NSEI"] asyncio.run(main(stockcodes, period="1y", interval="1d", batchsize=10, delay=2.0, visualize=True))
CLI Example
python -m smartmoneyconcepts.cli --stocks ^NSEI RELIANCE.NS --period 1y --interval 1d
Options:
--stocks: List of stock codes (default: RELIANCE.NS)--period: Data period (default: 1y)--interval: Data interval (default: 1d)--batch-size: Number of stocks before pause (default: 10)--delay: Delay between batches (default: 2.0s)--no-visualize: Only print summary
📊 Example Output
- BOS / CHoCH markers on swing structures
- Bullish & Bearish Order Blocks
- Fair Value Gaps (highlighted)
- Equal Highs & Equal Lows
- Premium / Discount zones
📂 Project Structure
smart-money-concepts/
├── smartmoneyconcepts/
│ ├── init.py
│ ├── smc.py
│ ├── cli.py
├── README.md
├── requirements.txt
🙌 Credits
- Code Tech (YouTube) → This code is Take from YouTube tutorial by Code Tech, which provides a detailed walkthrough of building an SMC indicator in Python
- LuxAlgo → Inspiration from their Smart Money Concepts indicator
⚠️ Notes
- Uses
yfinance, subject to rate limits (retry logic included). - Requires an active internet connection.
- Disclaimer: Educational purposes only — not financial advice.