User Guide

Complete reference for all AlpaTrade commands. Type any command in the terminal on the home page.

Backtesting

Quick Start

Run a parameterized backtest across multiple strategy configurations:

agent:backtest lookback:1m

This runs the Buy the Dip strategy over the last month using the default 7 symbols (AAPL, MSFT, GOOGL, AMZN, NVDA, TSLA, META) with $10,000 starting capital. The backtester automatically tests multiple parameter combinations and reports the best one.

Parameter Grid

The backtester doesn't run a single configuration — it builds a parameter grid and tests every combination. This is how it finds the optimal strategy parameters for the given time period.

Default grid for Buy the Dip:

ParameterValues testedCount
dip_threshold3%, 5%, 7%3
take_profit1%, 1.5%2
hold_days1, 2, 3 days3
stop_loss0.5%1
position_size10%1

Total combinations: 3 x 2 x 3 x 1 x 1 = 18 variations

Each variation runs a full backtest — fetching price data, simulating entries and exits, calculating P&L, fees, and risk metrics. The best configuration is selected by Sharpe ratio (risk-adjusted return).

The grid uses itertools.product() internally, so adding more values to any parameter multiplies the total. Keep grids reasonable (under ~100 variations) to avoid long runtimes.

Parameters Reference

ParameterDefaultDescription
lookback:1m3mData period — 1m, 3m, 6m, 1y
symbols:AAPL,TSLA7 large capsComma-separated ticker list
capital:5000010000Starting capital ($)
strategy:buy_the_dipbuy_the_dipStrategy name
hours:extendedregularInclude pre/after-market (4AM-8PM ET)
intraday_exit:truefalseUse 5-min bars for precise TP/SL timing
pdt:falseautoDisable Pattern Day Trader rule (for >$25k accounts)

Examples:

# 1-month backtest, custom symbols
agent:backtest lookback:1m symbols:AAPL,TSLA,NVDA

# 6-month backtest with extended hours
agent:backtest lookback:6m hours:extended

# Large account, no PDT rule, intraday exits
agent:backtest lookback:3m capital:50000 pdt:false intraday_exit:true

Reading Results

After a backtest completes, you'll see a results table:

MetricWhat it means
Sharpe RatioRisk-adjusted return. Higher is better. >1 is good, >2 is excellent
Total ReturnPercentage gain/loss on initial capital
Annualized ReturnReturn projected to a 1-year basis
Total P&LDollar profit or loss
Win RatePercentage of trades that were profitable
Total TradesNumber of trades executed across all symbols
Max DrawdownLargest peak-to-trough decline. Lower is better

The Params line shows which parameter combination won: dip threshold, take profit target, and hold days.

Equity Curve Chart

An interactive Plotly chart renders below the results showing:

Hover over the chart to compare values at any date. If the blue line is above the others, the strategy outperformed passive investing.

Paper Trading

Starting a Session

Paper trading runs continuously in the background, placing real orders on Alpaca's paper trading API:

agent:paper duration:7d

This monitors your symbols every 5 minutes for 7 days, executing the Buy the Dip strategy with real market data — but no real money is at risk.

ParameterDefaultDescription
duration:7d7dHow long to run — 1h, 1d, 7d, 1m
symbols:AAPL,MSFT7 large capsTickers to trade
poll:60300Seconds between strategy checks
hours:extendedregularTrade pre/after-market
email:falsetrueDisable daily P&L email reports
pdt:falseautoDisable PDT rule

Monitoring & Stopping

agent:status    # check paper trading state
agent:stop      # cancel the background session

Paper trading logs appear in the console. When the session ends, a summary with total trades and P&L is shown.

Email Reports

When enabled (default), a daily P&L summary is emailed via Postmark. Requires POSTMARK_API_KEY, TO_EMAIL, and FROM_EMAIL in your .env file.

Full Cycle

The full cycle chains all phases automatically:

agent:full lookback:1m duration:1m

Workflow:

  1. Backtest — find the optimal parameters
  2. Validate — check backtest trades for anomalies
  3. Paper Trade — deploy the winning config live (paper)
  4. Validate — verify paper trades against market data

Each phase passes its results to the next. If validation finds issues, it attempts up to 10 self-correction iterations before stopping.

ParameterDescription
lookback:3mBacktest data period
duration:1mPaper trading duration
symbols:AAPL,TSLATickers to trade
hours:extendedExtended trading hours

Validation

Validate backtest or paper trade results against real market data:

agent:validate run-id:abc12345
agent:validate run-id:abc12345 source:paper_trade

The validator checks:

If anomalies are found, the validator attempts up to 10 self-correction iterations to fix them. After 10 failures, it stops and reports the issues with suggestions.

Reconciliation

Compare your database records against your actual Alpaca account:

agent:reconcile              # last 7 days
agent:reconcile window:14d   # last 14 days

Reports:

Research Commands

Market research commands use the command:TICKER syntax. Data is sourced from XAI Grok and Tavily APIs.

News

news:TSLA                    # company news (default 10 articles)
news:TSLA limit:20           # more articles
news:TSLA provider:xai       # force XAI Grok provider
news:TSLA provider:tavily    # force Tavily search
news                         # general market news

Returns headlines with source and date. By default, the system tries XAI first and falls back to Tavily.

Company Profile

profile:TSLA

Company overview: sector, industry, market cap, description, and key stats.

Financials

financials:AAPL              # annual income & balance sheet
financials:AAPL period:quarterly

Revenue, net income, EPS, debt, and other fundamental data.

Price & Technicals

price:TSLA

Current quote, daily change, volume, 52-week range, and technical indicators.

Market Movers

movers              # top gainers and losers
movers gainers      # only gainers
movers losers       # only losers

Today's biggest price movers in the US market.

Analyst Ratings

analysts:AAPL

Consensus rating (buy/hold/sell), price targets, and recent analyst actions.

Valuation Comparison

valuation:AAPL              # single stock valuation
valuation:AAPL,MSFT,GOOGL   # side-by-side comparison

P/E, P/S, P/B, EV/EBITDA, and other valuation multiples. Compare multiple tickers to spot relative value.

Query & Reporting

Trades & Runs

trades                       # latest run's trades (current account)
trades paper                 # paper trades only
trades backtest              # backtest trades only
trades paper btd             # paper + strategy slug filter
trades backtest btd-3dp      # backtest + specific slug
trades all                   # all accounts (not just active)
runs                         # recent runs
runs paper                   # paper runs only
runs backtest                # backtest runs only

Filter order: typeslugrun-id (all optional). Add all to see across all linked accounts. Default: current user + active account, latest run.

Performance Reports

report                       # summary of recent runs
report paper                 # paper runs summary
report backtest              # backtest runs summary
report <run-id>              # detailed single-run report
report paper btd             # paper + strategy slug filter
report all                   # all accounts

The summary view shows a compact table with return, Sharpe ratio, P&L, and trade count for each run. The detail view shows full metrics for a specific run.

Top Strategies

top                          # rank strategies (backtest)
top paper                    # rank paper trade results
top paper btd               # paper + slug filter
top all                      # all accounts

Aggregates across all runs to rank strategy configurations by average annualized return. Shows Sharpe ratio, return, win rate, drawdown, and how many times each config has been tested.

Strategy Slugs

Each backtest variation gets a human-readable slug that encodes the strategy type, parameters, and lookback period into a compact identifier. Slugs let you compare configurations at a glance and filter results with agent:top or agent:report.

Format

{strategy}-{param1}-{param2}-...-{lookback}

Units use consistent suffixes: d = days, m = months. Percentages drop the decimal point for fractional values (0.5% becomes 05).

Buy the Dip

Prefix: btd

btd-7dp-05sl-1tp-1d-3m
Token Meaning
btd Strategy: buy_the_dip
{n}dp Dip threshold %
{n}sl Stop loss %
{n}tp Take profit %
{n}d Hold (days)
{period} Lookback (e.g. 1m, 3m)

Example: btd-7dp-05sl-1tp-1d-3m = 7% dip, 0.5% stop loss, 1% take profit, 1 day hold, 3-month lookback

Momentum

Prefix: mom

mom-20lb-5mt-5d-10tp-5sl-1m
Token Meaning
mom Strategy: momentum
{n}lb Lookback period (days)
{n}mt Momentum threshold %
{n}d Hold (days)
{n}tp Take profit %
{n}sl Stop loss %
{period} Lookback

VIX Fear Index

Prefix: vix

vix-20t-on
Token Meaning
vix Strategy: vix
{n}t VIX threshold
{type} Hold type (e.g. on = overnight)

Box-Wedge

Prefix: bwg

bwg-2r-5ct
Token Meaning
bwg Strategy: box_wedge
{n}r Risk %
{n}ct Contraction threshold %
The PDT (Pattern Day Trader) rule is enforced by default for accounts under $25k: max 3 day trades per rolling 5-business-day window. PDT status does not affect the slug itself — two backtests with identical parameters but different PDT settings share the same slug. Use pdt:false to disable for accounts with $25k+ equity.

Options & Flags

These flags can be appended to backtest, paper trade, and full cycle commands.

Extended Hours

agent:backtest lookback:1m hours:extended

Regular hours: 9:30 AM - 4:00 PM ET. Extended hours: 4:00 AM - 8:00 PM ET (pre-market + after-hours). Extended hours backtests include more trading opportunities but may have lower liquidity and wider spreads.

Intraday Exits

agent:backtest lookback:1m intraday_exit:true

When enabled, the backtester uses 5-minute intraday bars to determine exactly when take-profit or stop-loss would trigger within each trading day. This is more accurate than daily bars (which only check open/high/low/close) but takes longer to run.

Key behavior: determines which of TP/SL is hit first. No same-day re-entry after exit.

PDT Rule

agent:backtest lookback:1m pdt:false

The Pattern Day Trader (PDT) rule is a FINRA regulation: accounts under $25,000 are limited to 3 day trades per rolling 5-business-day window. AlpaTrade enforces this by default.

Set pdt:false if your account has $25k+ equity. This removes the day-trade limit and allows the strategy to trade more aggressively.


Need quick help? Type help in the terminal for a compact command reference.