Private project · not a product

Every trade had to pass the rules first

CryptoBot is a trading bot I built in Delphi. It runs as a Windows service, reads the market minute by minute and only places an order when my rules agree. Before a rule went live, I could replay it on historical data.

4timeframes per coin, from 5 minutes to 3 days
9indicator families in the analysis tool
2live exchange integrations, Binance and Bitvavo
19,000handwritten lines of Delphi, roughly

Try a rule

See what a rule does

The bot buys when the MACD histogram turns positive after two negative candles, and sells on the opposite turn. Change the calculation or add a filter and watch the signals move.

Buy rules


        

Sell rules


        

These prices are invented in your browser. They are not market data, and nothing on this page is trading advice. The formulas and the rule syntax come from the bot; the RSI threshold is just an example.

The story

From a desktop tool to a service that keeps running

The first version I can still show you was a Windows application with a chart, a simulator and a box where I could type rules. If an idea looked good in hindsight, the simulator could show it trade by trade, including the trades that went wrong.

The trading itself then moved into a Windows service, so it no longer depended on an open window. Over the years it picked up the things long-running software needs: maintenance of its own database, a restart when a cycle hangs, a daily mail to say it's still alive, and a small web page to read its logs.

  1. The analysis toolCharts, indicators and simulation, with Binance and Bitfinex tabs
  2. A Windows serviceTrading moves out of the desktop app
  3. Master and paired servicesOne service can pass its decisions on to others
  4. BitvavoA second live exchange, followed by trading in several wallets at once
  5. Alive mail and log viewerA daily sign of life and its logs in a browser

How it works

Four steps, repeated every few seconds

  1. Collect

    One-minute candles come in from the exchange and are combined into 5-minute, 1-hour, 12-hour and 3-day views.

  2. Calculate

    Each view gets its indicators: three MACD variants, RSI, CCI, ADX, MFI, Awesome Oscillator and Bollinger Bands.

  3. Decide

    A scenario holds buy and sell rules per timeframe, with alternative rule sets. The bot only acts when a set passes completely.

  4. Protect

    After buying, a stop-sell order tracks the trade. Its distance is expressed in multiples of the exchange fee, and a separate escape rule can get out sooner.

Prices are moving in the wrong direction. Just keep those fingers crossed…From the mail the bot sends about an open trade, trimmed.

The rule language

Strategies as text, not as code

I didn't want to rebuild the bot for every new idea. So the rules are plain text: one condition per line, grouped into alternatives. The analysis tool, the simulator and the live service all read the same text.

  • And within an alternativeLines with the same number form one group. Every line in it has to be true, on every timeframe that has rules for it.
  • Or between alternativesA new number starts another way to get a yes. One alternative that passes is enough to trade.
  • Thresholds and comparisonsCompare any indicator with = <> > >= < <= against a number, true or false, or the candle's close price.
  • Buy, sell and escapeEach scenario has its own buy rules, sell rules and escape rules. An escape rule wins over a normal sell, to get out of a trade that goes wrong.
Per timeframeDifferent rules for the 5-minute, 1-hour, 12-hour and 3-day candles of the same coin.
Multiple scenariosA scenario per coin, a manual one, a sell-only one and a test scenario to try new ideas next to the live ones.
Settings next to the rulesSell only above a profit of a few times the exchange fee, a loss border for the escape, and a looser exit once the profit is large.
Test a single alternativeThe simulator can filter on alternatives, so you can see which group actually makes the trades.

Under the hood

A small system around one trading loop

The service

A native Windows service with generated data and business layers on my own Delphi library. API keys are stored encrypted, and live trading and simulation share the same bot code.

  • Delphi
  • Windows service
  • FireDAC
  • Firebird
  • DUnitX

The analysis tool

A desktop application for viewing charts, editing rules and running simulations. A second small app offers a manual "Buy now!" and "Sell now!" for when a person has to step in.

  • Delphi VCL
  • Scenarios
  • Simulation

The log viewer

A later addition: a small web app that shows the logs of the service in a browser, itself running as a Windows service through NSSM.

  • React
  • Vite
  • Express
  • NSSM