7.2 KiB
7.2 KiB
Algo Trading - Quick Start
What You Built
A complete algorithmic trading system that:
- ✅ Screens for stock candidates
- ✅ Detects pump signals before they happen
- ✅ Sizes positions smartly (8% per stock max)
- ✅ Manages exits with profit targets, stop losses, time limits
- ✅ Trades automatically with Webull paper trading
- ✅ Protects portfolio with guardrails (25% risky max)
Portfolio Guardrails (Already Built In)
| Guardrail | Limit | Protection |
|---|---|---|
| Max per stock | 8% | Doesn't bet too much on one stock |
| Max risky trades | 25% | Doesn't exceed comfort zone |
| Max positions | 10 | Manageable portfolio |
| Min per trade | $100 | Only meaningful trades |
| Max per trade | $2000 | Reasonable position sizing |
Exit Strategies (Already Built In)
When to automatically SELL:
- Profit Target: +5% → EXIT
- Stop Loss: -2% → EXIT
- Time Limit: 5 days → EXIT
- Trailing Stop: 2% from peak → EXIT
- Signal Deterioration: Signal drops below 40 → EXIT
Quick Start (3 minutes)
Step 1: Run the Demo (No Setup Needed)
cd /home/gnara/TradingAgents
python algo_trading_demo.py
This demonstrates:
- Position sizing (8% rule in action)
- Exit strategies (profit targets, stops)
- Trade validation
- Complete flow
Step 2: Set Up Webull (Paper Trading)
- Go to https://webull.com
- Create account
- In settings: Enable Paper Trading
- Get your Trading PIN (usually 6 digits)
Step 3: Configure for Webull
Create .env file in project root:
WEBULL_EMAIL=your_email@example.com
WEBULL_PASSWORD=your_password
WEBULL_PIN=123456
Or set environment variables:
export WEBULL_EMAIL="your_email@example.com"
export WEBULL_PASSWORD="your_password"
export WEBULL_PIN="123456"
Step 4: Run Real Trading
Option A - In Python script:
from algo_trading_workflow import AlgoTradingBot
import os
bot = AlgoTradingBot(
portfolio_cash=10000.0,
paper_trading=True,
selected_analysts=["market", "social"],
webull_email=os.getenv("WEBULL_EMAIL"),
webull_password=os.getenv("WEBULL_PASSWORD"),
webull_pin=os.getenv("WEBULL_PIN"),
)
# Run 10 iterations (50 minutes with 5-min intervals)
bot.run(iterations=10, interval_seconds=300)
bot.print_summary()
Option B - Command line (after setting env vars):
# Edit bottom of algo_trading_workflow.py to use env vars
python algo_trading_workflow.py
How It Works (Example)
MINUTE 0: Market opens
→ Screening agent finds NVDA is trending
→ Pump detection: score 82/100
→ Buy signal (>70) ✓
→ Position size: 8% * 82% = 6.5% of portfolio
→ Enter: 4 shares @ $150 = $600
MINUTE 5-25: Monitor position
→ Current price: $155 (+3.3%)
→ Still holding (no exit signal yet)
MINUTE 30: Price jumps to $158
→ P/L: +5.3% ✓ HIT PROFIT TARGET
→ EXIT: Sell 4 shares @ $158
→ Profit: $32 (5.3%)
→ Cash restored to portfolio
MINUTE 35: Ready for next trade
→ Repeat for next signal
Customization Examples
Conservative (Lower Risk)
bot = AlgoTradingBot(portfolio_cash=10000)
# Tighter exits
bot.exit_strategy.config.profit_target_pct = 3.0 # Take profit at 3%
bot.exit_strategy.config.stop_loss_pct = 1.5 # Stop at 1.5%
bot.exit_strategy.config.max_hold_days = 3 # Hold max 3 days
# Smaller positions
bot.portfolio_manager.max_position_pct = 0.05 # 5% per stock
bot.portfolio_manager.max_risky_pct = 0.15 # 15% risky
bot.portfolio_manager.max_positions = 5 # Max 5 positions
Aggressive (Higher Risk)
bot = AlgoTradingBot(portfolio_cash=10000)
# Wider exits (hold for bigger gains)
bot.exit_strategy.config.profit_target_pct = 10.0 # Hold for 10%
bot.exit_strategy.config.stop_loss_pct = 5.0 # Stop at 5%
bot.exit_strategy.config.max_hold_days = 10 # Hold 10 days
# Larger positions
bot.portfolio_manager.max_position_pct = 0.12 # 12% per stock
bot.portfolio_manager.max_risky_pct = 0.40 # 40% risky
bot.portfolio_manager.max_positions = 15 # Max 15 positions
Monitoring Your Trades
Check Status
status = bot.get_status()
print(f"Iteration: {status['iteration']}")
print(f"Portfolio: ${status['portfolio']['total_value']:.2f}")
print(f"Positions: {status['portfolio']['num_positions']}")
View Trades
for trade in bot.trade_log:
if trade['action'] == 'BUY':
print(f"BUY {trade['shares']}x {trade['ticker']} @ ${trade['price']:.2f}")
else:
print(f"SELL {trade['shares']}x {trade['ticker']} @ ${trade['price']:.2f} "
f"(P/L: ${trade['profit']:.2f})")
Print Summary
bot.print_summary()
# Shows total portfolio value, P/L, number of trades, etc.
Save State
bot.save_state("my_trading_results.json")
# Load later to resume or analyze
Core Files
| File | Purpose |
|---|---|
algo_trading_demo.py |
← START HERE - Run this first |
algo_trading_workflow.py |
Main bot orchestrator |
tradingagents/strategy/portfolio_manager.py |
Position sizing & limits |
tradingagents/strategy/exit_strategy.py |
Profit/loss management |
tradingagents/strategy/trade_validator.py |
Pre-flight validation |
tradingagents/agents/trader/paper_trading.py |
Webull integration |
ALGO_TRADING_GUIDE.md |
Full detailed documentation |
Common Issues
Q: Bot places too many trades
- Lower profit target:
exit_strategy.config.profit_target_pct = 3.0 - Increase hold time:
exit_strategy.config.max_hold_days = 7
Q: Positions too small
- Increase max position:
portfolio_manager.max_position_pct = 0.12 - Lower min position:
portfolio_manager.min_position_size = 50.0
Q: Too risky
- Lower max risky:
portfolio_manager.max_risky_pct = 0.15 - Tighter stop loss:
exit_strategy.config.stop_loss_pct = 1.0
Q: Webull login fails
- Check email/password in .env
- Check Trading PIN is correct
- Check 2FA is enabled on account
- Try logging in to webull.com manually first
Safety Tips
- Always test in demo mode first - Run
algo_trading_demo.pyto verify logic - Start with small capital - Use $500-$1000 first, not $10,000
- Monitor first trades - Watch your first 5-10 trades closely
- Adjust based on results - If win rate is <50%, tighten stops
- Never go all-in - Always keep reserve cash (25% minimum)
- Use paper trading first - Don't use real money until you're profitable
Next Steps
- ✅ Run
algo_trading_demo.py- See how it works - ✅ Read
ALGO_TRADING_GUIDE.md- Full technical details - ✅ Set up Webull account - Get paper trading ready
- ✅ Configure bot - Customize strategy for your risk appetite
- ✅ Test with small capital - $500-$1000 in paper trading
- ✅ Monitor daily - Track results, adjust rules
- ✅ Scale up - Only after consistent profits
Questions?
Check ALGO_TRADING_GUIDE.md for:
- Detailed architecture diagrams
- All configuration options
- Code examples
- Troubleshooting guide
Remember: Algo trading is powerful but risky. Paper trading lets you learn safely. Start small, monitor closely, and only scale after proven results.
Good luck! 🚀