What You'll Build

An AI trading agent that monitors market conditions, analyzes trends, and executes buy/sell orders on a live brokerage account. It runs continuously using OpenClaw's heartbeat system, checking in on positions and making decisions without human intervention.

Why This Works

Most retail traders lose money because of emotions. They panic-sell on dips, FOMO-buy at peaks, and check their portfolio 47 times a day. An AI agent doesn't have feelings. It follows the strategy you define, executes consistently, and never revenge-trades after a loss.

The heartbeat pattern is what makes this possible. Instead of running a fragile always-on script, OpenClaw wakes up at regular intervals, evaluates the current state, makes decisions, and goes back to sleep. If something crashes, it picks up where it left off.

Prerequisites

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Heartbeat   │────▢│  Market      │────▢│  Decision    β”‚
β”‚  (every 5m)  β”‚     β”‚  Scanner     β”‚     β”‚  Engine      β”‚
β”‚              β”‚     β”‚              β”‚     β”‚              β”‚
β”‚  Wake up,    β”‚     β”‚  - Prices    β”‚     β”‚  - Strategy  β”‚
β”‚  check state β”‚     β”‚  - Volume    β”‚     β”‚  - Risk mgmt β”‚
β”‚              β”‚     β”‚  - News      β”‚     β”‚  - Position  β”‚
β”‚              β”‚     β”‚  - Sentiment β”‚     β”‚    sizing    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                  β”‚
                                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
                                         β”‚  Executor      β”‚
                                         β”‚                β”‚
                                         β”‚  - Place order β”‚
                                         β”‚  - Set stops   β”‚
                                         β”‚  - Log trade   β”‚
                                         β”‚  - Alert human β”‚
                                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Step 1: Connect Your Brokerage

Most modern brokerages offer API access. Alpaca is popular for this because it's free and designed for algo trading:

# Store your API keys in OpenClaw's environment
# Never hardcode these in skill files
ALPACA_API_KEY=your_key
ALPACA_SECRET_KEY=your_secret
ALPACA_BASE_URL=https://paper-api.alpaca.markets  # Start with paper trading!

Start with paper trading. Seriously. Run this for weeks on a simulated account before touching real money.

Step 2: Define Your Strategy

Tell your agent exactly how to trade. Be specific about entry conditions, exit conditions, and risk management:

## Trading Rules
- Only trade these tickers: SPY, QQQ, AAPL, MSFT
- Max position size: 5% of portfolio per ticker
- Entry: Buy when RSI < 30 and price above 200-day MA
- Exit: Sell when RSI > 70 or stop-loss at -3%
- Never hold more than 3 positions at once
- No trading in first/last 15 minutes of market hours

The more specific your rules, the better the agent performs. Vague strategies lead to vague results.

Step 3: Set Up Heartbeats

Configure OpenClaw to check markets at regular intervals. During market hours, you might want checks every 5 minutes. After hours, once an hour is fine:

The heartbeat checks current positions, scans for new opportunities, and executes any trades that match your criteria. Each heartbeat is a fresh evaluation, so the agent won't get stuck in loops or chase bad trades.

Step 4: Build the Risk Rails

This is the most important step. Your agent needs hard limits it cannot override:

Think of these as guardrails on a mountain road. The AI drives, but the rails keep it from going off a cliff.

Step 5: Monitor and Adjust

Set up daily reports that summarize:

Review these daily for the first few weeks. Adjust your strategy based on real results, not backtests.

What Could Go Wrong

Let's be honest: this is real money.

The Bottom Line

An AI trading agent won't make you a genius investor. What it will do is execute your strategy with perfect discipline, zero emotion, and 24/7 attention. For anyone who already has a strategy but lacks the time or discipline to follow it consistently, this is a force multiplier.

Just remember: paper trade first, risk what you can afford to lose, and keep a kill switch handy.