🧠 Understand gradient boosting and XGBoost
Using machine learning to trade successfully helps you understand exactly what’s going on inside your asset data. Core theory Gradient boosting is a powerful machine learning technique used for regression and classification tasks. Unlike deep learning networks, which process data through abstract layers of nodes, gradient boosting relies on an ensemble of simple decision trees, often called “weak learners” or “stamps.”
The training process works sequentially.
- Initial guess: The model makes basic baseline predictions. Calculate error (residuals): Check where the forecast deviates from actual historical market results.
- Correcting mistakes: A new decision tree is constructed specifically to predict those mistakes (the slope of the loss function).
- Iterative learning: The model repeats this process several rounds. Each new tree is dedicated to fixing the deficiencies of the previous tree, and adjusts the adjustments by the learning rate to maintain stability.
What’s special about XGBoost?
XGBoost (Extreme Gradient Boosting) optimizes this framework for speed, scalability, and performance. Apply strict regularization techniques to minimize overfitting and ensure that the model learns true structural behavior rather than simply “remembering” past market noise. Estimate the probability that a specific event will occur by evaluating multiple market characteristics simultaneously.
🛠️About indicators
XGBoost Lite: Reversals is a machine learning-driven technical indicator designed to capture depletion and reversal setups.
machine learning pipeline
- Dual Engine: The script simultaneously fits four separate models: a long classifier and regressor, and a short classifier and regressor.
- Dynamic retraining: The model does not remain static, but automatically flushes memory and retrains internal mathematical weights every n bars to adapt to evolving market regimes.
- Strict non-redraw execution: An important upgrade to this framework ensures that functions and calculations are strictly computed and locked when the bar closes. Signals, dynamic entry points, and risk metrics are printed only after the triggering candle is confirmed, ensuring that what you see on the historical chart exactly matches the real-time execution.
Core features evaluated
The model processes a combination of multidimensional market inputs to generate an integrated forecast.
- RSI (14): Evaluates the expansion and contraction of conventional momentum.
- Relative Volume (20): Evaluates an institution’s commitment by dividing its current volume by its 20-period SMA.
- Z-score (20): Measures how far the current price deviates from the statistical average.
- ADX (14): Measures the overall strength of macro trends to prevent direct trades into runaway freight trains.
📊 How to use indicators
- Real-time dashboard: When applied to a chart, the indicator renders an advanced feature importance scatter plot in the right margin.
- Distribution scatter plot: horizontal bars plot the historical density of successful signals. Dark, dense nodes represent highly concentrated, high probability clusters detected by the algorithm.
Signal visualization
When a market pivot (e.g. a structural low or high swing) is detected and the classifier reaches the target confirmation probability, a signal arrow is printed on the chart to indicate mathematical certainty ($example74.2\%$).
⚙️ Settings input
The indicator’s interface is neatly divided into three main functional groups:
⚙️ XGBoost model settings:
- Training Lookback (bar): (default: 250) History window used to feed the training array. The maximum value is limited to 300 to allow calculations within the limits of Pine Script.
- Retrain Frequency: (Default: 50) Determines how often (in bars) the model retrains the tree. Boosting Rounds: (Default: 20) Number of consecutive trees (stumps) trained per model. Higher numbers allow you to capture more complexity, but you run the risk of overfitting.
- Learning Rate: (Default: 0.3) The step size applied to each boosting round to prevent the model from training too quickly. Minimum Probability of Signal: (Default: 0.65) The minimum confidence threshold ($65\%$) required from the classification model to trigger an active trade.
- ADX Length/Min Filter: (Default: 14 / 20.0) Prevents countertrend signals when the general macro trend is too strong.
🛡️ Goal and risk management
- SL Wick Buffer ×ATR: (Default: 0.25) Sets how much breathing space to give below the swing low wick or above the swing high wick, depending on the ATR.
- TP1 × Risk (R multiple): (default: 1.0) We aim for a 1:1 risk-to-reward ratio for initial profit taking.
- TP3 Min × Risk (Floor): (Default: 2.0) Minimum target floor for machine learning regression targets.
- Breakeven after TP1: (Default: True) Automatically moves the stop loss to the exact entry price the moment TP1 is captured, eliminating the remaining risk of the trade.
📈 How to trade indicators
Trading with machine learning models requires a blend of quantitative probabilities and standard structural execution.
entry: Wait until the bullish (neon purple) or bearish (neon pink) arrow is confirmed on a closed candlestick. The percentage output indicates the reliability of the model.
Risk settings: The system automatically draws a solid line that firmly anchors the stop loss to the local structural core pivot and applies an ATR buffer to account for minor noise.
Scaling target:
- Target 1 (TP1): Lands at a symmetrical 1:1 distance. Once hit, the indicator dynamically updates the stop loss to the entry line, anchoring the “scratch or better” runner.
- Target 2 (TP2): Represents the mathematical midpoint between the baseline risk and the macro ML objective.
- Target 3 (TP3): Directly driven by the XGBoost regression model. Regressors estimate potential mathematical expansion based on current market characteristics. If volatility is expanding, TP3 will automatically expand further to ride the big trend change.
📊 Learn more: Feature importance and scatter plot dashboard
The dashboard, which appears to the right of the chart, acts as the “brain” of the indicator. This allows you to see in real-time exactly how your machine learning models are evaluating your data and assessing current market conditions.
Feature importance bar (relative weight): The horizontal progress bar displays the percentage of mathematical weight assigned to each of the four indicators processed during the model’s most recent training cycle. These values change dynamically every time you trigger a retraining block (default: every 50 bars) as the model adapts to changing market conditions. For example, if the market moves into a strong trend phase, you will see indicators such as ADX and Z-Score occupying a higher proportion of the model’s attention, while RSI is often the dominant factor when the asset is in a range.
Holographic scatter plot (historical feature density): Overlaid above the progress bar is an advanced distribution scatter plot consisting of individual circular glyphs (○, ◉, ●) that plot a rolling record of the last 30 historical signal points. The horizontal position of each dot shows exactly where the feature value has landed compared to the past extreme values (0 on the far left, 1 on the far right). This script introduces a subtle vertical “jitter” to separate these dots, allowing us to visually identify dense clusters where successful inversion setups frequently occur. On the other hand, the glyph shifting style flags clusters of dense solid nodes (●), indicating highly concentrated mathematical sweet spots detected by the XGBoost classifier.
