Skip to main content

ML for Crypto Signals

Classification models for signal generation, feature engineering with on-chain data, XGBoost basics, why most ML backtests fail, and responsible ML trading.

From Thrive on YouTube

Watch the matching Thrive video

More on YouTube
On-Chain Analysis Explained: The Complete Guide for Crypto Traders

On-Chain Analysis Explained: The Complete Guide for Crypto Traders

Education only. Not financial advice.

Why ML in Crypto Is Hard

Machine learning in crypto is not like image classification where adding more data reliably improves results. Crypto markets are non-stationary: the statistical properties of the data change over time. A model trained on the 2021 bull market learns patterns that are useless in the 2022 bear. Regime changes (from trending to ranging, from low to high volatility) invalidate learned relationships without warning.

The dataset is small by ML standards. BTC has existed since 2009 with reliable data from roughly 2015. That gives you about 10 years of daily data: 3,650 samples. A model for cat photos trains on millions of images. A model for crypto prediction trains on thousands of candles, many of which occurred in fundamentally different market regimes. Overfitting is not a risk. It is the default outcome.

Feature Engineering

Features are the inputs your model uses to make predictions. In crypto ML, the quality of your features matters far more than the sophistication of your model. A simple model with excellent features will outperform a complex model with garbage features every time.

Price featuresReturns (1d, 7d, 30d), volatility (rolling std), RSI, MACD histogram, distance from moving averages, Bollinger Band position, ATR.
Volume featuresVolume ratio (today vs 20-day avg), OBV trend, volume-weighted price deviation, buy/sell volume ratio if available.
On-chain featuresExchange inflows/outflows, active addresses, MVRV z-score, SOPR, funding rate, open interest changes: Thrive's analytics provide these pre-computed.
Sentiment featuresFear & Greed Index, social media volume, search trends, funding rate direction (sentiment proxy). Encode as numerical scores.
python-Feature engineering pipeline
1def engineer_features(df):
2 """Create ML features from OHLCV + on-chain data."""
3 features = pd.DataFrame(index=df.index)
4
5 # Price-based
6 features['return_1d'] = df['close'].pct_change(1)
7 features['return_7d'] = df['close'].pct_change(7)
8 features['return_30d'] = df['close'].pct_change(30)
9 features['volatility_14d'] = df['close'].pct_change().rolling(14).std()
10 features['rsi_14'] = compute_rsi(df['close'], 14)
11 features['close_vs_sma50'] = df['close'] / df['close'].rolling(50).mean() - 1
12 features['close_vs_sma200'] = df['close'] / df['close'].rolling(200).mean() - 1
13
14 # Volume-based
15 features['volume_ratio'] = df['volume'] / df['volume'].rolling(20).mean()
16
17 # Target: next 7-day return classification
18 fwd_return = df['close'].pct_change(7).shift(-7)
19 features['target'] = pd.cut(fwd_return, bins=[-np.inf, -0.03, 0.03, np.inf],
20 labels=[0, 1, 2]) # bearish, neutral, bullish
21
22 return features.dropna()

XGBoost for Classification

XGBoost (Extreme Gradient Boosting) is the workhorse of tabular ML. It builds an ensemble of decision trees, where each tree corrects the errors of the previous ones. For crypto classification (bullish/bearish/neutral), XGBoost handles mixed feature types, missing values, and nonlinear relationships well.

python-Training an XGBoost classifier
1from xgboost import XGBClassifier
2from sklearn.metrics import classification_report
3
4features = engineer_features(df)
5feature_cols = [c for c in features.columns if c != 'target']
6
7# TEMPORAL split: never random for time series
8split_date = '2024-01-01'
9train = features.loc[:split_date]
10test = features.loc[split_date:]
11
12X_train, y_train = train[feature_cols], train['target']
13X_test, y_test = test[feature_cols], test['target']
14
15model = XGBClassifier(
16 n_estimators=200,
17 max_depth=4, # shallow trees reduce overfitting
18 learning_rate=0.05,
19 subsample=0.8,
20 colsample_bytree=0.8,
21 random_state=42
22)
23
24model.fit(X_train, y_train, eval_set=[(X_test, y_test)],
25 verbose=False)
26
27predictions = model.predict(X_test)
28print(classification_report(y_test, predictions,
29 target_names=['Bearish', 'Neutral', 'Bullish']))

NEVER use random train/test splits on time series

Random splitting leaks future information into the training set. Your model will see data from 2024 while "predicting" 2023: inflating accuracy dramatically. Always split temporally: train on the past, test on the future. If your model performs well with a random split but poorly with a temporal split, it has learned to time-travel, not to trade.

Evaluating ML Models

AccuracyPercentage of correct predictions. Misleading in imbalanced datasets: predicting "neutral" every day might give 60% accuracy but zero trading value.
PrecisionWhen the model says "bullish," how often is it correct? High precision means fewer false signals. Critical for trading where false signals cost money.
RecallOf all actual bullish days, how many did the model catch? High recall means fewer missed opportunities. Trade-off with precision.
F1 scoreHarmonic mean of precision and recall. Balances both metrics. Use macro-averaged F1 for multi-class evaluation. Above 0.45 for 3-class crypto prediction is respectable.

Why 99% of ML Backtests Fail in Production

The crypto ML graveyard is filled with beautiful backtests. The most common failure modes are not technical. They are methodological.

Look-ahead bias

Features computed using future data (even accidentally), random train/test splits, or target variables that peek ahead. The most common and most fatal error.

Overfitting to the past regime

A model trained on a trending market cannot handle a ranging market. Crypto changes regime every 6–18 months. Your model has an expiration date.

Feature leakage

A feature that is a proxy for the target (like next-day open price) gives perfect accuracy in backtesting and zero value in production.

Survivorship bias

Testing only on assets that still exist. The model never learned from the tokens that went to zero, which biases predictions upward.

Ignoring transaction costs

A model that generates 100 trades per month with 0.5% edge per trade loses money after 0.1% fees × 2 (buy + sell) per trade.

Responsible ML Trading

The most effective approach treats ML as one input among many, not an oracle. Use ML predictions to confirm or challenge your discretionary analysis. When the model, the derivatives data, the on-chain metrics, and your chart analysis all agree, you have convergence. When they disagree, you have a reason to stay cautious.

ML as a filter, not a strategy

The highest-value application of ML in crypto is not pure prediction. It is filtering. Use your model to identify the 20% of market conditions where your strategy has the highest win rate, and only trade during those windows. A simple moving average strategy that only trades when an ML model says conditions are favorable can dramatically improve risk-adjusted returns compared to trading the strategy blindly.
Module Quiz

1.Why is random train/test splitting dangerous for time-series ML models in crypto?

2.What makes vectorbt significantly faster than traditional loop-based backtesting frameworks?

3.A backtest shows a strategy with 80% returns. The Sharpe ratio is 0.4 and the p-value from a t-test is 0.15. What should you conclude?

4.What is the primary purpose of walk-forward analysis in strategy validation?

5.Why do 99% of ML backtests fail when deployed in live crypto markets?

0/5 answered

Put this lesson to work

Free on Thrive, no account needed.