<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vitor Calvi </title>
    <description>The latest articles on DEV Community by Vitor Calvi  (@vitorcalvi).</description>
    <link>https://dev.to/vitorcalvi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F677686%2F50c35ca5-f76c-4090-af85-6e24e69f3384.jpeg</url>
      <title>DEV Community: Vitor Calvi </title>
      <link>https://dev.to/vitorcalvi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vitorcalvi"/>
    <language>en</language>
    <item>
      <title>How I Built an AI Trading Agent That Learns From Every Trade (And Why 90% of Strategies Fail)</title>
      <dc:creator>Vitor Calvi </dc:creator>
      <pubDate>Mon, 18 May 2026 16:31:58 +0000</pubDate>
      <link>https://dev.to/vitorcalvi/how-i-built-an-ai-trading-agent-that-learns-from-every-trade-and-why-90-of-strategies-fail-53j7</link>
      <guid>https://dev.to/vitorcalvi/how-i-built-an-ai-trading-agent-that-learns-from-every-trade-and-why-90-of-strategies-fail-53j7</guid>
      <description>&lt;h1&gt;
  
  
  How I Built an AI Trading Agent That Learns From Every Trade (And Why 90% of Strategies Fail)
&lt;/h1&gt;

&lt;p&gt;Most trading bots are dumb.&lt;/p&gt;

&lt;p&gt;They follow rules like &lt;em&gt;"buy when RSI &amp;lt; 30 and volume spikes"&lt;/em&gt; — and never question whether the market has fundamentally changed.&lt;/p&gt;

&lt;p&gt;But markets evolve. Regimes shift. Volatility clusters. Correlations break. A strategy that printed money last month might be dead today.&lt;/p&gt;

&lt;p&gt;So I built something different: &lt;strong&gt;an AI trading agent that runs on your own machine, remembers every trade it's ever made, and evolves its strategies through brutal backtest validation.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's the architecture, the methodology, and the uncomfortable truth about what happens when you actually test your trading ideas.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Core Idea
&lt;/h2&gt;

&lt;p&gt;What if a trading system could:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Watch markets autonomously&lt;/strong&gt; — scanning for opportunities every 15 minutes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remember what happened before&lt;/strong&gt; — encoding every trade outcome into a searchable memory&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recall similar situations&lt;/strong&gt; — "this setup looks like the one that lost 3% last Tuesday"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate before committing&lt;/strong&gt; — running walk-forward backtests before any real capital goes in&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evolve winners automatically&lt;/strong&gt; — mutating successful strategy parameters to stay ahead of regime changes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's Cognitive Trader. And it's not a signal bot. It's a cognitive system.&lt;/p&gt;




&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Autonomous Market Analysis
&lt;/h3&gt;

&lt;p&gt;Every 15 minutes (configurable), the system runs a cognitive cycle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Polls prices for BTC, ETH, SOL, and any user-defined symbols&lt;/li&gt;
&lt;li&gt;Aggregates signals from technical indicators, active trading goals, and memory recalls&lt;/li&gt;
&lt;li&gt;The LLM makes a decision: &lt;strong&gt;STAY_SILENT&lt;/strong&gt;, &lt;strong&gt;SPEAK&lt;/strong&gt; (send a Telegram alert), or &lt;strong&gt;ACT&lt;/strong&gt; (execute a trade)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The LLM layer supports GPT-4, Claude, Gemini, and even local models via Ollama. You choose the brain.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Vector-Embedded Memory
&lt;/h3&gt;

&lt;p&gt;This is where it gets interesting. Every closed trade gets processed through two "memory wires":&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;W1 — Manual Fact Extraction&lt;/strong&gt;&lt;br&gt;
When a trade closes, the system extracts factual statements:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"RSI divergence on BTCUSDT produced +2.3% in low volatility regime"&lt;br&gt;
"Breakout failed on ETHUSDT during FOMC announcement"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;W2 — Vector Similarity Retrieval&lt;/strong&gt;&lt;br&gt;
Using Ollama's &lt;code&gt;nomic-embed-text&lt;/code&gt;, every fact gets encoded into a vector embedding. When a new market situation arises, the system retrieves the most similar past experiences via cosine similarity.&lt;/p&gt;

&lt;p&gt;So when the LLM is deciding whether to act, it doesn't just see current prices. It sees &lt;em&gt;what happened the last 5 times this exact pattern appeared.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: The LLM Firewall
&lt;/h3&gt;

&lt;p&gt;Before any trade executes, it passes through a risk-gated decision layer I call "The LLM Firebreak":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Position sizing: &lt;code&gt;min(notional_cap, risk_based_size)&lt;/code&gt; — the smaller wins&lt;/li&gt;
&lt;li&gt;Stop losses: capped at 5% from entry, always&lt;/li&gt;
&lt;li&gt;Daily drawdown killswitch: if 24h PnL drops below -$500, the autonomous cycle halts&lt;/li&gt;
&lt;li&gt;Maximum 3 concurrent positions&lt;/li&gt;
&lt;li&gt;OCA (One-Cancels-All) bracket orders: every entry gets paired SL/TP algo orders&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The LLM can suggest a trade, but the risk engine has veto power. Always.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Brutal Truth About Backtesting
&lt;/h2&gt;

&lt;p&gt;Here's what nobody tells you about trading strategies:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;~90% of hypotheses die in walk-forward validation.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They look amazing in-sample. Beautiful equity curves. Sharpe ratios above 2. Then you run them on out-of-sample data and they bleed money.&lt;/p&gt;

&lt;p&gt;Classic overfitting.&lt;/p&gt;

&lt;p&gt;I built a backtest dashboard that runs your hypotheses through walk-forward validation and shows you the truth:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which strategies are &lt;strong&gt;ALIVE&lt;/strong&gt; (survived out-of-sample)&lt;/li&gt;
&lt;li&gt;Which strategies are &lt;strong&gt;DEAD&lt;/strong&gt; (failed validation)&lt;/li&gt;
&lt;li&gt;Win rate, total P&amp;amp;L, Sharpe ratio per run&lt;/li&gt;
&lt;li&gt;A cumulative ROI bar that compounds &lt;strong&gt;only from surviving strategies&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No curve-fitting illusions. No cherry-picked time windows. Just brutal, honest validation.&lt;/p&gt;




&lt;h2&gt;
  
  
  Strategy Evolution
&lt;/h2&gt;

&lt;p&gt;The strategies that survive backtesting don't just sit there. They evolve.&lt;/p&gt;

&lt;p&gt;The system automatically mutates their parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tighter or wider stop losses&lt;/li&gt;
&lt;li&gt;Different entry thresholds&lt;/li&gt;
&lt;li&gt;New symbol combinations&lt;/li&gt;
&lt;li&gt;Adjusted position sizing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's Darwinian. Only the fittest compound. The rest get pruned.&lt;/p&gt;




&lt;h2&gt;
  
  
  Local-First Architecture
&lt;/h2&gt;

&lt;p&gt;Everything runs on &lt;strong&gt;your&lt;/strong&gt; machine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your API keys never leave your hardware&lt;/li&gt;
&lt;li&gt;Your memory database is local (PostgreSQL)&lt;/li&gt;
&lt;li&gt;Your LLM calls go through your own OpenRouter/Ollama setup&lt;/li&gt;
&lt;li&gt;No cloud dependency, no data leakage, no third-party access&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can run it with cloud LLMs (GPT-4, Claude, Gemini) or fully locally with Ollama. Your choice.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Tech Stack
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Technology&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Language&lt;/td&gt;
&lt;td&gt;Go (primary), JavaScript (dashboard)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LLM&lt;/td&gt;
&lt;td&gt;OpenRouter (GPT-4, Claude, Gemini) + Ollama (local)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory&lt;/td&gt;
&lt;td&gt;PostgreSQL + vector embeddings (nomic-embed-text)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exchange&lt;/td&gt;
&lt;td&gt;Binance USDT-M futures (testnet or live)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dashboard&lt;/td&gt;
&lt;td&gt;Static HTML/CSS/JS — no frameworks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Notifications&lt;/td&gt;
&lt;td&gt;Telegram bot&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Most Trading Ideas Are Bad
&lt;/h3&gt;

&lt;p&gt;The first time I ran my hypothesis generator, I was excited. Then the backtests came back. 9 out of 10 strategies died. Humbling, but honest.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Memory Changes Everything
&lt;/h3&gt;

&lt;p&gt;A trading system that remembers its mistakes is fundamentally different from one that doesn't. The vector embedding recall is the closest thing to "experience" a machine can have.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Local-First Is Non-Negotiable
&lt;/h3&gt;

&lt;p&gt;When it comes to trading, your keys are your sovereignty. Anything that requires sending API keys to a third party is a non-starter.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. LLMs Are Good at Reasoning, Bad at Math
&lt;/h3&gt;

&lt;p&gt;The LLM layer excels at pattern recognition and contextual reasoning. But it needs a deterministic risk engine underneath. Never let an LLM calculate position sizes directly.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Multi-timeframe analysis (15m + 1h + 4h confluence)&lt;/li&gt;
&lt;li&gt;Sentiment integration (news, social, on-chain)&lt;/li&gt;
&lt;li&gt;Portfolio-level risk management (cross-position correlation)&lt;/li&gt;
&lt;li&gt;More exchange support beyond Binance&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Drop a comment — I read every one.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built with Go, PostgreSQL, Ollama, and a healthy distrust of in-sample backtests.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
  </channel>
</rss>
