Skip to content

Trading Automation Setup Guide

Automated RSI Alerts, Stop-Loss Monitoring, and Daily Scans

Created: 2025-10-22


📋 Overview

This guide sets up three automated trading tools:

  1. RSI Alert Monitor - Notifies when stocks hit RSI thresholds (FAST > 27, etc.)
  2. Stop-Loss Monitor - Watches your positions and alerts on stop-loss triggers
  3. Daily Scan Tracker - Runs batch scanner daily, tracks changes over time

🚀 Quick Start

Run all three automations with one command:

cd ~/mem-agent-mcp

# Test each system (run once)
uv run python3 tools/rsi_alert_monitor.py --check-once
uv run python3 tools/stop_loss_monitor.py --check-once
# Daily scan takes ~4 minutes, runs automatically

# Install for automatic running (optional)
./tools/install_trading_automation.sh

🔔 1. RSI Alert Monitor

What It Does

  • Monitors specific stocks for RSI threshold crossovers
  • Sends macOS notifications when buy/sell signals trigger
  • Configured stocks:
  • FAST (Fastenal): Alert when RSI > 27 (buy signal)
  • SBGI (Sinclair): Alert when RSI > 20 (speculative buy)
  • HALO (Halozyme): Alert when RSI > 25 (biotech buy)
  • IQ (Your position): Alert when RSI > 65 (take profits)
  • VERI (Your position): Alert when RSI > 50 (danger zone)

Manual Usage

# Check once and exit
uv run python3 tools/rsi_alert_monitor.py --check-once

# Run continuous monitoring (every 60 minutes)
uv run python3 tools/rsi_alert_monitor.py --interval 60

Example Output

🔔 RSI ALERT MONITOR
══════════════════════════════════════════════════════════
Time: 2025-10-22 09:00:00

Checking FAST (Fastenal)... RSI: 28.2
   🔔 ALERT TRIGGERED: 🟢 BUY SIGNAL

Checking IQ (iQIYI)... RSI: 25.0
   ✅ No alerts

Checking VERI (Veritone)... RSI: 58.2
   ✅ No alerts

Notification Example

┌────────────────────────────────────┐
│ RSI Alert: FAST                     │
├────────────────────────────────────┤
│ 🟢 BUY SIGNAL                        │
│ RSI: 28.2                           │
│ Quality large-cap buy opportunity   │
└────────────────────────────────────┘

Log Files

  • Alerts Log: ~/Documents/rsi-alerts.log
  • Format: One JSON object per alert

🛡️ 2. Stop-Loss Monitor

What It Does

  • Monitors ALL open paper trading positions
  • Alerts when positions approach stop-loss levels
  • Three types of stops:
  • Trailing Stop (IQ): 5% trailing for profit protection
  • Hard Stop (VERI, LCID): Fixed % loss limit
  • RSI-Based Stop (RC, VZ): Wider stops for oversold stocks

Stop-Loss Rules

Symbol Type Level Reason
IQ Trailing 5% Protect profits (currently +2.5%)
VERI Hard Stop -10% Not oversold, limit downside
LCID Hard Stop -10% High volatility EV stock
RC RSI-Based -15% Extreme oversold (RSI 18), allow recovery
VZ RSI-Based -12% Quality large-cap, oversold (RSI 23)

Manual Usage

# Check once and exit
uv run python3 tools/stop_loss_monitor.py --check-once

# Run continuous monitoring (every 15 minutes)
uv run python3 tools/stop_loss_monitor.py --interval 15

Example Output

🛡️  STOP-LOSS MONITOR
══════════════════════════════════════════════════════════
Time: 2025-10-22 09:00:00

📊 Checking 5 position(s)...

🟢 IQ: +2.5% (Stop type: trailing_stop_percent)
🔴 VERI: -9.0% (Stop: -10%, Distance: 1.0%)
   🔔 ALERT TRIGGERED: ⚠️  WARNING - Approaching stop loss (-10%)
⚪ RC: -2.5% (Stop: -15%, Distance: 12.5%)
⚪ VZ: -2.1% (Stop: -12%, Distance: 9.9%)
🔴 LCID: -3.6% (Stop: -10%, Distance: 6.4%)

Notification Types

Warning (2% before stop):

┌────────────────────────────────────┐
│ Stop-Loss Alert: VERI               │
├────────────────────────────────────┤
│ ⚠️  WARNING - Approaching -10%      │
│ Current P/L: -9.0%                  │
│ Not oversold, limit downside        │
└────────────────────────────────────┘
Sound: Submarine

Critical (stop triggered):

┌────────────────────────────────────┐
│ Stop-Loss Alert: VERI               │
├────────────────────────────────────┤
│ 🔴 SELL - Hard stop at -10% reached │
│ Current P/L: -10.2%                 │
│ Not oversold, limit downside        │
└────────────────────────────────────┘
Sound: Basso

Log Files

  • Alerts Log: ~/Documents/stop-loss-alerts.log

📊 3. Daily Scan Tracker

What It Does

  • Runs batch micro-cap scanner daily
  • Tracks RSI changes over time
  • Identifies:
  • 🟢 New oversold opportunities (newly became oversold)
  • 📈 Recovered stocks (recovered from oversold)
  • 🔴 New overbought stocks (take profit signals)
  • Generates daily markdown reports
  • Sends daily summary notification

Manual Usage

# Run daily scan workflow (takes ~4 minutes)
uv run python3 tools/daily_scan_tracker.py

# Show changes from last scan
uv run python3 tools/daily_scan_tracker.py --show-changes

Example Output

📊 RUNNING DAILY MICRO-CAP SCAN
══════════════════════════════════════════════════════════
Time: 2025-10-22 08:00:00

[Scanning 544 stocks...]

✅ Scan complete: 544 stocks scanned

📈 SIGNIFICANT RSI CHANGES (Last Scan)
══════════════════════════════════════════════════════════

🟢 NEW OVERSOLD OPPORTUNITIES (12 stocks):
   AMZN   - RSI: 28.9
   TSLA   - RSI: 29.2
   ...

📈 RECOVERED FROM OVERSOLD (8 stocks):
   AAPL
   MSFT
   ...

🔴 NEW OVERBOUGHT - TAKE PROFITS (5 stocks):
   NVDA   - RSI: 72.3
   ...

Daily Notification

┌────────────────────────────────────┐
│ Daily Micro-Cap Scan Complete       │
├────────────────────────────────────┤
│ Found 102 oversold opportunities    │
│ 12 NEW stocks became oversold       │
└────────────────────────────────────┘

Generated Files

  • Scan History: ~/Documents/trading-scans/scan-history.jsonl
  • Changes: ~/Documents/trading-scans/significant-changes.json
  • Daily Report: ~/Documents/trading-scans/daily-report-YYYY-MM-DD.md

Daily Report Example

# Daily Micro-Cap Scan Report
**Date**: 2025-10-22

## Scan Summary
- **Total Scanned**: 544
- **Opportunities**: 102

## Changes Since Last Scan
- **New Oversold**: 12
- **Recovered**: 8
- **New Overbought**: 5

### 🟢 New Oversold Opportunities
- **AMZN**: RSI 28.9
- **TSLA**: RSI 29.2
- **PYPL**: RSI 27.5
...

🤖 Automated Setup (LaunchAgents)

Install All Automations

cd ~/mem-agent-mcp
chmod +x tools/install_trading_automation.sh
./tools/install_trading_automation.sh

This creates 3 LaunchAgents:

  1. com.trading.rsi-alerts.plist - Runs every hour
  2. com.trading.stop-loss.plist - Runs every 15 minutes
  3. com.trading.daily-scan.plist - Runs daily at 8:00 AM

Manual LaunchAgent Management

# Load (enable) agents
launchctl load ~/Library/LaunchAgents/com.trading.rsi-alerts.plist
launchctl load ~/Library/LaunchAgents/com.trading.stop-loss.plist
launchctl load ~/Library/LaunchAgents/com.trading.daily-scan.plist

# Unload (disable) agents
launchctl unload ~/Library/LaunchAgents/com.trading.rsi-alerts.plist
launchctl unload ~/Library/LaunchAgents/com.trading.stop-loss.plist
launchctl unload ~/Library/LaunchAgents/com.trading.daily-scan.plist

# Check status
launchctl list | grep trading

# View logs
tail -f ~/Library/Logs/trading-rsi-alerts.log
tail -f ~/Library/Logs/trading-stop-loss.log
tail -f ~/Library/Logs/trading-daily-scan.log

📝 Customization

Add More RSI Alerts

Edit tools/rsi_alert_monitor.py, line 22-57:

self.alerts = {
    "YOUR_SYMBOL": {
        "name": "Company Name",
        "trigger_above": 30,  # Alert when RSI crosses above this
        "trigger_below": 70,  # Alert when RSI crosses above this
        "reason": "Why to trade this",
        "position_size": "$500-1000"
    }
}

Modify Stop-Loss Rules

Edit tools/stop_loss_monitor.py, line 27-58:

self.stop_loss_rules = {
    "YOUR_SYMBOL": {
        "type": "hard_stop_percent",  # or "trailing_stop_percent" or "rsi_based"
        "value": -10.0,  # Stop loss percentage
        "reason": "Your reasoning"
    }
}

Change Scan Schedule

Edit LaunchAgent file: ~/Library/LaunchAgents/com.trading.daily-scan.plist

<key>StartCalendarInterval</key>
<dict>
    <key>Hour</key>
    <integer>8</integer>  <!-- Change hour (0-23) -->
    <key>Minute</key>
    <integer>0</integer>  <!-- Change minute (0-59) -->
</dict>

Then reload:

launchctl unload ~/Library/LaunchAgents/com.trading.daily-scan.plist
launchctl load ~/Library/LaunchAgents/com.trading.daily-scan.plist


🔍 Troubleshooting

No Notifications Appearing

  1. Check System Preferences → Notifications → Script Editor (allow notifications)
  2. Test notification:
    osascript -e 'display notification "Test" with title "Trading Alert"'
    

RSI Alerts Not Triggering

  1. Check Alpaca API keys are set:

    echo $ALPACA_PAPER_API_KEY
    echo $ALPACA_PAPER_SECRET_KEY
    

  2. Run manually with verbose output:

    uv run python3 tools/rsi_alert_monitor.py --check-once
    

Stop-Loss Monitor Not Finding Positions

  1. Verify you have open positions:

    uv run python3 tools/portfolio_fetcher.py
    

  2. Check API connection:

    uv run python3 tools/stop_loss_monitor.py --check-once
    

Daily Scan Failing

  1. Check disk space (scans generate data):

    df -h ~
    

  2. Test manually:

    uv run python3 tools/daily_scan_tracker.py
    


📊 Monitoring & Logs

Check LaunchAgent Logs

# RSI Alerts log
tail -50 ~/Library/Logs/trading-rsi-alerts.log

# Stop-Loss log
tail -50 ~/Library/Logs/trading-stop-loss.log

# Daily Scan log
tail -50 ~/Library/Logs/trading-daily-scan.log

View Alert History

# RSI alerts
tail -20 ~/Documents/rsi-alerts.log | jq .

# Stop-loss alerts
tail -20 ~/Documents/stop-loss-alerts.log | jq .

# Scan history
tail -7 ~/Documents/trading-scans/scan-history.jsonl | jq .

🎯 Best Practices

  1. Test First: Always run --check-once before installing LaunchAgents
  2. Review Logs Weekly: Check for missed alerts or errors
  3. Update Rules: Adjust stop-loss levels as positions move
  4. Paper Trade First: All automation targets paper account only
  5. Monitor Resources: Ensure automations aren't slowing down system

🚨 Safety Reminders

  • ✅ All automations are ALERT ONLY - they never execute trades automatically
  • ✅ You must manually execute any buy/sell decisions
  • ✅ Stop-loss alerts are recommendations, not automatic orders
  • ✅ Test in paper account before considering live trading
  • ⚠️ Never blindly follow alerts - verify market conditions first

  • Analysis Report: ~/Documents/micro-cap-analysis-2025-10-22.md
  • Batch Scanner: ~/mem-agent-mcp/tools/batch_opportunity_scanner.py
  • Portfolio Fetcher: ~/mem-agent-mcp/tools/portfolio_fetcher.py
  • Trading Analytics: ~/mem-agent-mcp/tools/trading_analytics.py

Questions? Run any script with --help for detailed usage information.

Next Steps: After setup, check notifications once daily and review weekly scan reports to identify trends!