How to Build Your Own AI Trading Agent in 2026 (End-to-End)
Wire a pre-screened small-cap momentum feed into a self-learning agent: a five-layer build — data funnel (signals → watchlist → alerts), an observe-reason-act-score-learn loop, daily synthesis, deterministic as_of backtesting, and a paper agent reasoning on an open model. Educational, paper only.
Read this first
This is a practical, end-to-end guide to building your own AI trading agent in 2026. It is educational. It is not financial advice, it is not a copy-paste production template, and no part of it suggests the agent you build will be profitable. The agent here suggests names to study — it never buys anything for real. Paper trade for at least 30 days before any live capital, and only ever trade with money you can afford to lose.
The framing matters. BullAlert is a data tool — we surface positive-momentum small-caps, publish our own derived intelligence per session, and stop there. The agent you build in this guide is a separate system that consumes BullAlert as one input and adds everything we don't: a reasoning loop, a memory, a backtest, and a paper-execution layer that you own and operate yourself. We're going to walk through the whole stack.
Think of BullAlert as the first step in your stack — the picks-and-shovels layer, not the whole mine. We do the universe-filtering plus the scam/pump screening so the $0.20–$20 names you start from are signal, not noise. You pair our derived intelligence (score, status, tier, catalyst, volume band) with your own broker (IBKR, Alpaca, whatever you trade through) for execution and your own strategy for the edge. We deliberately do not redistribute raw Level 1/2 market data or quotes — that stays with your broker and market-data provider; what we publish is our proprietary intelligence layer. The value is in what you skip — the part where a bot drowns in pump-and-dumps and bot-spam — so your time goes into building your alpha: infinite strategies, your edge, on a clean base we've backtested.
The architecture: five layers
An autonomous trading agent, regardless of model or strategy, decomposes into the same five layers. Building the agent is choosing a tool for each layer and wiring them together honestly.
- Data — a pre-screened universe + context the agent can reason over.
- Agent loop — observe → reason → act-on-paper → score → learn.
- Synthesis — turning the feed plus memory into a daily shortlist.
- Backtest — replaying past sessions deterministically against a baseline.
- Live (paper) — running the agent's reasoning model on real cycles, paper only.
Most agents that fail do so because one layer was treated as an afterthought — usually the backtest, or the discipline of keeping everything on paper. The sketches below are the shape; the work is in making each layer honest.
Layer 1 — Data: a pre-screened universe
An agent is only as good as what it's allowed to look at. Point a raw LLM at the entire market and it drowns; the universe-filtering and scam/pump screening is where most of the real edge lives, and it's exactly the part you don't want to rebuild from scratch. BullAlert exposes that work as three momentum endpoints — read them as a funnel, breadth at the top, conviction at the bottom:
-
GET /v1/signals— the breadth feed. Every $0.20–$20 ticker our scanner validated this session (hundreds), after we've done the universe-filtering plus scam/pump screening so your agent doesn't have to. Each row is identity only —{ticker, caught_at, session}— a data input, not a ranked call. -
GET /v1/watchlist— our proprietary ranking. The breadth pool sorted into a green/yellow shortlist with ascore(0–100) and astatusofmomentumorwatch. -
GET /v1/alerts— the handful that passed every internal gate (ticker · caught_at). The narrow end of the funnel. -
GET /v1/edgar/{ticker}— SEC-EDGAR filing context for a microcap: financials plus small-cap signals (dilution, runway, insider direction, recent 8-K flags). The "why might this move (or fade)" layer.
The funnel is the point: signals (breadth) → watchlist (ranking) →
alerts (conviction). Your agent decides where on that funnel it wants to fish.
Here's the breadth feed over plain REST — one key in the x-ba-api-key header,
minted from your dashboard:
curl -H "x-ba-api-key: ba_live_..." \
"https://api.bullalert.ai/v1/signals?session=current&limit=50" The same call in Python, with the watchlist ranking layered on top:
# data.py — the BullAlert funnel: breadth -> ranking -> conviction
import os, requests
BASE = 'https://api.bullalert.ai/v1'
HEADERS = {'x-ba-api-key': os.environ['BULLALERT_API_KEY']}
def get_signals(session='current', limit=50) -> list[dict]:
"""Breadth: the validated $0.20-$20 pool. Rows are identity only:
{ticker, caught_at, session}. We did the universe + scam/pump screen."""
r = requests.get(f'{BASE}/signals',
headers=HEADERS,
params={'session': session, 'limit': limit},
timeout=10)
r.raise_for_status()
return r.json()['data']['signals']
def get_watchlist(session='current', limit=25) -> list[dict]:
"""Ranking: green/yellow shortlist. Rows carry rank, ticker, score (0-100),
status ('momentum' | 'watch')."""
r = requests.get(f'{BASE}/watchlist',
headers=HEADERS,
params={'session': session, 'limit': limit},
timeout=10)
r.raise_for_status()
return r.json()['data']['watchlist']
def get_edgar(ticker: str) -> dict:
"""Context: SEC-EDGAR financials + small-cap signals for one name."""
r = requests.get(f'{BASE}/edgar/{ticker}', headers=HEADERS, timeout=10)
r.raise_for_status()
return r.json()['data']
# DXST showed up in today's breadth pool; pull its filing context before reasoning.
pool = get_signals() # e.g. [{'ticker': 'DXST', 'caught_at': '...', 'session': 'market'}, ...]
ranked = get_watchlist() # the green/yellow cut of that pool
context = get_edgar('DXST') # dilution / runway / insider / 8-K flags
If your agent is MCP-capable, skip the glue entirely. The same primitives are exposed as native
tools at https://api.bullalert.ai/v1/mcp with one key —
list_signals, list_watchlist, list_alerts, and
get_company_financials. An MCP agent calls them directly, the same way it calls any
other tool. Full reference at /api. BullAlert is the data + tools layer; your
agent owns every decision.
Layer 2 — The agent loop
The heart of an autonomous agent is a self-learning loop: observe → reason → act-on-paper → score → learn. Each cycle the agent pulls the feed (observe), asks its model what looks worth studying and why (reason), records a hypothetical paper pick (act), waits for the session to settle and grades that pick against what actually happened (score), and folds the lesson back into its memory (learn). Over weeks, the memory is where the agent's "judgment" accrues — not the model weights.
We built one of these for ourselves (an internal research agent, Hermes-style) the same way. Here's the conceptual skeleton — keep it paper-only and keep the reasoning model on a short leash with a tight system prompt:
# agent_loop.py — educational skeleton, paper only. Suggests study, never buys.
import json, datetime
from data import get_signals, get_watchlist, get_edgar
from memory import load_memory, save_lesson # your own tiny JSON/SQLite store
from model import reason # Layer 5: the LLM call
SYSTEM_PROMPT = '''You are a research agent studying US small-cap momentum.
You are handed a pre-screened watchlist (our data tool already filtered the
$0.20-$20 universe and screened for scams/pumps). Your job: pick up to 3 names
worth RESEARCHING today and explain why, citing ticker + score + any filing
context. You never place real orders and you never give buy/sell/hold advice.
Frame everything as study. End with the disclaimer your jurisdiction requires.'''
def observe() -> dict:
return {
'watchlist': get_watchlist(session='current', limit=25), # ranked names
'breadth': len(get_signals(session='current', limit=100)), # pool size
}
def cycle():
state = observe()
memory = load_memory() # past lessons, prior scored picks
# --- reason: ask the model for a paper shortlist + rationale ---
picks = reason(SYSTEM_PROMPT, context={'state': state, 'memory': memory})
# --- act (paper): enrich the chosen names + log a hypothetical entry ---
for p in picks:
p['edgar'] = get_edgar(p['ticker']) # add filing context to the note
log_paper_pick(p) # write to a notebook ledger, no broker
return picks
def settle_and_learn(scan_date):
# Next day: grade yesterday's paper picks against what the watchlist did,
# then write the gap back to memory so the agent reasons better tomorrow.
for pick in yesterdays_paper_picks(scan_date):
outcome = score_against_baseline(pick, scan_date) # see Layer 4
save_lesson(pick, outcome)
if __name__ == '__main__':
cycle() # run on a schedule during the session; settle_and_learn() the next morning
The loop is deliberately boring. The interesting part is the honesty of the
score step — an agent that grades itself generously learns nothing. Everything here
is paper: log_paper_pick writes to a ledger, not a broker.
Layer 3 — Synthesis: from feed to a daily shortlist
Synthesis is where the agent earns its keep: turning a hundred-name breadth pool plus its own memory into a 1–3 name shortlist a human could actually study. The pattern that works is layered, not one giant prompt:
- Filter on the ranking. Start from
/v1/watchlist, not the raw breadth pool. The green/yellow status is a candidate filter — let it narrow hundreds to a handful before the model ever sees them. - Enrich the survivors. For each shortlisted ticker, pull
/v1/edgar/{ticker}so the model reasons over filing context (a fresh contract 8-K reads very differently from a dilutive S-3) instead of price alone. - Consult memory. Hand the model its own recent lessons — "names like LASE with a contract catalyst tended to hold; thin after-hours catches tended to fade." This is the compounding part.
- Ask for a ranked study list with rationale. Up to three names, each with a one-line "why study this" tied to the ticker, its score, and a filing flag. No execution, no price targets — a research queue, not a trade list.
The output is a shortlist you read with your morning coffee. No order is ever placed here; the agent's job ends at "here are three names worth your own due diligence, and here's why."
Layer 4 — Backtest: replay against a baseline
Before you trust the agent's judgment, validate it. The honest test is a deterministic replay: re-run the agent against past sessions exactly as they settled, and compare its shortlist to a simple baseline — the watchlist ranking itself. If the agent can't beat "just take the top of the watchlist," it isn't adding anything yet.
Both the breadth feed and the ranking support an as_of parameter — a UTC ISO8601
timestamp that returns the validated pool / ranking exactly as it settled for that ET trading
date. The historical record reaches back to 2026-04-20, so you can replay weeks of sessions
deterministically:
curl -H "x-ba-api-key: ba_live_..." \
"https://api.bullalert.ai/v1/watchlist?as_of=2026-05-12T14:30:00Z&limit=25" # backtest.py — replay the agent vs the watchlist baseline, deterministically.
import os, requests
from datetime import datetime, timezone
BASE = 'https://api.bullalert.ai/v1'
HEADERS = {'x-ba-api-key': os.environ['BULLALERT_API_KEY']}
def watchlist_as_of(iso_utc: str, limit=25) -> list[dict]:
r = requests.get(f'{BASE}/watchlist', headers=HEADERS,
params={'as_of': iso_utc, 'limit': limit}, timeout=10)
r.raise_for_status()
return r.json()['data']['watchlist']
def signals_as_of(iso_utc: str, limit=100) -> list[dict]:
r = requests.get(f'{BASE}/signals', headers=HEADERS,
params={'as_of': iso_utc, 'limit': limit}, timeout=10)
r.raise_for_status()
return r.json()['data']['signals']
# For each past session: what did the agent pick, vs the baseline top-of-watchlist?
def replay(iso_utc: str):
pool = signals_as_of(iso_utc) # the breadth the agent would have seen
ranked = watchlist_as_of(iso_utc) # the baseline ranking
baseline = [row['ticker'] for row in ranked[:3]] # naive: top-3 by score
agent_picks = run_agent_on(pool, ranked) # your Layer 2/3 loop, frozen at as_of
# Compare agent_picks to baseline using your own forward-looking outcome
# source (your market-data API). Did the agent's reasoning beat 'take the top'?
return {'as_of': iso_utc, 'baseline': baseline, 'agent': agent_picks}
# Walk every trading session back to 2026-04-20 and tally agent-vs-baseline.
The discipline that matters more than the harness: no look-ahead. The
as_of response is frozen to how the session settled, so the agent only ever sees
what it could have seen at decision time. Score the outcome with your own forward
market-data source, and judge the agent against the baseline, not against a story you tell
yourself afterward.
Layer 5 — Live (paper): run the model on Replicate
The last layer wires a real reasoning model into the loop. The snippets above leaned on a
reason() function; here's the smallest honest version of it, running an open model
on Replicate (one API key, swap models freely):
# model.py — the reasoning step, on Replicate. Paper only; suggests study.
import os, json
import replicate # pip install replicate; set REPLICATE_API_TOKEN
def reason(system_prompt: str, context: dict) -> list[dict]:
prompt = (
system_prompt
+ "\n\nWATCHLIST + MEMORY:\n"
+ json.dumps(context, default=str)
+ "\n\nReturn JSON: up to 3 {ticker, score, why} to RESEARCH today."
)
# Call an open instruction model hosted on Replicate.
output = replicate.run(
"meta/meta-llama-3-8b-instruct",
input={"system_prompt": system_prompt, "prompt": prompt,
"max_tokens": 512, "temperature": 0.3},
)
text = "".join(output) # Replicate streams tokens; join them
return json.loads(_extract_json(text)) # your tiny JSON-extraction helper
# Wire model.reason into agent_loop.cycle(). The agent now reasons over the
# live BullAlert funnel each session and writes paper picks to its ledger.
# It NEVER places a real order — every "action" is a hypothetical study note.
Run this on a schedule during market hours and you have a complete, self-learning paper agent:
it observes the BullAlert funnel, reasons with an open model on Replicate, logs paper picks,
and grades itself the next morning via the as_of replay. Every "action" is a study
note. Going from paper to live is a separate decision — your broker, your risk layer, your
capital — and one you only make after the paper loop has earned weeks of trust.
Where BullAlert fits — and where it doesn't
To restate it cleanly: BullAlert is Layer 1 in the architecture above — the data and tools layer. It hands your agent a pre-screened $0.20–$20 universe (signals), a proprietary ranking (watchlist), a conviction set (alerts), and SEC filing context (edgar), over REST and as native MCP tools. It does not own the agent loop, the synthesis prompt, the memory, the backtest, or the paper-execution discipline. Your agent owns all of that. Always.
And BullAlert is not a market-data API: we publish derived intelligence, not raw prices, quotes, percentages, or volume. If your agent needs bars or live quotes, bring a market-data API of your choice and run it alongside our feed — the right stack for the agent you're building.
Frequently asked questions
Is this financial advice?
No. This is an educational, engineering guide. Nothing here is investment advice or a recommendation to buy, sell, or hold any security. The agent you build studies a feed and suggests names to research — it never makes a real-money decision for you. BullAlert is an informational data tool; you own every decision.
What does BullAlert provide vs what do I build?
BullAlert provides the data + tools layer: three public momentum endpoints (signals, watchlist, alerts) plus SEC-EDGAR filing context, available over REST and as native MCP tools. You build everything else — the agent loop, the reasoning prompt, the memory/scoring, the backtest harness, and the paper-execution layer. We are the funnel that hands your agent a clean, pre-screened universe; the strategy and the discipline are yours.
Do I need my own market data?
Yes. BullAlert is not a market-data redistributor — we hand you filtered tickers and our derived intelligence (rank, score, status, catalyst context), not raw prices, percentages, volume, or quotes. If your agent needs bars, charts, or live quotes to confirm a setup, bring a market-data API of your choice and wire it in alongside our feed.
Do I still need a broker or a market-data feed?
Yes — BullAlert is the first step, the filtered quality-ticker data layer, not an execution venue or a raw market-data feed. Pair it with your own broker (IBKR, Alpaca, etc.) for live or paper execution and for prices. We tell you which $0.20–$20 names are worth your attention — that's our backtested intelligence (score, status, tier, catalyst, volume band); you bring the strategy and the broker. It's informational and educational, never advice — every order and every decision is yours.
What's the difference between paper and live here?
Everything in this guide is framed as PAPER. The agent "acts" only against a simulated book or a notebook ledger — it scores its own hypothetical picks the next day and learns from the gap. Going live is a separate decision you make with your own broker, your own risk layer, and your own capital, long after the paper loop has earned your trust. Paper for at least 30 days before any live capital.
Which LLM should I use?
Any capable instruction-following model works for the reasoning step. The snippets here call an open model hosted on Replicate so you can run the whole loop with one API key and swap models freely. A smaller open model is plenty for a daily shortlist; reserve a larger model for the synthesis step if your reasoning chain gets long. The agent design matters far more than the exact model.
How is this different from BullAlert as a product?
BullAlert (the product) is a hosted momentum scanner and data tool — it surfaces positive-momentum small-caps and publishes its own derived intelligence, and stops there. The agent you build in this guide is a separate system that consumes that feed as one input and adds the reasoning loop, the memory, the backtest, and the paper-execution layers on top. We even built our own internal research agent the same way — this guide is how to build yours.
Related reading
- How to build your own trading bot (2026) — the rules-engine sibling of this agent guide
- Best stock market data APIs (2026) — bring your own bars + quotes feed
- SEC filings, decoded — what the edgar context layer is reading
- How we built the multi-session scanner — the data tool behind the funnel
- How to find runners before they run — the pre-market signal-stack thinking
- Momentum Trading 101 — the strategy class the agent reasons over
- BullAlert methodology — what the data layer measures and what stays opaque


