Skip to main content

A Python implementation of Smart Money Concepts (SMC) for technical analysis using yfinance data.

Project description

Smart Money Concepts (SMC) Python Package

A Python package for performing Smart Money Concepts (SMC) technical analysis using historical stock data from yfinance. This package provides a comprehensive framework for detecting market structures, order blocks, fair value gaps, and other SMC components, with visualization capabilities using matplotlib.


📌 Features

  • Market Structure Analysis: Detects Break of Structure (BOS) and Change of Character (CHoCH) for swing and internal structures.
  • Order Blocks: Identifies bullish and bearish order blocks for potential institutional trading zones.
  • Fair Value Gaps (FVG): Detects price imbalances with mitigation logic.
  • Equal Highs and Lows: Marks potential reversal points with Equal Highs (EQH) and Equal Lows (EQL).
  • Premium and Discount Zones: Calculates dynamic zones based on trailing extremes.
  • Visualization: Plots candlestick charts with SMC indicators (BOS, CHoCH, order blocks, FVGs, etc.) using matplotlib.
  • Real-time Data: Fetches OHLCV data from yfinance for stocks and indices.
  • Customizable Settings: Configure analysis parameters like swing length, FVG thresholds, and visualization styles (colored or monochrome).

⚙️ Installation

From PyPI (when published)

pip install smart-money-concept

📦 Requirements

  • Python 3.8+
  • yfinance>=0.2.40
  • pandas>=2.0.0
  • numpy>=1.24.0
  • matplotlib>=3.7.0

🚀 Usage

The package provides a SmartMoneyConcepts class for analyzing market data and a command-line interface (CLI) for batch processing multiple stocks.

Python Script Example

import asyncio
from typing import List, Dict
from smart_money_concepts import SmartMoneyConcepts

async def main(stock_codes: List[str], period: str = "max", interval: str = "1d", batch_size: int = 10, delay: float = 2.0, visualize: bool = True):
    if not stock_codes:
        stock_codes = ["RELIANCE.NS"]  # Default to NSE-listed Reliance

    for i, stock_code in enumerate(stock_codes):
        print(f"\n==============================")
        print(f"🔍 Analyzing stock: {stock_code}")
        print(f"==============================")

        smc = SmartMoneyConcepts(stock_code=stock_code, 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.run_smc_analysis()
                    if visualize:
                        smc.visualize_smc(bars_to_show=250)
                    else:
                        smc.print_analysis_summary()  # 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 {stock_code}. Retrying ({attempt + 1}/{max_retries}) 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 {stock_code} after {max_retries} attempts.")

        # Add delay after every batch_size stocks
        if (i + 1) % batch_size == 0 and i + 1 < len(stock_codes):
            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(stock_codes, period="1y", interval="1d", batch_size=10, delay=2.0, visualize=True))

CLI Example

python -m smart_money_concepts.cli --stocks ^NSEI RELIANCE.NS --period 1y --interval 1d

CLI Options:

  • --stocks: List of stock codes (e.g., ^NSEI, RELIANCE.NS). Default: RELIANCE.NS.
  • --period: Data period (e.g., 1d, 1mo, 1y, max). Default: 1y.
  • --interval: Data interval (e.g., 1m, 1h, 1d). Default: 1d.
  • --batch-size: Number of stocks to process before pausing. Default: 10.
  • --delay: Delay (seconds) between batches. Default: 2.0.
  • --no-visualize: Disable visualization and print analysis summary only.

📊 Example Output

The package generates a detailed analysis summary and optional visualizations, including:

  • Candlestick charts with swing and internal structure breaks (BOS/CHoCH).
  • Order blocks, fair value gaps, and equal highs/lows.
  • Premium, equilibrium, and discount zones.

📂 Project Structure

smart_money_concepts/
├── smart_money_concepts/
│   ├── __init__.py
│   ├── smc.py
│   ├── cli.py
├── README.md
├── pyproject.toml
├── requirements.txt

🙌 Credits

This project was inspired by and builds upon the following resources:

  • 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 → The conceptual framework and feature set are inspired by LuxAlgo's Smart Money Concepts indicator.

🤝 Contributing

Contributions are welcome! Please submit a pull request or open an issue on the GitHub repository for bug reports, feature requests, or improvements.


⚠️ Notes

  • Rate Limits: The package uses yfinance for data fetching, which may be subject to rate limits. Built-in retry logic handles HTTP 429 errors.
  • Internet Connection: Ensure a stable internet connection for fetching market data.
  • Disclaimer: This package is for educational purposes and should not be used as financial advice. Trading involves risks, and past performance does not guarantee future results.

📬 Contact

For questions or support, please open an issue on the GitHub repository.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smart_money_concept-0.1.3.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smart_money_concept-0.1.3-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file smart_money_concept-0.1.3.tar.gz.

File metadata

  • Download URL: smart_money_concept-0.1.3.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for smart_money_concept-0.1.3.tar.gz
Algorithm Hash digest
SHA256 33dcf65d0f29aeba9462428c08c0d318bdd21f20971af6e5eeff51bf81946636
MD5 211b3cb6eac340009881a519b7ff7be5
BLAKE2b-256 bc81cb29577196167b62da168565c35f6ce77a55d50f423a78781bae1914074f

See more details on using hashes here.

File details

Details for the file smart_money_concept-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for smart_money_concept-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aeec1ac0d07ca188e7c5e199b4106dbf8155abc2f70539b51f0f2b91cae06f2c
MD5 e82ebae9fac51b40ab204d050e10f2bc
BLAKE2b-256 02f100e3eb95c11f9b6eab7e1fe07da6abc36a197980a8678f371deb1cef4aa8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page