An intelligent stock portfolio tracker for NSE India with technical analysis, multi-strategy backtesting, and automated daily reports. Built with Next.js, MongoDB, and a curated set of technical indicators.
ShareTrack pulls daily OHLCV data from Yahoo Finance, evaluates positions against four distinct trading strategies, and surfaces actionable BUY / SELL / HOLD signals for individual stocks, full NSE indexes, or your live portfolio.
- Features
- Tech Stack
- Trading Strategies
- Project Structure
- Requirements
- Environment Setup
- Running Locally
- Docker Deployment
- API Reference
- Automated Reports (Cron)
- Scripts
- Documentation
Welcome screen with portfolio summary stats, the latest report preview, and action-required highlights. Pulls live data from your MongoDB-backed portfolio and reports collections.
Browse any major NSE index (NIFTY 50, NIFTY 100, NIFTY 500, NIFTY BANK, NIFTY IT, NIFTY PHARMA, midcap/smallcap indexes, sectoral and thematic indexes) and run all four strategies across every stock in the index. Results are rendered in a sortable/filterable AG Grid with signal badges and supporting indicator values.
Two analysis modes:
- Normal — full strategy scoring across trend-following and breakout setups
- Sideways — range-reversion strategy tuned for non-trending markets
Manually maintain holdings (symbol, quantity, average buy price, notes). Stored in MongoDB. Provides full CRUD with live P&L computed against the latest Yahoo Finance close.
Backtest all four strategies on 1 year of historical data for a single NSE index or every available index, with ₹1,00,000 starting capital per stock. Tracks:
- Total P&L (₹) and percentage return
- Win rate, false positives, false negatives
- Maximum drawdown
- Per-strategy and per-stock breakdowns
- Buy & Hold benchmark comparison
Persisted daily analysis reports stored in MongoDB. Each report records: total holdings analyzed, action-required items (STRONG SELL / SELL / LOSS ALERT / MOMENTUM), per-holding signals, RSI, and execution time. Reports can be browsed in the UI or generated on demand via a cron-triggerable endpoint.
| Layer | Technology |
|---|---|
| Framework | Next.js 15 (Pages Router) |
| UI | React 18, Bootstrap 5, React Bootstrap, Tailwind CSS 4 |
| Data Grid | AG Grid Community 33 |
| Charts | @talkrz/price-chart |
| Database | MongoDB 7 (via mongodb Node driver) |
| Market Data | Yahoo Finance public chart API, stock-nse-india |
| Indicators | technicalindicators (SMA, EMA, RSI, MACD, Bollinger Bands, Stochastic, ADX, MFI, ATR, VWAP) |
@emailjs/browser |
|
| Package Manager | Yarn (classic) |
ShareTrack evaluates each stock against four strategies. See docs/Trading_Strategies_Guide.md for the full scoring rubric.
| # | Strategy | Style | Best For |
|---|---|---|---|
| 1 | Trend-Pullback | Trend-following with pullback entries | Catching retracements in strong uptrends (50 EMA filter + Bollinger / Stochastic setup + MACD trigger + volume validation) |
| 2 | MFI Momentum Trend | Volume-weighted momentum | Buying pullbacks in uptrends using MFI(14) as a volume-weighted RSI, gated by ADX > 20 |
| 3 | Momentum Breakout (Donchian) | Breakout | 10-day high breakouts confirmed by ADX > 25, volume > 1.5× average, and RSI in the 50–70 momentum zone |
| 4 | Opening Range Breakout | Range expansion | Capturing volatility after 3-day consolidation, with VWAP confirmation and a midpoint stop loss |
All strategies use a 0–100 weighted score and emit one of STRONG BUY / BUY / HOLD / SELL / STRONG SELL. Phase 1 (trend filter) failures cap the bullish score so the engine cannot enter counter-trend positions.
ShareTrack/
├── pages/
│ ├── index.js # Dashboard
│ ├── analysis.js # NSE index analysis with all 4 strategies
│ ├── portfolio.js # Portfolio CRUD
│ ├── backtest.js # 1-year multi-strategy backtest
│ ├── reports.js # Historical reports browser
│ ├── sma-analysis.js # Standalone SMA analysis view
│ ├── nse/[id].js # Individual NSE index detail page
│ ├── stock/[id].js # Individual stock detail page
│ └── api/
│ ├── portfolio.js # GET / POST / PUT / DELETE holdings
│ ├── reports.js # GET stored reports
│ ├── analyze-portfolio.js # Run all strategies against live portfolio
│ ├── stock-data.js # Historical OHLCV (Yahoo Finance + Mongo cache)
│ ├── indicators.js # Compute technical indicators on demand
│ ├── sentiment.js # Sentiment analysis endpoint
│ ├── nse-symbols.js # NSE symbol lookup
│ ├── nse-index-stocks.js # Constituents of a given index
│ └── cron/
│ └── generate-report.js # Cron-triggerable daily report
├── components/
│ ├── Layout.js # Navbar + sidebar shell
│ ├── IndexSelector.js
│ └── StockChart.js
├── utils/
│ ├── stockData.js # All 4 strategy implementations (single source of truth)
│ ├── backtest.js # Backtest engine
│ ├── mongodb.js # Mongo connection + cached collections
│ ├── nseIndexes.js # NSE index catalog (major / sectoral / thematic)
│ ├── constants.js # NSE index slug map
│ └── dataPreprocessing.js
├── scripts/
│ └── test-db-connection.js # Standalone MongoDB connectivity check
├── docs/
│ ├── Trading_Strategies_Guide.md
│ └── Trading_Strategies_Guide.pdf
├── Dockerfile
├── docker-compose.yml
├── next.config.js
└── package.json
- Node.js v22.16.0 (newer LTS should work, but
package.jsonis pinned to the v22 line) - Yarn (classic, v1.x)
- MongoDB 7+ (local install, Docker, or MongoDB Atlas). The app degrades gracefully if Mongo is not configured — the analysis and backtest pages still work, but portfolio and reports require Mongo.
-
Copy the example env file:
cp .env.example .env.local
-
Configure the variables in
.env.local:Variable Required Description MONGODB_URIYes (for portfolio/reports) Mongo connection string — e.g. mongodb://localhost:27017/sharetrackor an Atlas SRV URIMONGODB_DBYes Database name (defaults to sharetrack)CRON_SECRETNo If set, /api/cron/generate-reportwill requirex-cron-secretheader or?secret=query paramFor Docker Compose use
MONGODB_URI=mongodb://mongodb:27017/sharetrack.
# Install dependencies
yarn install
# (Optional) Verify MongoDB connectivity
node scripts/test-db-connection.js
# Start the Next.js dev server
yarn devThe app is served at http://localhost:3000.
Other scripts:
yarn build # Production build
yarn start # Run production build
yarn lint # Next.js lintingA single command brings up MongoDB and the Next.js app together:
docker compose up --buildThis launches:
sharetrack-mongodb— MongoDB 7 on port27017, with a namedmongodb_datavolume for persistencesharetrack-web— the Next.js production server on port3000, wired to talk to the Mongo container viamongodb://mongodb:27017/sharetrack
To run only the database (e.g. for local dev against yarn dev):
docker compose up mongodbThe standalone Dockerfile is a multi-stage build (node:18-alpine builder + runner) and can be used independently in other orchestration environments.
All routes are under /api. JSON in, JSON out.
| Method | Description | Body / Query |
|---|---|---|
GET |
List all holdings | — |
POST |
Add a holding | { symbol, quantity, avgBuyPrice, notes? } |
PUT |
Update a holding | { id, symbol?, quantity?, avgBuyPrice?, notes? } |
DELETE |
Remove a holding | ?id=<ObjectId> |
Symbols are auto-uppercased. A holding for the same symbol cannot be inserted twice — use PUT instead.
| Method | Description | Query |
|---|---|---|
GET |
List recent reports | ?limit=30 |
GET |
Fetch a specific report | ?id=<ObjectId> |
Runs all four strategies against every holding using fresh 1-year Yahoo Finance data and returns per-holding signals plus an actionRequired list.
Fetches OHLCV history. Symbols default to NSE (.NS); other Yahoo Finance exchange suffixes (.BO, .L, .TO, .AX, .HK, .SI, .F, .DE, .PA) and index symbols starting with ^ are passed through unchanged. Data is cached in the stockHistoricalData Mongo collection, indexed on (symbol, date).
On-demand calculation of SMA, RSI, MACD, Bollinger Bands, ADX, Stochastic, VWAP, etc. for a given symbol/period.
/api/nse-symbols— search NSE symbols/api/nse-index-stocks?index=<INDEX_ID>— list constituents of an index/api/sentiment— sentiment scoring endpoint
/api/cron/generate-report is designed to be hit by any external scheduler — cron-job.org, GitHub Actions, Vercel Cron, or a server-side cron. It iterates over every holding, pulls 1 month of OHLCV, runs a fast SMA/RSI/volume scoring pass, and writes a report document to MongoDB.
Recommended schedule: 9:00 AM IST (before the NSE opens at 09:15).
Example:
curl -X POST https://your-host/api/cron/generate-report \
-H "x-cron-secret: $CRON_SECRET"Or with a query string:
curl "https://your-host/api/cron/generate-report?secret=$CRON_SECRET"If CRON_SECRET is not set in the environment, the endpoint is open (useful for local testing).
Each generated report flags any of:
STRONG SELL/SELLsignalsLOSS ALERTfor positions down more than 10%MOMENTUMforSTRONG BUYsignals on already-profitable positions
The actionRequiredCount surfaces on the dashboard so you see what needs attention at a glance.
-
scripts/test-db-connection.js— quick standalone connectivity check againstMONGODB_URI. Loads.env.local(falling back to.env), pings the database, lists collections, and prints Atlas-specific hints if authentication fails (code8000).node scripts/test-db-connection.js
docs/Trading_Strategies_Guide.md— full scoring rubric for all four strategies, indicator periods, benchmark methodology, and backtest metric definitionsdocs/Trading_Strategies_Guide.pdf— PDF version of the same guide