All indicators

Bagging

By LuxAlgoApr 30, 2026

Bagging is an indicator on Vela, our next-generation charting platform, written in Pine Script®.

Static chart image

Bagging implements bagging (bootstrap aggregating) end to end on the chart: 50 k-nearest-neighbors models, each fit on its own resample of the last 100 labeled observations, combine into one directional prediction between −1 and +1. Three standardized features feed every member: momentum, RSI and a price-stretch z-score; labels record whether close rose or fell over a 5-bar horizon.

Two layers make the method's point visible: an unbagged reference line shows the same k-NN trained once without resampling, and a dispersion band widens when members disagree, when the output depends on which observations were drawn.

How to Trade the Bagging?

  • Bagged Prediction above zero: the ensemble leans bullish; below zero, bearish. Zero crosses fire the alerts.
  • Wide dispersion band: the prediction is sample-sensitive; an alert fires when dispersion crosses 0.5.
  • ±1 dotted levels: unanimous membership.
  • OOB Error: out-of-bag scoring in the dashboard; readings near 50% say the ensemble finds no edge here.

Bagging Settings

  • Bootstrap Replicates (B) (default 50): number of resamples and members.
  • Training Window (n) (default 100): the training set; resamples are drawn at size n.
  • Neighbors (k) (default 5): each member's k-NN; small k is the high-variance regime bagging stabilizes.
  • Label Horizon (default 5): bars ahead used for labels.
  • Aggregation (default Average (Regression)): or Majority Vote (Classification).
  • Bootstrap Type (default Standard (IID)) with Block Length (default 10) for the block variant.
  • Random Seed (default 1): redraws the ensemble deterministically.
  • Disagreement Alert Level (default 0.5): dispersion that fires the alert.
  • Momentum Length (default 10), RSI Length (default 14), Mean Reversion Length (default 20): feature lookbacks.
  • Style toggles cover the gradient fill, dispersion band, single-model reference and the dashboard.

Frequently Asked Questions

Free to use

Run it on Vela. Go further with a paid plan.

  • Up to 500 Custom Alerts, with webhook automation
  • Up to 10× the chart history of Free
  • Orderflow lookback up to full history
  • More Quant usage to customize it, plus extra usage when you need it
  • Futures data alongside crypto, stocks, forex and commodities
See plans
Original indicatorBuilt in-house by LuxAlgo

Run it on Vela. Make it yours with Quant.

Open this indicator free on Vela, our next-generation charting platform. Then ask Quant, our coding agent built into Vela, to retune it or turn it into a backtested strategy of your own.