No description
Find a file
2025-11-21 21:17:03 -08:00
readme Updates 2025-11-18 20:44:05 -08:00
.gitignore first 2025-11-18 01:16:08 -08:00
analyzer.py garbage collector 2025-11-21 21:17:03 -08:00
app.py Updates 2025-11-18 20:44:05 -08:00
data_updater.log cahnges 2025-11-19 01:15:35 -08:00
data_updater.py cahnges 2025-11-19 01:15:35 -08:00
package-lock.json Updates 2025-11-18 20:44:05 -08:00
README.md more google ai changes 2025-11-21 14:14:27 -08:00
requirements.txt Updates 2025-11-18 20:44:05 -08:00


Advanced stock analysis application with automated daily data updates via Massive API (formerly Polygon) and a refined multi-stage screening system designed to identify "Elite" swing trading candidates.

🏗️ Architecture Overview

Data Flow

  1. Initial Setup: Upload d_us_txt.zip to populate database (one-time)

  2. Daily Updates: Automated data fetch from Massive API at 5:00 PM PST

  3. Analysis: Automated analysis runs at 5:01 PM PST (1 minute after data update)

  4. Multi-Stage Filtering: Stocks go through strict filters to eliminate false positives

Schedule

  • Monday-Friday: Data update at 5:00 PM PST, Analysis at 5:01 PM PST

  • Sunday: Data update at 5:00 PM PST (fetches Friday's data), Analysis at 5:01 PM PST

🚀 Setup

1. Install Dependencies

python3 -m venv venv source venv/bin/activate pip install -r requirements.txt

2. Configure Environment Variables

export SIGMA_API_TOKEN="your-secure-token-here" export MASSIVE_API_KEY="your-massive-api-key-here"

3. Initial Database Setup (One-Time)

Upload the d_us_txt.zip file to initialize the database:

curl -X POST \   -H "X-API-Token: your-secure-token-here" \   -F "file=@d_us_txt.zip" \   http://localhost:5000/upload`

4. Run Application

python app.py

The server starts on http://localhost:5000


📊 Analysis Pipeline

Stage 1: Initial Screening & Safety Checks

Basic Criteria:

  • Minimum Market Cap: $1 Billion

  • Minimum Average Volume: 2 Million shares

  • Minimum Price: $1.00

  • Trend Filter: Price must be above 200-day SMA

Edge Case Safety Filters (Automatic Rejection):

  • Extension Check: Reject if price is > 40% above 200-day SMA (Overextended/Mean Reversion Risk)

  • Parabolic Check: Reject if price gained > 30% in the last 5 days (Chasing Risk)


Stage 2: Strategy Score (Top 50% Pass)

Components (100 points total):

  1. Relative Volume (40 points max)

    • Compares current volume to 30-day average

    • 150%+ = 40 pts

    • 120-150% = 30 pts

    • 100-120% = 20 pts

    • 80-100% = 10 pts

    • <80% = 0 pts

  2. ATR - Volatility Sweet Spot (35 points max)

    • Measures daily volatility range.

    • 1.5% - 4.0% (Sweet Spot) = 35 pts (Ideal tradeable volatility)

    • > 4.0% = 20 pts (Too erratic/risky)

    • 1.0% - 1.5% = 15 pts (Moderate)

    • < 1.0% = 0 pts (Dead money)

  3. Average Volume Score (25 points max)

    • Rates liquidity scaled to 0-25 points

    • 10M+ shares = 25 pts

    • 5M+ shares = 20 pts

    • 2M+ shares = 15 pts

    • 1M+ shares = 10 pts

Threshold: Only top 50% of stocks by strategy score move forward.


Stage 3: Entry Filter (60+ Points Required)

Components (100 points total):

  1. Trend Alignment & Strength (40 points)

    • EMA Stacking (15 pts): 8-EMA > 20-EMA > 50-SMA (Bullish Alignment)

    • ADX Strength (15 pts): ADX > 20 (Confirms a true trend, not chop)

    • RSI Check (10 pts): RSI between 50 and 75 (Bullish but not overbought)

  2. Price Action & Structure (30 points)

    • Candle Position (15 pts): Close is in the top 25% of the daily high/low range.

    • Breakout Proximity (15 pts): Price is within 2% of the 20-day High.

  3. Trend Consistency (30 points)

    • Replaces "Reclaims" with "Respect".

    • Strong Hold (30 pts): Price closed above 8-EMA for ≥15 of the last 20 days.

    • Moderate Hold (15 pts): Price closed above 8-EMA for ≥10 of the last 20 days.

Threshold: Stocks need 60+ points to qualify for entry point generation.


Technical Analysis

For qualified stocks, the system calculates:

  • ADX (Average Directional Index): To ensure trend strength.

  • EMA Stacking: Verifying 8 > 20 > 50 alignment.

  • Support/Resistance: Historical pivots found via swing highs/lows.

  • Fibonacci Retracements: Automated level generation.

Entry Point Generation

For Down/Consolidating Trends (Pullbacks):

  • Entry #1: Average support retracement from highest 8-EMA

  • Entry #2: Closest Fibonacci level

  • Entry #3: Next deeper Fibonacci level

For Breakout Patterns:

  • Entry #1: Average of last 4 highs and lows

  • Entry #2: Average of last 2 highs

  • Entry #3: Highest high in last 4 days

🔌 API Endpoints

POST /upload

Initial database setup - upload d_us_txt.zip

POST /trigger-update

Manually trigger data update and analysis (useful for testing)

GET /status

Check application status and database statistics

💾 Database Schema

stocks

Main stock data with all metrics and scores

ticker TEXT PRIMARY KEY last_updated TIMESTAMP current_price REAL market_cap REAL avg_volume REAL ema_8 REAL ema_8_trend TEXT sma_200 REAL ema_20 REAL rsi REAL avg_support_retracement REAL avg_resistance_retracement REAL relative_volume REAL atr REAL avg_volume_score REAL strategy_score REAL entry_filter_score REAL passed_screening BOOLEAN passed_strategy BOOLEAN passed_entry_filter BOOLEAN

historical_supports / historical_resistances

Support/Resistance levels found in historical data pivot points.

entry_points

Calculated entry points (Price, Type, Number) for qualified stocks.

daily_data

Last 250 days of OHLC data for each stock including EMA and RSI calculations.

📝 Query Examples

Get Elite Candidates

SELECT ticker, current_price, strategy_score, entry_filter_score, rsi FROM stocks WHERE passed_entry_filter = 1 ORDER BY entry_filter_score DESC;

Get Stocks with High Strategy Score (Volatility/Volume)

SELECT ticker, strategy_score, relative_volume, atr FROM stocks WHERE passed_strategy = 1 AND atr_percent BETWEEN 1.5 AND 4.0 ORDER BY strategy_score DESC;

🔧 Troubleshooting

No Stocks Passing Filters

The v2.1 logic is stricter than previous versions to reduce false positives.

  • Check ADX: If market is choppy, few stocks will pass the ADX > 20 filter.

  • Check Extension: If the market is overextended, the "40% above 200 SMA" rule may be filtering many names.

  • Test: Lower the Entry Filter threshold in analyzer.py from 60 to 50.

Massive API Rate Limiting

The application handles rate limiting automatically (5 calls/minute for free tier).

📄 License

Proprietary - All rights reserved