# Decision Trees

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

Decision Trees grows a CART tree walk-forward on five stationary features (RSI, relative volume, rate of change, Stochastic %K, and ATR %) to predict direction probability, forward return, or forward volatility over a 10-bar horizon. The prediction plots as an oscillator, and a rules table lists every leaf as an auditable if-then rule, marking the live bar's leaf.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Jun 9, 2026.
- Access: free.
- Concepts: [Decision Trees](https://www.luxalgo.com/library/concept/decision-trees/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=sbnp1tis0q1ljothbijmv0q2
- Page: https://www.luxalgo.com/library/indicator/decision-trees/

**Decision Trees** brings [decision trees](https://www.luxalgo.com/library/concept/decision-trees/) to the chart as a genuine CART implementation. Each retrain grows a depth-limited tree on the most recent window, labeled by what close did over the following bars; the live bar routes down it and the leaf's prediction plots as an oscillator: P(up) around 50% for Direction, a percent return around zero for Forward Return, and a non-negative volatility reading for Forward Volatility. The rules table is the heart: one row per leaf with its conditions, an arrow on the live bar's row.

## How to Trade the Decision Trees?

- **Prediction above the center**: the routed leaf favors upside; center crossings fire the Bullish and Bearish Flip alerts.
- **High-confidence guides**: on the Direction target, dashed 70%/30% levels isolate the strongest readings for gating other strategies.
- **Read the active rule**: the arrowed row says why the model leans as it does; if they look like noise, treat the signal that way.

Training uses only closed bars whose forward horizon is realized, no lookahead. The build sits in the Library's [machine-learning family](https://www.luxalgo.com/library/family/machine-learning/).

## Decision Trees Settings

- **Target** (default Direction (Up/Down)): classification, or regression on Forward Return % / Forward Volatility %.
- **Impurity Measure** (default Gini): split rule for Direction; regression uses variance.
- **Prediction Horizon (bars)** (default 10), **Training Window (samples)** (default 200), **Retrain Every (bars)** (default 10): labeling, sampling, and refit cadence.
- **Maximum Depth** (default 3) and **Minimum Leaf Size** (default 20): the readability stopping rules.
- **Minimum Gain** (default 0) and **Split Candidates** (default 24): pre-pruning and threshold search granularity.
- **High-Confidence Level %** (default 70): the dashed guides and alerts.
- Features: **RSI** (Length 14), **Relative Volume** (Length 20), **Rate of Change %** (Length 10), **Stochastic %K** (Length 14), **ATR %** (Length 14), all on by default with toggles.
- **Show Rules Table** (default on) plus location, size, colors.

## Frequently Asked Questions

### Why a single tree instead of a Random Forest?

Transparency. The [Random Forest](https://www.luxalgo.com/library/indicator/random-forest/) averages many randomized trees, taming variance but burying logic; this build accepts instability to keep every rule auditable.

### How do I fight overfitting?

Depth and leaf size are the levers: shallow trees with generous leaves cannot memorize much. Each extra level doubles the regions available to fit noise; Minimum Gain discards splits that barely improve purity.

### Why did the oscillator jump without price moving?

A retrain replaced the tree, and the new structure can route the same features to a different leaf. Longer windows, lower depth, and slower retraining make jumps rarer.

## Related indicators

- [Nadaraya-Watson Envelope](https://www.luxalgo.com/library/indicator/nadaraya-watson-envelope/) (Kernel Regression): markdown at https://www.luxalgo.com/library/indicator/nadaraya-watson-envelope.md
- [Nadaraya-Watson Smoothers](https://www.luxalgo.com/library/indicator/nadaraya-watson-smoothers/) (Kernel Regression): markdown at https://www.luxalgo.com/library/indicator/nadaraya-watson-smoothers.md
- [Gaussian Volume Profile](https://www.luxalgo.com/library/indicator/gaussian-volume-profile/) (Kernel Density Estimation): markdown at https://www.luxalgo.com/library/indicator/gaussian-volume-profile.md
- [KDE Value Clouds](https://www.luxalgo.com/library/indicator/kde-value-clouds/) (Kernel Density Estimation): markdown at https://www.luxalgo.com/library/indicator/kde-value-clouds.md
- [Structural SVM Ranker](https://www.luxalgo.com/library/indicator/structural-svm-ranker/) (Support Vector Machines): markdown at https://www.luxalgo.com/library/indicator/structural-svm-ranker.md
- [Machine Learning: Gaussian Process Regression](https://www.luxalgo.com/library/indicator/machine-learning-gaussian-process-regression/) (Kernel Regression): markdown at https://www.luxalgo.com/library/indicator/machine-learning-gaussian-process-regression.md
- [Gradient Boosting](https://www.luxalgo.com/library/indicator/gradient-boosting/) (Machine Learning): markdown at https://www.luxalgo.com/library/indicator/gradient-boosting.md
- [Machine Learning: Anchored Gaussian Process Regression](https://www.luxalgo.com/library/indicator/machine-learning-anchored-gaussian-process-regression/) (Kernel Regression): markdown at https://www.luxalgo.com/library/indicator/machine-learning-anchored-gaussian-process-regression.md

---

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