# Model Stacking

Model Stacking is an indicator on [Vela](https://vela.luxalgo.com/chart), our next-generation charting platform, written in Pine Script®.

Trains three small logistic models on momentum, mean-reversion and volume/volatility features, then blends their stored out-of-fold predictions through a ridge-regularized meta-learner into one stacked probability plotted from 0 to 100%. A dashboard reports each base model's learned weight and out-of-sample hit rate, and four alerts cover the 60/40 thresholds and midline crosses.

- Indicator in the LuxAlgo Library, by LuxAlgo, published May 30, 2026.
- Access: free.
- Concepts: [Model Stacking](https://www.luxalgo.com/library/concept/model-stacking/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=wcwvoqd11k27mf9fkhkl5va1
- Page: https://www.luxalgo.com/library/indicator/model-stacking/

**Model Stacking** runs a stacked ensemble bar by bar: three logistic base learners (momentum, mean reversion and volume/volatility) and a meta-learner that blends their outputs into one probability of price closing higher after the prediction horizon. The mechanical heart of [model stacking](https://www.luxalgo.com/library/concept/model-stacking/) is respected: every stored base prediction is out-of-fold, made before its outcome is known or trained on. The stacked line plots 0-100% with a gradient fill, dashed thresholds and, optionally, the three base probabilities behind it.

## How to Trade the Model Stacking?

- **Cross above the Upper Threshold**: decisively bullish; below the Lower Threshold is the bearish mirror, both alerted, as are 50% midline crosses.
- **Line hugging 50%**: the bases disagree or the ridge penalty is keeping the combiner cautious. The stack has no opinion, itself usable information.
- **Read the dashboard first**: each base's learned weight and out-of-sample hit rate, the stack's own hit rate, and its edge over the best base: whether blending adds anything here.

## Model Stacking Settings

- **Prediction Horizon** (default 5): bars ahead each model predicts.
- **Feature Length** (default 14): lookback behind the nine normalized features.
- **Training Window** (default 200): resolved out-of-fold samples kept for training and hit-rate measurement.
- **Base Learning Rate** (default 0.5) and **Meta Learning Rate** (default 0.2): gradient steps of the once-per-bar, walk-forward training pass.
- **Meta Ridge (L2)** (default 0.02): shrinks the meta weights so the combiner stays simple.
- **Upper Threshold** (default 60) and **Lower Threshold** (default 40): the decisive-signal levels.
- **Show Base Model Probabilities** (on) and **Show Dashboard** (on, Top Right, Small).

## Frequently Asked Questions

### How does stacking differ from ensemble voting?

[Ensemble voting](https://www.luxalgo.com/library/indicator/ensemble-voting-of-signals/) counts agreement between finished signals under a fixed rule. Stacking trains the combiner itself: the meta-learner fits the stored out-of-fold base predictions and can learn that one model deserves systematically more weight.

### Why must the meta-learner train on out-of-fold predictions?

Trained on in-sample predictions, it would learn to trust each base exactly where that base memorized the data. Each bar's outputs are therefore computed before the label exists or any training touches it; only those stored values reach the meta-learner.

### Do the plotted probabilities repaint?

No. Each bar's value comes from the weights as they stood on that bar and is never revised. The models keep retraining as samples resolve, so similar conditions can map to different probabilities later, but history stays as printed.

## Related indicators

- [Ensemble Voting of Signals](https://www.luxalgo.com/library/indicator/ensemble-voting-of-signals/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/ensemble-voting-of-signals.md
- [Bagging](https://www.luxalgo.com/library/indicator/bagging/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/bagging.md
- [SuperTrend AI (Clustering)](https://www.luxalgo.com/library/indicator/supertrend-ai-clustering/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/supertrend-ai-clustering.md
- [KNN Supertrend Horizon](https://www.luxalgo.com/library/indicator/knn-supertrend-horizon/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/knn-supertrend-horizon.md
- [Nadaraya-Watson Envelope](https://www.luxalgo.com/library/indicator/nadaraya-watson-envelope/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/nadaraya-watson-envelope.md
- [kNN Market Architecture](https://www.luxalgo.com/library/indicator/knn-market-architecture/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/knn-market-architecture.md
- [Dynamic Time Warping Similarity](https://www.luxalgo.com/library/indicator/dynamic-time-warping-similarity/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/dynamic-time-warping-similarity.md
- [Machine Learning Moving Average](https://www.luxalgo.com/library/indicator/machine-learning-moving-average/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/machine-learning-moving-average.md

---

Source: https://www.luxalgo.com/library/indicator/model-stacking/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
