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
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 features | Returns (1d, 7d, 30d), volatility (rolling std), RSI, MACD histogram, distance from moving averages, Bollinger Band position, ATR. |
| Volume features | Volume ratio (today vs 20-day avg), OBV trend, volume-weighted price deviation, buy/sell volume ratio if available. |
| On-chain features | Exchange inflows/outflows, active addresses, MVRV z-score, SOPR, funding rate, open interest changes: Thrive's analytics provide these pre-computed. |
| Sentiment features | Fear & Greed Index, social media volume, search trends, funding rate direction (sentiment proxy). Encode as numerical scores. |
1def engineer_features(df):2 """Create ML features from OHLCV + on-chain data."""3 features = pd.DataFrame(index=df.index)45 # Price-based6 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() - 112 features['close_vs_sma200'] = df['close'] / df['close'].rolling(200).mean() - 11314 # Volume-based15 features['volume_ratio'] = df['volume'] / df['volume'].rolling(20).mean()1617 # Target: next 7-day return classification18 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, bullish2122 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.
1from xgboost import XGBClassifier2from sklearn.metrics import classification_report34features = engineer_features(df)5feature_cols = [c for c in features.columns if c != 'target']67# TEMPORAL split: never random for time series8split_date = '2024-01-01'9train = features.loc[:split_date]10test = features.loc[split_date:]1112X_train, y_train = train[feature_cols], train['target']13X_test, y_test = test[feature_cols], test['target']1415model = XGBClassifier(16 n_estimators=200,17 max_depth=4, # shallow trees reduce overfitting18 learning_rate=0.05,19 subsample=0.8,20 colsample_bytree=0.8,21 random_state=4222)2324model.fit(X_train, y_train, eval_set=[(X_test, y_test)],25 verbose=False)2627predictions = 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
Evaluating ML Models
| Accuracy | Percentage of correct predictions. Misleading in imbalanced datasets: predicting "neutral" every day might give 60% accuracy but zero trading value. |
| Precision | When the model says "bullish," how often is it correct? High precision means fewer false signals. Critical for trading where false signals cost money. |
| Recall | Of all actual bullish days, how many did the model catch? High recall means fewer missed opportunities. Trade-off with precision. |
| F1 score | Harmonic 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.
Features computed using future data (even accidentally), random train/test splits, or target variables that peek ahead. The most common and most fatal error.
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.
A feature that is a proxy for the target (like next-day open price) gives perfect accuracy in backtesting and zero value in production.
Testing only on assets that still exist. The model never learned from the tokens that went to zero, which biases predictions upward.
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
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?
Put this lesson to work
Free on Thrive, no account needed.