An end-to-end algorithmic trading prototype built with Python, powered by RSI + DMA strategy, enhanced with ML predictions, Google Sheets P&L tracking, Groq commentary, and Telegram alerts β all wrapped in a stylish Flask UI.
| Component | Stack / Tool |
|---|---|
| Strategy Logic | RSI + 20DMA / 50DMA Crossover |
| ML Model | Scikit-Learn (Decision Tree) |
| Stock Data | Yahoo Finance via yfinance |
| Automation | Python + Flask |
| Logging & P&L | Google Sheets API + GCP Service |
| Alerts | Telegram Bot API |
| Commentary | Groq API (LLaMA3-70B Instruct) |
| UI | HTML5 + CSS3 (Glassmorphism style) |
This project implements a hybrid technical + rule-based strategy:
-
β Buy Signal Conditions:
- RSI < 30 (oversold)
- 20DMA crosses above 50DMA
- Optional relaxed condition: RSI < 50 + 20DMA > 50DMA (for testing)
-
β Backtest Window:
- Last 6 months (
period='6mo') using daily candles (interval='1d')
- Last 6 months (
-
β Backtest Output:
- Total Trades
- Win Count / Loss Count
- Win Ratio
- Total P&L
- Model:
DecisionTreeClassifier - Features Used:
- RSI
- 20DMA
- 50DMA
- MACD
- Volume
- Target: Whether next-day close is higher than todayβs close
- Train/Test Split: 80/20
- Accuracy Output is displayed on the UI
Trade and summary logs are stored live using:
- π A
creds.jsonfile (GCP Service Account key) - π Trade logs go to
Trade_Logsheet - π Summary stats go to
Summarytab with:- Date
- Total Trades
- Wins / Losses
- Win Ratio
- P&L
Libraries Used:
gspreadoauth2client
Each trade signal is pushed via Telegram Bot API in real-time:
- Uses:
requests.postto the Telegram API - Requires:
TELEGRAM_BOT_TOKENTELEGRAM_CHAT_ID
Youβll get alerts like:
π’RELIANCE.NS BUY at 2953.25
Each trading cycle ends with Groq LLaMA3-based summarization:
- Model:
llama3-70b-8192 - API:
https://api.groq.com/openai/v1/chat/completions - Output: Smart summary of the dayβs trade signals
Example:
βToday, RELIANCE and TCS showed promising RSI-based buy signals supported by DMA crossovers. INFY remained neutral.β
- Responsive, animated UI
- Glassmorphism cards
- Color-coded trade signals
- Display of:
- Trade Signal Table
- ML Model Accuracy
- Groq Commentary
UI styled using custom CSS with:
backdrop-filter+-webkit-backdrop-filterfor Safari support- Neon headings
- Card animations and hover effects
β βββ app.py # Flask server βββ strategy.py # RSI + DMA logic βββ ml_model.py # Decision Tree model βββ data_fetcher.py # Yahoo Finance fetcher βββ telegram_alert.py # Sends alerts βββ groq_commentary.py # Groq LLM summary βββ google_sheets.py # Google Sheets logging via GCP
β βββ static/ β βββ style.css # UI styling (glassmorphism) β
βββ templates/ β βββ index.html # Frontend dashboard β
βββ creds.json # GCP service account key βββ .env # Secrets (API keys, tokens)
Create a .env file with:
GROQ_API_KEY=your_groq_api_key
GOOGLE_SHEET_NAME=YourSheetName
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id# Step 1: Install dependencies
pip install -r requirements.txt
# Step 2: Run the Flask app
python app.py
# Visit the dashboard at:
http://localhost:5000## πΉ Demo Videos
| Demo Type | Link |
|--------------------------|------------------------------|
| π½οΈ Strategy & Code Flow | [Watch on Google Drive](#) |
| π Output + Google Sheets | [Watch on Google Drive](#) |
- β RSI + DMA strategy logic
- β 6-month backtesting
- β Decision Tree prediction
- β Google Sheets automation
- β Telegram alerts
- β Groq-generated insights
- β Modern web UI
- β Modular, well-documented code
Shrutakeerti β For any updates please contract through the given links π GitHub Β Β π¬ Telegram Β Β πΌ LinkedIn
MIT License β use this as a template, study tool, or launchpad for your own bots.
βSystems trade logic. Traders trade emotion. Bots donβt care.β