Back to projects

2026 · WIP · 5 min read

AI Trading Signal Bot

  • C++
  • Python
  • Gemini AI
  • Telegram
  • Docker
  • Railway
AI Trading Signal Bot preview
On this page9 parts
  1. What it does
  2. Key features
  3. Talking to the bot
  4. How a signal is decided
  5. How it's built
  6. Keeping the AI honest
  7. The hardest problem: real gold data
  8. Testing
  9. What's next

What it does

A private Telegram bot that keeps an eye on gold (XAU/USD) and Bitcoin for me. I can ask it for the latest prices and a technical analysis, and it messages me on its own when important gold news comes out or when a practice trading setup appears, with Gemini AI explaining what it all means in plain language. It's paper-only: it never connects to a broker and never places a real trade, so it's a safe way to learn how markets move.

Lines of C++20
12.9k
Lines of Python
1.2k
Automated tests
95
Telegram commands
27

Key features

  • Latest prices for gold and Bitcoin, always showing where the data came from and how fresh it is.
  • Technical analysis: moving averages (EMA/SMA), RSI, MACD, ATR, support and resistance, and trend.
  • AI explanations: Gemini turns indicators and headlines into a short summary. Only public market data and news are sent to it, never private messages.
  • News alerts: picks out gold-relevant headlines from CoinDesk, Federal Reserve and BLS news feeds, sorts them by impact, and is rate-limited so it never spams.
  • Backtesting: replays past market data on a virtual $10,000 balance, with simulated fees and slippage, to see how a strategy would have done.
  • Safety by design: only approved Telegram users can use it, the paper-only mode can't be switched off, and tokens and keys are never written to logs.

Talking to the bot

Everything happens in a Telegram chat. A few of the commands:

  • Prices: /gold and /btc show the latest price, its source and its timestamp.
  • Analysis: /analysis gives the latest gold analysis with related news and an optional Gemini explanation. /analysis_on turns on automatic alerts.
  • News: /news lists the latest gold-related headlines with their impact level and links. /news_high or /news_all picks which alerts I get.
  • Signals: /signal shows the current practice setup, or WAIT if there isn't a safe one.
  • Results: /history lists saved setups, and /performance runs a backtest on past data.
  • Health check: /status and /data_status show whether the scheduler, data sources and database are working.

How a signal is decided

The bot never guesses. A BUY or SELL practice setup only appears when all five checks agree on the most recent finished candle:

  1. Trend: the 20- and 50-period moving averages point the same way.
  2. Momentum: the MACD histogram points that way too.
  3. Strength: RSI is at least 55 for a buy, or at most 45 for a sell.
  4. Position: the price closed above (or below) its 20-period average.
  5. Breakout: the price closed above the resistance level (or below the support level) of the previous 20 candles.

If even one check disagrees, or the data is old, incomplete or has gaps, the answer is WAIT, with no prices at all. When a setup does pass, the stop-loss and targets come from the market's recent volatility (ATR), and the first target has to be worth at least 1.5 times the risk, or the setup is thrown out.

How it's built

Telegram

You chat with the bot

  • Commands
  • Alerts

C++20 core

The main program

  • Commands & scheduler
  • Signal checks & risk rules
  • SQLite storage

Python worker

Restricted helper

  • Gold API prices
  • RSS news
  • Gemini AI
How it fits together: Telegram, the C++20 core and the Python worker. Docker packages it all for Railway.

The main program is written in C++20. It talks to Telegram, runs the schedule that checks the market every few minutes, validates every signal against risk rules (for example, a minimum risk-to-reward ratio), and saves everything in SQLite.

Calls to gold prices, news feeds and Gemini run in a separate, restricted Python worker. The C++ program starts it directly without a shell, talks to it in a strict, versioned JSON format with size limits and timeouts, and gives it only the keys it needs. If the Python and C++ indicator results disagree, no signal is sent.

Keeping the AI honest

Gemini only explains a setup. It can't create one or change any of its prices. To keep its answers trustworthy:

  • Every answer has to be split into Facts, Possible implications and Uncertainty. An answer without those sections, or one that tells me to buy or sell, is rejected.
  • News headlines are treated as untrusted text, so a headline can't sneak instructions into the prompt.
  • Source links are added by the bot itself, not written by the AI, so they can't be made up.
  • If Gemini is down or out of free quota, news alerts still arrive with the headline, time and link.

The hardest problem: real gold data

The signals work on 5-minute candles, but the free gold price service only gives a current price and a 24-hour range. Real minute-by-minute history is a paid feature. The easy shortcut would have been to build fake candles out of price snapshots. I chose not to, because signals made from fake candles would look correct while being wrong.

Instead, the bot shows DATA UNAVAILABLE and stays on WAIT until it has genuine candles. I also built two ways to get real data:

  • An optional, read-only connection to OANDA's practice (demo) API, which provides real 5-minute gold candles.
  • An importer for downloaded historical gold files, used only for backtesting and never for live alerts.

Testing

The project has 95 automated tests (62 in C++ and 33 in Python). They use saved sample data and fake versions of Telegram, the news feeds and Gemini, so they never call a real service.

The backtester is built to avoid "cheating with the future":

  • Each decision only uses the candles that existed at that moment.
  • Trades enter at the next candle's open.
  • If a candle hits both the stop-loss and the target, it counts as a loss, because there's no way to know which came first.

What's next

  • Connect a reliable source of real 5-minute gold candles, so gold signals can move past WAIT.
  • Follow practice trades forward in time, not only in backtests.
HomeSection on the homepage
AboutSection on the homepage
ExperienceSection on the homepage
ProjectsPage
ContactSection on the homepage
AI Trading Signal BotC++ · Python · Gemini AI
Personal PortfolioNext.js · React · TypeScript
Cambodia Odyssey – Trip PlannerReact · TypeScript · Vite
Copy emailchounlyhour13@gmail.com
Send an emailOpens your email app
Switch to dark themeChange how the site looks