A Python package for Smart Money Concepts (SMC) analysis and stock screening
Project description
SMC Screener ๐
A Python package for Smart Money Concepts (SMC) analysis and stock screening, designed to identify key market levels such as swing highs/lows, order blocks, fair value gaps (FVGs), and premium/discount zones.
Features โจ
- SMC Analysis: Identifies swing highs/lows, order blocks, FVGs, and market structure breaks using
yfinancedata. ๐ - Stock Screener: Screens stocks near key SMC levels based on a proximity percentage. ๐
- Visualization: Generates candlestick charts with SMC levels using
matplotlib. ๐ - Output Options: Saves results to CSV files and/or Google Sheets. ๐๐
- Interactive CLI: Choose tasks (analysis, screener, or both) and stock lists (e.g., Nifty 50, F&O). ๐ฅ๏ธ
Installation ๐
-
Install via pip:
pip install smc-screener
Note: The package is not yet on PyPI. To install locally, use the wheel file (see Development Setup ๐ ๏ธ).
-
Install Dependencies: The package requires the following Python libraries:
yfinance>=0.2.44pandas>=2.2.2numpy>=1.26.4matplotlib>=3.9.2gspread>=6.1.2(optional, for Google Sheets)oauth2client>=4.1.3(optional, for Google Sheets)tqdm>=4.66.5
Install them manually if needed:
pip install yfinance pandas numpy matplotlib gspread oauth2client tqdm
-
Google Sheets Setup (optional, for
output_format="google_sheets"or"both") ๐:- Create a Google Cloud project and enable the Google Sheets API and Google Drive API. ๐ง
- Create a service account and download the JSON credentials file. ๐
- Save the JSON file as
Credentials/credentials.jsonin your project directory. - Share your Google Sheet with the service accountโs email (found in the JSON file) with edit access.
- Update the
spreadsheet_idinmain_pipeline.pywith your Google Sheet ID (from the URL:https://docs.google.com/spreadsheets/d/<SPREADSHEET_ID>/edit).
Usage ๐ ๏ธ
Command-Line Interface
Run the package directly from the command line:
smc-screener
This launches an interactive CLI where you can:
- Select a task: SMC Analysis, SMC Screener, or both. ๐
- Choose a stock list: Nifty Top 10, Nifty 50, F&O, or Nifty 500. ๐
Example interaction:
Select the task to run:
1. SMC Analysis
2. SMC Screener
3. Both (Analysis + Screener)
Enter your choice (1, 2, or 3): 3
Select the stock list to process:
1. Nifty Top 10
2. Nifty 50
3. F&O
4. Nifty 500
Enter your choice (1, 2, 3, or 4): 1
Selected stock list: Nifty Top 10 (10 stocks)
Step 1: Running SMC Analysis... ๐
Step 2: Running SMC Screener... ๐
Task 'both' completed for Nifty Top 10! ๐
nifty_500 = ["360ONE.NS", "ABB.NS", "APLAPOLLO.NS"] # add more stocks here
Programmatic Usage
Run the pipeline programmatically:
import asyncio
import os
from smc_trading.smc_analysis import main as main_analysis
from smc_trading.smc_screener import main as main_screener
async def run_full_pipeline():
# Create analysis directory
os.makedirs("analysis", exist_ok=True)
# Define stock code lists for each option
indices = ["^NSEI", "^NSEBANK", "^CNXIT", "^CNXAUTO", "^CNXFMCG", "^CNXMETAL", "^CNXPHARMA", "^CNXREALTY", "^CNXENERGY", "^CNXMEDIA"]
nifty_top_10 = ["HDFCBANK.NS", "ICICIBANK.NS", "RELIANCE.NS", "INFY.NS", "BHARTIARTL.NS", "LT.NS", "ITC.NS", "SBIN.NS", "AXISBANK.NS", "TCS.NS"]
nifty_50 = ["360ONE.NS", "ABB.NS", "APLAPOLLO.NS"] # add more stocks here
fn_o_stocks = ["360ONE.NS", "ABB.NS", "APLAPOLLO.NS"] # add more stocks here
nifty_500 = ["360ONE.NS", "ABB.NS", "APLAPOLLO.NS"] # add more stocks here
csv_column_mapping = {
'OPEN_PRICE': 'open',
'HIGH_PRICE': 'high',
'LOW_PRICE': 'low',
'CLOSE_PRICE': 'close',
'DATE1': 'Date'
}
spreadsheet_id = "YOUR_SPREADSHEET_ID" # Replace with your Sheet ID
csv_directory = "Stocks"
fetch_csv_data = False
period = "max" # "1d", "5d", "1mo", "3mo", "6mo", "1y", "2y","5y", "10y", "ytd", "max"
interval = "1d" # "1m", "2m", "5m", "15m", "30m", "60m"/"1h", "90m", "1d", "5d", "1wk", "1mo", "3mo"
auto_adjust = False # Raw prices โ unadjusted for splits/dividends.
batch_size = 10 # Stocks per batch in analysis to manage yfinance API limits.
delay = 2.0 # Seconds to pause between batches to avoid rate limits.
visualize = False # If True, plots SMC charts; False skips to save time.
print_details = False # If True, logs detailed analysis/screener info; False for minimal output.
output_format = "csv" # Save to csv, google_sheets, or both for analysis and screener results.
clear = True # Clears existing CSVs and Google Sheets before saving new data.
use_colab = False # if goole colab use True otherwise False
distance_percentage = 2.0 # % threshold for screener to find stocks near SMC levels.
output_csv = "screener_results.csv" # File path for screener results CSV.
while True:
print("\n๐ Select the task to run:")
print(" 1๏ธโฃ SMC Analysis")
print(" 2๏ธโฃ SMC Screener")
print(" 3๏ธโฃ Both (Analysis + Screener)")
print(" 0๏ธโฃ Exit")
try:
task_choice = input("\n๐ Enter your choice (1, 2, 3, or 0 to exit): ").strip().lower()
if task_choice in ["1", "2", "3"]:
break
elif task_choice == "0" or task_choice == "exit":
print("\n๐ Exiting program.")
return
print("โ Invalid choice. Please enter 1, 2, 3, or 0.")
except KeyboardInterrupt:
print("\n๐ Exiting program.")
return
# Map task
task = {"1": "analysis", "2": "screener", "3": "both"}[task_choice]
stock_codes, stock_list_name = None, None
# Only ask stock list if Analysis or Both is selected
if task in ["analysis", "both"]:
while True:
print("\n๐ Select the stock list to process:")
print(" 1๏ธโฃ Nifty Top 10")
print(" 2๏ธโฃ Nifty 50")
print(" 3๏ธโฃ F&O")
print(" 4๏ธโฃ Nifty 500")
print(" 5๏ธโฃ Indices")
print(" 0๏ธโฃ Back to task selection")
try:
stock_choice = input("\n๐ Enter your choice (1, 2, 3, 4, 5, or 0 to go back): ").strip().lower()
if stock_choice in ["1", "2", "3", "4", "5"]:
break
elif stock_choice == "0" or stock_choice == "exit":
print("\n๐ Returning to task selection.")
return await run_full_pipeline() # Go back to task selection
print("โ Invalid choice. Please enter 1, 2, 3, 4, 5, or 0.")
except KeyboardInterrupt:
print("\n๐ Exiting program.")
return
# Map stock list
stock_codes = {
"1": nifty_top_10,
"2": nifty_50,
"3": fn_o_stocks,
"4": nifty_500,
"5": indices
}[stock_choice]
stock_list_name = {
"1": "Nifty Top 10",
"2": "Nifty 50",
"3": "F&O",
"4": "Nifty 500",
"5": "Indices"
}[stock_choice]
print(f"\nโ
Selected Stocks or Indices list: *{stock_list_name}* ({len(stock_codes)} No. of Stocks or Indices)")
# Execute selected task(s)
if task in ["analysis", "both"]:
print("\n๐ Running SMC Analysis...")
await main_analysis(
stock_codes = stock_codes,
csv_directory = csv_directory,
fetch_csv_data = fetch_csv_data,
csv_column_mapping = csv_column_mapping,
spreadsheet_id = spreadsheet_id,
period = period,
interval = interval,
auto_adjust = auto_adjust,
batch_size = batch_size,
delay = delay,
visualize = visualize,
print_details = print_details,
clear = clear,
output_format = output_format,
use_colab = use_colab
)
print("๐ Analysis completed successfully!")
if task in ["screener", "both"]:
print("\n๐ Running SMC Screener...")
main_screener(
proximity_percentage = distance_percentage,
output_csv = output_csv,
spreadsheet_id = spreadsheet_id,
output_format = output_format,
clear = clear,
print_details = print_details,
use_colab = use_colab
)
print("๐ Screener completed successfully!")
# Final message
if stock_list_name:
print(f"\n๐ฏ Task *{task.upper()}* completed for *{stock_list_name}*! ๐")
else:
print(f"\n๐ฏ Task *{task.upper()}* completed successfully! ๐")
# โ
CLI entry point wrapper
def main():
asyncio.run(run_full_pipeline())
if __name__ == "__main__":
main()
Customizing Parameters
Edit main_pipeline.py to customize:
- Stock Lists: Modify
nifty_top_10,nifty_50,fn_o_stocks, ornifty_500. ๐ - Period/Interval: Change
period(e.g.,"1y","max") andinterval(e.g.,"1d","1h") foryfinancedata. โณ - Output Format: Set
output_formatto"csv","google_sheets", or"both". ๐ - Proximity Percentage: Adjust
proximity_percentage(default2.0) for the screener. ๐ - Visualization: Set
visualize=Truefor charts orFalsefor faster execution. ๐ - Clear Output: Set
clear=Trueto overwrite existing CSV files or Google Sheets. ๐๏ธ
Output ๐
- SMC Analysis:
- CSV: Saves to
analysis/smc_analysis_summaries.csv(summary data) andanalysis/smc_analysis_levels.csv(key levels). ๐ - Google Sheets: Saves to
SummariesandLevelsworksheets (if enabled). ๐ - Visualization: Candlestick charts with SMC levels (if
visualize=True). ๐
- CSV: Saves to
- SMC Screener:
- CSV: Saves to
screener_results.csvwith stocks near SMC levels. ๐ - Google Sheets: Saves to
Screener_Resultsworksheet (if enabled). ๐ - Console: Displays a table of stocks near key levels. ๐ฅ๏ธ
- CSV: Saves to
Project Structure ๐ ๏ธ
smc_trading/
โโโ smc_trading/
โ โโโ __init__.py
โ โโโ smc_analysis.py
โ โโโ smc_screener.py
โ โโโ main_pipeline.py
โโโ Credentials/
โ โโโ credentials.json
โโโ pyproject.toml
โโโ README.md
โโโ LICENSE
โโโ requirements.txt
yfinance Period & Interval Reference ๐
- Period:
"1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max" - Interval:
"1m","2m","5m","15m","30m","60m","90m","1h","1d","5d","1wk","1mo","3mo" - Restrictions:
"1m"interval: Only last 7 days max.- Intraday intervals (
"1m","1h", etc.):period โค 60d. - Daily/weekly/monthly: Longer periods allowed.
Troubleshooting ๐
- yfinance Rate Limits: Reduce
batch_sizeor increasedelayinmain_pipeline.py. ๐ - Google Sheets Errors: Verify
Credentials/credentials.jsonand share the Google Sheet with the service account. ๐ - No Data: Check ticker validity (e.g.,
RELIANCE.NS). Useyf.Ticker("TICKER").infoto verify. ๐ - Visualization Issues: Ensure
matplotlibis installed andvisualize=True. ๐ - Screener Empty: Run SMC Analysis first to generate
smc_analysis_levels.csvandsmc_analysis_summaries.csv. ๐
License ๐
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing ๐ค
Contributions are welcome! Please submit a pull request or open an issue on the repository.
Happy trading! ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smc_screener-0.0.8.tar.gz.
File metadata
- Download URL: smc_screener-0.0.8.tar.gz
- Upload date:
- Size: 28.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e287f3e1c941f385ef553a77ac96dc6ad7a2d7f720405d887e54e9b3baef17b3
|
|
| MD5 |
5da8a33579c9d050a3d6eec2696763f3
|
|
| BLAKE2b-256 |
6551d5395325a8989fce09dd910e7b6dec87f548fcb10fc0678e0f81a76b8b1f
|
File details
Details for the file smc_screener-0.0.8-py3-none-any.whl.
File metadata
- Download URL: smc_screener-0.0.8-py3-none-any.whl
- Upload date:
- Size: 29.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ab98dd70f474b112489bc1732adc53ef99c941c5eb4c9366941922170405acc
|
|
| MD5 |
aaa5d0180d4aaac1b9dfa64d2352ffd0
|
|
| BLAKE2b-256 |
565916b840150d306088cad2b2c2e90c669888a9eb5bc6e4abff42d04bfaee5a
|