DEV Community

Dennis Arnum Sørensen
Dennis Arnum Sørensen

Posted on • Originally published at app.intelligentcryptotrading.com

How We Built an AI That Explains Every Crypto Trade It Makes

Why We Built This

Most crypto trading bots are black boxes. They buy. They sell. They lose your money. And they never tell you why.

We wanted to build something different: a platform where every single trade comes with a plain-English explanation written by an AI — not a template, not a lookup table, but actual reasoning about what the market was doing and why the algorithm acted the way it did.

This is the technical story of how we built that.


The Architecture at a Glance

Our platform runs 26 trading strategies across 7 exchanges simultaneously. When a trade signal fires, it passes through three layers before execution:

  1. Signal scoring — A LightGBM model evaluates 20+ market factors to assign a probability score
  2. Trade explanation — An Ollama/Llama 3.1 8B instance generates a natural language explanation
  3. Portfolio AI — A meta-layer decides position sizing and risk allocation

Let's dig into each.


Layer 1: ML Signal Scoring with LightGBM

Before any trade executes, it gets scored by a gradient boosting model trained on historical signal performance.

The model ingests a context dictionary built in Python:

signal_context = {
    "strategy": strategy_name,
    "symbol": trading_pair,
    "exchange": exchange_id,
    "signal_type": "BUY" | "SELL",
    "timeframe": "1h" | "4h" | "1d",

    # Price action
    "price_change_1h": float,
    "price_change_24h": float,
    "price_change_7d": float,

    # Volume
    "volume_ratio": float,          # current vs 20-period avg
    "volume_trend": float,          # slope of volume

    # Technical indicators
    "rsi_14": float,
    "macd_signal": float,
    "bb_position": float,           # position within Bollinger Bands
    "atr_normalized": float,        # volatility measure

    # Market structure  
    "trend_strength": float,
    "support_distance": float,
    "resistance_distance": float,

    # Cross-asset
    "btc_correlation": float,
    "market_dominance": float,

    # Strategy-specific metadata
    "strategy_win_rate_30d": float,
    "strategy_avg_return": float,
    "time_since_last_signal": int,
}
Enter fullscreen mode Exit fullscreen mode

The model outputs a probability score between 0 and 1. Signals below 0.45 are filtered out entirely. Signals above 0.75 get flagged for increased position sizing.


Layer 2: AI Trade Explanations via Ollama

This is the part we're most proud of.

After scoring, the signal context gets passed to a local Ollama instance running Llama 3.1 8B. We run this locally (not via API) to keep latency under 2 seconds and avoid per-explanation costs at scale.

The prompt is structured to force the model to reason like a trader:

def build_explanation_prompt(context: dict) -> str:
    return f"""You are a professional crypto trader explaining a trade decision to a client.

Trade Signal:
- Asset: {context['symbol']} on {context['exchange']}
- Action: {context['signal_type']}
- Strategy: {context['strategy']}
- ML Confidence Score: {context['ml_score']:.0%}

Market Conditions:
- Price change (1h/24h/7d): {context['price_change_1h']:+.1%} / {context['price_change_24h']:+.1%} / {context['price_change_7d']:+.1%}
- RSI(14): {context['rsi_14']:.1f}
- Volume vs average: {context['volume_ratio']:.1f}x
- Volatility (ATR): {context['atr_normalized']:.3f}

Write a 2-3 sentence explanation of WHY this trade makes sense right now.
Be specific about the market conditions. Do not use filler phrases.
Write as if explaining to someone who understands trading basics."""
Enter fullscreen mode Exit fullscreen mode

The output looks like this:

"ETH is showing a strong momentum breakout on the 4h chart, with RSI at 67 indicating bullish pressure without yet reaching overbought territory. Volume is running at 2.3x the 20-period average, confirming institutional participation in this move. The 24h price action of +4.2% combined with declining sell-side pressure near the $2,840 resistance suggests continuation is probable."

No templates. No mad-libs. Actual reasoning.


Layer 3: Portfolio AI

The Portfolio AI sits above individual strategies and makes allocation decisions across the whole portfolio.

It considers:

  • Current open positions and their unrealized P&L
  • Correlation between pending signals (avoids doubling up on correlated assets)
  • Account drawdown limits
  • Strategy performance over the trailing 30 days
  • Market regime detection (trending vs ranging)

When multiple signals fire simultaneously, the Portfolio AI ranks them by a composite score combining ML probability, strategy recent performance, and portfolio exposure.


The Infrastructure

Everything runs on a self-hosted Proxmox cluster:

  • FastAPI backend (Python) handling strategy execution and API endpoints
  • PostgreSQL for trade history and strategy state
  • React/Vite frontend for the dashboard
  • Ollama container running Llama 3.1 8B (requires ~8GB VRAM or runs on CPU with ~16GB RAM)
  • Docker Compose orchestrating everything

The AI explanation step adds roughly 1.2-1.8 seconds to signal processing time. We consider this acceptable — humans read the explanation, and the few extra seconds don't affect execution on the exchanges.


What's Next

We're currently working on:

  • Backtesting with explanations — so users can review AI reasoning on historical signals
  • Explanation quality scoring — using a secondary model to rate explanation accuracy
  • Strategy suggestions — letting the AI propose new strategy parameters based on what's been working

If you're building in the crypto + AI space, we'd love to compare notes.

👉 Try it live: app.intelligentcryptotrading.com

We're in beta — feedback welcome.

Top comments (0)