Skip to content

codebytelabs/DayTraderAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 DayTraderAI

Institutional-Grade Algorithmic Day Trading System

A sophisticated, fully autonomous trading platform combining real-time technical analysis, AI-powered validation, and professional risk management. Built with 20+ specialized modules working in harmony to execute high-probability trades with surgical precision.

Python FastAPI React Alpaca


📊 Live Performance (December 2025)

Metric Current Target
Win Rate 65-70% 70%+
Avg Winner +2.2R +2.0R
Avg Loser -0.8R -1.0R
Profit Factor ~2.8 2.5+
Sharpe Ratio 2.8+ 2.5+
Max Drawdown <2% <5%

🏗️ System Architecture

Core Components

┌─────────────────────────────────────────────────────────────────────┐
│                         DAYTRADERAI ENGINE                          │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐             │
│  │   Market    │───▶│   Feature   │───▶│  Strategy   │             │
│  │    Data     │    │   Engine    │    │   Engine    │             │
│  │  (Alpaca)   │    │ (50+ Indic) │    │ (EMA/RSI)   │             │
│  └─────────────┘    └─────────────┘    └──────┬──────┘             │
│                                               │                     │
│  ┌─────────────┐    ┌─────────────┐    ┌──────▼──────┐             │
│  │   Regime    │───▶│    Risk     │───▶│   Order     │             │
│  │  Manager    │    │   Manager   │    │  Manager    │             │
│  │ (Fear/Greed)│    │ (Sizing)    │    │ (Execution) │             │
│  └─────────────┘    └─────────────┘    └──────┬──────┘             │
│                                               │                     │
│  ┌─────────────┐    ┌─────────────┐    ┌──────▼──────┐             │
│  │   Profit    │◀───│  Position   │◀───│   Smart     │             │
│  │ Protection  │    │   Manager   │    │  Executor   │             │
│  │ (R-Multiple)│    │ (Tracking)  │    │ (Fill Det.) │             │
│  └─────────────┘    └─────────────┘    └─────────────┘             │
│                                                                     │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐             │
│  │  Stop Loss  │    │  Momentum   │    │     ML      │             │
│  │ Protection  │    │   Scanner   │    │ Shadow Mode │             │
│  │ (5s checks) │    │ (Wave Rider)│    │ (Learning)  │             │
│  └─────────────┘    └─────────────┘    └─────────────┘             │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Module Breakdown

Layer Module Purpose
Data market_data.py Real-time bars from Alpaca WebSocket
Data features.py 50+ technical indicators (EMA, RSI, MACD, VWAP, etc.)
Data daily_cache.py Twelve Data API for daily charts
Indicators fear_greed_scraper.py CNN Fear & Greed Index (0-100)
Indicators vix_fetcher.py VIX volatility monitoring
Indicators market_regime.py Market breadth analysis
Trading strategy.py EMA crossover signals with multi-factor confirmation
Trading risk_manager.py Dynamic position sizing, circuit breakers
Trading order_manager.py Order routing and bracket management
Trading position_manager.py Position tracking, trailing stops, partial profits
Trading regime_manager.py Fear/Greed regime adaptation
Trading momentum_confirmed_regime.py Triple-layer regime intelligence
Trading stop_loss_protection.py 5-second stop verification
Trading profit_protection/ R-multiple tracking, 2R/3R/4R profit taking
Orders smart_order_executor.py Slippage protection, fill detection
Orders fill_detection_engine.py Multi-method fill verification
Scanner momentum_scanner.py Momentum Wave Rider system
Scanner opportunity_scanner.py Technical opportunity detection
ML shadow_mode.py Zero-impact learning system
Advisory perplexity.py AI market research
Advisory openrouter.py Multi-model AI (DeepSeek, Grok)

⚡ How It Works

1. Signal Generation (Real-Time)

# backend/data/features.py generates signals every minute
Signal: SELL NVDA
├── EMA9: $183.32 crosses below EMA21: $183.60
├── RSI: 32.7 (bearish)
├── MACD: Bearish crossover
├── Volume: 1.50x average (confirmed)
├── VWAP: Price below VWAP (aligned)
└── Confidence: 74%

2. Regime-Adaptive Filtering

# backend/trading/strategy.py validates signals
Fear & Greed Index: 27/100 (FEAR regime)
├── Short in fear? Requires 3+ confirmations ✓
├── RSI > 25? Checking for oversold bounce risk
├── Confidence > 70%? Required in fear environment
└── Result: Signal APPROVED or REJECTED

3. Risk Management

# backend/trading/risk_manager.py calculates position size
Risk Multipliers:
├── Confidence (74%): 1.0x
├── Safety Score: 1.00x
├── Sentiment (27): 0.80x (reduced in fear)
├── Trend: 1.00x
├── Combined: 0.80x
└── Final Risk: 0.80% of equity

4. Smart Order Execution

# backend/orders/smart_order_executor.py
Order: SELL 55 NVDA @ $182.25
├── Slippage buffer: +0.3%
├── Stop Loss: $184.43 (1.5% from entry)
├── Take Profit: $176.25 (2:1 R/R)
├── Fill detection: 30-second timeout
└── Bracket orders: Created automatically

5. Profit Protection (Continuous)

# backend/trading/position_manager.py monitors positions
Position: NVDA @ +2.22R
├── State: PARTIAL_PROFIT_TAKEN
├── Action: Take 50% profits (27 shares)
├── Remaining: 28 shares with trailing stop
├── Stop updated: $184.96 → $181.90
└── R-multiple logged to Supabase

6. Stop Loss Protection (Every 5 Seconds)

# backend/trading/stop_loss_protection.py
Position Check: NVDA
├── Has active stop loss? NO
├── Action: Creating emergency bracket
├── Stop: $184.96 (1.5% from entry)
├── Take Profit: $177.67 (2:1 R/R)
└── Result: Position PROTECTED

🎯 Key Features

Momentum-Confirmed Regime System

  • Triple Intelligence: Fear & Greed + Momentum Strength + VIX
  • Dynamic Sizing: 0.8x in fear, 1.0x neutral, 1.2x in greed
  • VIX Caps: Automatic risk reduction when VIX > 30

Intelligent Profit Protection

  • R-Multiple Tracking: Every position measured in risk units
  • Partial Profits: 50% at 2R, scale out at 3R/4R
  • Breakeven Protection: Stop moved to entry at 1R
  • Trailing Stops: 1% trailing distance locks profits

Smart Signal Filtering

  • Oversold Bounce Rejection: RSI < 25 in fear = no shorts
  • Confidence Requirements: 70%+ needed in fear environment
  • Multi-Factor Confirmation: EMA + RSI + MACD + Volume + VWAP

Self-Healing Architecture

  • 5-Second Stop Verification: No position left unprotected
  • Orphan Order Cleanup: Stale orders removed automatically
  • Emergency Stops: Created for any unprotected position
  • Database Sync: Crash-resistant state management

🛠️ Tech Stack

Backend

  • Python 3.10+ - Core trading logic
  • FastAPI - High-performance async API
  • Alpaca Markets - Commission-free trading API
  • Supabase - Real-time database (PostgreSQL)
  • WebSockets - Live market data streaming

Frontend

  • React 18 - Modern UI framework
  • TypeScript - Type-safe development
  • Tailwind CSS - Utility-first styling
  • Vite - Fast build tooling

AI/ML

  • DeepSeek V3 - Trade validation
  • Perplexity Sonar - Market research
  • Grok 4 - Copilot chat
  • ML Shadow Mode - Learning system (0% weight)

🚀 Quick Start

1. Clone & Install

git clone https://github.com/codebytelabs/DayTraderAI.git
cd DayTraderAI

# Backend
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Frontend
cd ../frontend
npm install

2. Configure Environment

# backend/.env
ALPACA_API_KEY=your_key
ALPACA_SECRET_KEY=your_secret
ALPACA_BASE_URL=https://paper-api.alpaca.markets

SUPABASE_URL=your_url
SUPABASE_KEY=your_anon_key

PERPLEXITY_API_KEY=your_key  # Optional
OPENROUTER_API_KEY=your_key  # Optional

3. Run

# Terminal 1: Backend
cd backend && ./start_backend.sh

# Terminal 2: Frontend
cd frontend && npm run dev

📈 Configuration

Key Settings (backend/config.py)

# Risk Management
risk_per_trade_pct = 0.015      # 1.5% base risk
min_stop_distance_pct = 0.008   # 0.8% minimum stop
max_stop_distance_pct = 0.020   # 2.0% maximum stop
circuit_breaker_pct = 0.03      # 3% daily max loss

# Stop Loss
stop_loss_atr_mult = 1.5        # 1.5x ATR stops
stop_loss_atr_period = 10       # 10-period ATR

# Profit Taking
partial_profit_r_target = 2.0   # Take 50% at 2R
breakeven_r_trigger = 1.0       # Move stop to entry at 1R
trailing_stop_pct = 0.01        # 1% trailing distance

# Trading Hours
entry_cutoff_time = "15:30"     # No new trades after 3:30 PM
eod_exit_time = "15:57"         # Force close at 3:57 PM

📊 Performance Projections

Scenario Daily Monthly Annual Max DD
Conservative 0.3% 6-8% 75-100% <5%
Realistic 0.5% 10-12% 120-150% <8%
Optimistic 0.7% 14-16% 180-220% <12%

Compounding Example ($50,000 start):

  • Year 1: $50K → $125K (150% @ 0.4%/day)
  • Year 2: $125K → $312K (150%)
  • Year 3: $312K → $780K (150%)

⚠️ Disclaimer

This software is for educational purposes only. Trading involves substantial risk of loss. Past performance does not guarantee future results. Always test in paper trading before using real capital.


📄 License

MIT License - see LICENSE


Built with precision by the DayTraderAI Team 🚀

About

DayTraderAI

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors