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.
Metadata
Release files for smart-money-concept 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| smart_money_concept-0.1.3.tar.gz | 16.1 kB | Without provenance | Details for smart_money_concept-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| smart_money_concept-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for smart_money_concept-0.1.3-py3-none-any.whl |
Total release size: 33.6 kB
Release files / smart_money_concept-0.1.3.tar.gz
| Download URL | smart_money_concept-0.1.3.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33dcf65d0f29aeba9462428c08c0d318bdd21f20971af6e5eeff51bf81946636
|
|
BLAKE2b-256 checksum How to use checksums |
bc81cb29577196167b62da168565c35f6ce77a55d50f423a78781bae1914074f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / smart_money_concept-0.1.3-py3-none-any.whl
| Download URL | smart_money_concept-0.1.3-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aeec1ac0d07ca188e7c5e199b4106dbf8155abc2f70539b51f0f2b91cae06f2c
|
|
BLAKE2b-256 checksum How to use checksums |
02f100e3eb95c11f9b6eab7e1fe07da6abc36a197980a8678f371deb1cef4aa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for smart-money-concept 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.