DEV Community

eventhorizon-ai
eventhorizon-ai

Posted on

Lessons from building a Multi-Horizon Crypto Prediction System with Transformers

I started this project in January 2026 with a simple question: can a Transformer trained on technical indicators predict Bitcoin's direction better than a coin toss?

By June, the system had processed over 87,000 training generations, survived three major architectural bugs, and taught me more about machine learning than any course could.

This is not a "how to get rich with AI" post. This is the engineering story.

Architecture Overview

The system uses a hybrid Transformer + BiLSTM architecture:

  • Transformer: 6 blocks, 8 attention heads. Same architecture that powers GPT and BERT, adapted for financial time series. The self-attention mechanism captures short-term patterns across different technical indicators.
  • BiLSTM: 2-layer bidirectional LSTM. Handles long-range dependencies that the Transformer might miss — for example, regime changes that unfold over hours or days.
  • Cross-attention layer: Fuses the representations from both branches before feeding them to the prediction heads.
  • 10 specialized heads: One per temporal horizon — from 5 seconds to 1 day. Each head has a different depth and regularization, reflecting the noise profile of its horizon.

The entire network is custom-built in PyTorch. No AutoML. No third-party trading libraries. Every tensor, every gradient, every loss function — implemented from scratch.

The Verification Pipeline

Most crypto prediction systems show backtest results. Backtests lie.

I built a verification pipeline that timestamps every prediction. When the target horizon elapses, the system compares the prediction against the real Binance price and logs the result. No cherry-picking. No deleted trades. The audit panel is public.

This commitment to transparency became the project's core value. But it also exposed a bug that almost made me quit.

Bug #1: Autocorrelation (The 96% Lie)

I was getting 96% accuracy on 5-minute predictions. I celebrated. Then I looked at the raw data:

[0, 0, 0, 0, 0, 0, 0, 0, ... 300 zeros in a row ...]
[1, 1, 1, 1, 1, 1, 1, 1, ... 200 ones in a row ...]

Enter fullscreen mode Exit fullscreen mode

No model produces results like this. The problem was temporal dependence: I was recording a "trade" every 2 seconds, then verifying all ~900 snapshots against the same market event. The model wasn't predicting price direction — it was just reflecting whether the market went up or down in that window.
I fixed this with statistical subsampling:

_FATOR_SUBSAMPLE = {
    5: 1,       # 5s: record every tick
    60: 5,      # 1min: record every 5th tick
    300: 25,    # 5min: record every 25th tick
    1800: 150,  # 30min: record every 150th tick (5 min)
    3600: 300,  # 1h: record every 300th tick (10 min)
}

Enter fullscreen mode Exit fullscreen mode

Accuracy dropped from 96% to ~52%. It hurt. But now every trade in the history represents an independent decision by the model.

Bug #2: Look-Ahead Bias

If you predict a 1-hour horizon, you should only receive the reward 1 hour later — not a second sooner. But my early implementation allowed future price information to leak into the training signal.
The fix was a Delayed Reward Buffer. Every prediction is stored with its timestamp. The reward is computed and applied only when the target horizon actually elapses. The model never sees the future during training.

Bug #3: Gradient Truncation

For weeks, my Transformer and LSTM weren't actually learning. The gradient from the loss function was stopping at the prediction heads — it never reached the backbone.
I had to recompute the full forward pass during gradient computation, ensuring the error signal propagated through the entire network. My computer fans immediately spun up louder. The backbone was finally learning.

Current State

After fixing these bugs and training on 365 days of Binance data with a T4 GPU:

  • 54.9% average directional accuracy (5s–1h horizons)
  • 59.8% on 1-hour predictions (best individual horizon)
  • All metrics are publicly auditable against real Binance prices These numbers won't make anyone rich overnight. But they're real. And in a market saturated with fake performance claims, real metrics are a differentiator. ## What I Learned Building this system taught me three things that no course could:
  • Trust metrics, not feelings. When accuracy is 96%, something is broken. When it's 53%, it might be working perfectly. The numbers tell the truth — if you let them.
  • Transparency compounds. The audit panel was a burden to maintain at first. Now it's my strongest signal of credibility. In a market full of scams, showing your losses is more convincing than hiding them.
  • Patience over hype. The hardest bug (autocorrelation) took three days to diagnose and one line to fix. There is no shortcut.

Links




Enter fullscreen mode Exit fullscreen mode

Top comments (0)