<?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: maizi</title>
    <description>The latest articles on DEV Community by maizi (@michael_zhang_39361ad72c9).</description>
    <link>https://dev.to/michael_zhang_39361ad72c9</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%2F3911145%2Fa37b8913-e6e5-4072-b9c5-7f36ca23f123.png</url>
      <title>DEV Community: maizi</title>
      <link>https://dev.to/michael_zhang_39361ad72c9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/michael_zhang_39361ad72c9"/>
    <language>en</language>
    <item>
      <title>Building an AI-Powered Quantitative Trading System with Hermes Agent and IBKR</title>
      <dc:creator>maizi</dc:creator>
      <pubDate>Mon, 04 May 2026 02:10:20 +0000</pubDate>
      <link>https://dev.to/michael_zhang_39361ad72c9/building-an-ai-powered-quantitative-trading-system-with-hermes-agent-and-ibkr-476m</link>
      <guid>https://dev.to/michael_zhang_39361ad72c9/building-an-ai-powered-quantitative-trading-system-with-hermes-agent-and-ibkr-476m</guid>
      <description>&lt;h1&gt;
  
  
  Building an AI-Powered Quantitative Trading System with Hermes Agent and IBKR
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;How I set up a multi-signal ETF trading bot that runs on autopilot — and the 7 things that broke along the way&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;I wanted a system that watches the market 24/7, analyzes technical indicators across multiple ETFs, and executes trades automatically. No manual chart-checking. No emotional decisions. Just cold, calculated signals.&lt;/p&gt;

&lt;p&gt;Here's what I built and everything I learned.&lt;/p&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Twelve Data (market data) → Python strategy engine → IB Gateway → IBKR
                                    ↑
                            Hermes Agent (cron scheduling)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Market Data&lt;/strong&gt;: Twelve Data API (free tier, 800 calls/day)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution&lt;/strong&gt;: ib_insync Python library → IB Gateway → Interactive Brokers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheduling&lt;/strong&gt;: Hermes Agent cron jobs, every 3 minutes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dashboard&lt;/strong&gt;: Real-time HTML dashboard with signal indicators and market news&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strategy&lt;/strong&gt;: 6-condition buy signal, 3-condition sell trigger&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Strategy: Why 6/6, Not 2/3
&lt;/h2&gt;

&lt;p&gt;Most retail strategies use 2-3 indicators. I chose 6 for a reason: &lt;strong&gt;every additional condition exponentially reduces false signals&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here are the six gates a stock must pass before I'll buy:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Indicator&lt;/th&gt;
&lt;th&gt;Condition&lt;/th&gt;
&lt;th&gt;What It Means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;RSI &amp;lt; 30&lt;/td&gt;
&lt;td&gt;Oversold bounce&lt;/td&gt;
&lt;td&gt;The stock has been beaten down&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Price ≤ Lower Bollinger&lt;/td&gt;
&lt;td&gt;At support level&lt;/td&gt;
&lt;td&gt;It's at a statistical floor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Price &amp;gt; MA20&lt;/td&gt;
&lt;td&gt;Uptrend&lt;/td&gt;
&lt;td&gt;The direction is right&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;ADX &amp;gt; 20&lt;/td&gt;
&lt;td&gt;Trending, not ranging&lt;/td&gt;
&lt;td&gt;There's actual momentum&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;MACD histogram turning positive&lt;/td&gt;
&lt;td&gt;Momentum shift&lt;/td&gt;
&lt;td&gt;Bears are becoming bulls&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Volume confirmation&lt;/td&gt;
&lt;td&gt;Real interest&lt;/td&gt;
&lt;td&gt;It's not a fake-out&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Sell triggers are simpler — any one of three fires: RSI overbought, price hitting upper Bollinger, or MACD death cross. &lt;strong&gt;Getting out fast matters more than getting in perfectly.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I track three ETFs: SPY, QQQ, IWM. One position at a time. $1,000 paper account.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up IB Gateway: The 3-Hour Rabbit Hole
&lt;/h2&gt;

&lt;p&gt;Installing IB Gateway for headless automated trading should take 15 minutes. It took me three hours. Here's what nobody tells you.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Use the OFFLINE installer, not the auto-updating one
&lt;/h3&gt;

&lt;p&gt;IBC (Interactive Brokers Controller — the tool that types your password into the Gateway's login screen) &lt;strong&gt;does not work with the auto-updating version.&lt;/strong&gt; You MUST download the "Stable Standalone" build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/ibgateway-stable-standalone-linux-x64.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. JavaFX: The silent killer
&lt;/h3&gt;

&lt;p&gt;IB Gateway 10.45 uses JavaFX for its GUI. System OpenJDK does NOT include JavaFX. If you start Gateway via IBC with system Java, it crashes in 0.5 seconds with a cryptic NullPointerException.&lt;/p&gt;

&lt;p&gt;The fix: IB Gateway bundles its own Azul Zulu JRE (which includes JavaFX). Leave &lt;code&gt;JAVA_PATH=&lt;/code&gt; empty in IBC's config, and it auto-discovers the bundled JRE from &lt;code&gt;.install4j/inst_jre.cfg&lt;/code&gt;. &lt;strong&gt;Do not set JAVA_PATH=/usr/bin.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. IBC strips -D VM options. Patch it.
&lt;/h3&gt;

&lt;p&gt;IBC's &lt;code&gt;ibcstart.sh&lt;/code&gt; explicitly filters out ALL &lt;code&gt;-D&lt;/code&gt; prefixed options from &lt;code&gt;ibgateway.vmoptions&lt;/code&gt; (line 322: &lt;code&gt;! "${line:0:2}" = "-D"&lt;/code&gt;). Gateway 10.45 NEEDS &lt;code&gt;-DinstallDir&lt;/code&gt; and &lt;code&gt;-DvmOptionsPath&lt;/code&gt; to initialize. Without them, it silently exits after "LauncherFontUpdater."&lt;/p&gt;

&lt;p&gt;You must add these directly to the &lt;code&gt;java_vm_options&lt;/code&gt; variable in &lt;code&gt;ibcstart.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;java_vm_options&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$java_vm_options&lt;/span&gt;&lt;span class="s2"&gt; -DinstallDir=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;program_path&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;java_vm_options&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$java_vm_options&lt;/span&gt;&lt;span class="s2"&gt; -DvmOptionsPath=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;program_path&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/ibgateway.vmoptions"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Paper trading credentials are separate from Live
&lt;/h3&gt;

&lt;p&gt;I spent 30 minutes debugging "invalid username or password" because IBKR's paper trading account has its OWN username and password, different from your live login. Find them in: &lt;strong&gt;Client Portal → Settings → Paper Trading Account.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Read-Only API mode
&lt;/h3&gt;

&lt;p&gt;When you first log in manually, the Gateway's API is in Read-Only mode. ib_insync connects but every order fails with &lt;code&gt;Error 321: The API interface is currently in Read-Only mode&lt;/code&gt;. Fix: &lt;strong&gt;Configuration → API → Settings → uncheck "Read Only API."&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Live accounts require 2FA
&lt;/h3&gt;

&lt;p&gt;Live trading accounts need IBKR Mobile authentication. IBC handles the 2FA flow but you MUST acknowledge the push notification on your phone within 180 seconds. For automated paper trading, no 2FA needed — use a dedicated paper trading username.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. WSLg focus events flood the log
&lt;/h3&gt;

&lt;p&gt;Running in WSL2 with WSLg, the Gateway window generates hundreds of focus/lost-focus events. IBC logs them all. It doesn't break anything but makes reading the log... noisy.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Code
&lt;/h2&gt;

&lt;p&gt;The full strategy is a Python script that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetches 5-minute candles from Twelve Data&lt;/li&gt;
&lt;li&gt;Calculates all 6 indicators locally with NumPy&lt;/li&gt;
&lt;li&gt;Connects to IB Gateway via ib_insync&lt;/li&gt;
&lt;li&gt;Checks buy/sell conditions&lt;/li&gt;
&lt;li&gt;Executes market orders on signal&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Core signal check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check_buy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rsi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sma&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;upper&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;middle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;adx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ml&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hist&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vol&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;RSI oversold&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="n"&gt;rsi&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;At lower band&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;lower&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.02&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Uptrend&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;         &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sma&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Trending&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;        &lt;span class="n"&gt;adx&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;MACD turning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="n"&gt;hist&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;ph&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;hist&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Volume OK&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;       &lt;span class="n"&gt;vol&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All six must be &lt;code&gt;True&lt;/code&gt;. If any one fails, no trade. This filters out ~95% of false signals compared to a simple RSI-only strategy.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Dashboard
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/dashboard.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/dashboard.png" alt="Dashboard showing three ETF cards with signal indicators"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I built a real-time HTML dashboard that shows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each ETF's 6 signal lights (green ✓ / red ✗) with hover explanations&lt;/li&gt;
&lt;li&gt;Progress bar toward 6/6&lt;/li&gt;
&lt;li&gt;RSI, ADX, MA values&lt;/li&gt;
&lt;li&gt;Market status (open/closed/weekend)&lt;/li&gt;
&lt;li&gt;Latest Yahoo Finance news&lt;/li&gt;
&lt;li&gt;Auto-refresh every 3 seconds&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The strategy script writes a &lt;code&gt;data.json&lt;/code&gt; file each run, and the dashboard reads it. No server-side rendering needed — just static HTML + JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hermes Agent Cron Scheduling
&lt;/h2&gt;

&lt;p&gt;Hermes Agent handles scheduling. One command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes cron create &lt;span class="s2"&gt;"*/3 * * * *"&lt;/span&gt; &lt;span class="nt"&gt;--prompt&lt;/span&gt; &lt;span class="s2"&gt;"Run the strategy script"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agent executes the Python script, connects to IB Gateway, gets market data, evaluates signals, and places orders — all autonomously. If a trade happens, I get notified.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results (Paper Trading)
&lt;/h2&gt;

&lt;p&gt;After one weekend of running:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;0 trades executed&lt;/strong&gt; (markets closed)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;780 API calls saved&lt;/strong&gt; (rate limit not wasted on weekends)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dashboard functional&lt;/strong&gt; with live market status detection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Monday will be the real test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Offline installer, not auto-updating.&lt;/strong&gt; This alone saved what could have been hours of debugging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Let IBC find its own Java.&lt;/strong&gt; Don't override JAVA_PATH. The bundled JRE has JavaFX; your system JRE probably doesn't.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Patch ibcstart.sh.&lt;/strong&gt; IBC intentionally strips &lt;code&gt;-D&lt;/code&gt; options. Gateway 10.45 needs them. Add them manually.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;6/6 is strict but worth it.&lt;/strong&gt; Each additional condition exponentially reduces noise.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Paper trading credentials are separate from Live.&lt;/strong&gt; This one cost me 30 minutes of confusion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build a dashboard.&lt;/strong&gt; You can't debug what you can't see. Visual feedback for every indicator state is invaluable.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;This setup runs on a $1,000 paper trading account. Full code and configuration available at &lt;a href="https://maiweb.co.nz" rel="noopener noreferrer"&gt;maiweb.co.nz&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Built with Hermes Agent, ib_insync, Twelve Data, and too much coffee.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>trading</category>
      <category>automation</category>
    </item>
  </channel>
</rss>
