PINE LIBRARY
تم تحديثه Arbor_Gradient_Boosting_GainzAlgo

GainzAlgo is excited to bring the ability to perform gradient boosting and feature importance selection to Pine Script. Currently, there are no native capabilities within Pine Script for gradient boosting or feature importance selection. Arbor fills this significant gap by introducing a from-scratch Gradient Boosting Machine (GBM) engineered with XGBoost-style mechanics.
Designed to support both classification and regression tasks, and building on our Random Forest approach to Pinescript, Arbor utilizes depth-1 stumps, meaning it performs one split per round without column subsampling.
Because TradingView automatically lists the exported types and function parameters, the following outlines the core mechanics and capabilities you unlock by importing Arbor.
Core Mechanics
Arbor brings advanced machine-learning concepts directly into your Pine Script workflows:Advanced Training: Utilizes Newton leaf steps (second-order hessian weighting) and the exact XGBoost gain formula.
Regularization & Pruning: Integrates L2 regularization (lambda), minimum gain pruning (gamma), and minimum child weight checks to manage model complexity and prevent overfitting.
Stochasticity: Implements Fisher-Yates row subsampling to provide genuine round-to-round stochasticity matching XGBoost's subsample behavior.
Reproducibility: You can pass an optional seed to any fit function to ensure reproducible training runs across reloads.
Model Tiers
The library supports models scaled across three specific feature tiers:
GBM (1 Feature): Built for rapid classification or regression implementations.
GBM3 (3 Features): Purpose-built specifically for classification tasks.
GBM4 (4 Features): Supports both classification and regression, and uniquely offers XGBoost-style, gain-based feature importance evaluation.
Library "Arbor_Gradient_Boosting_GainzAlgo"
Arbor — gradient boosting for Pine Script. From-scratch GBM v2
with XGBoost-style mechanics: Fisher-Yates row subsampling, Newton leaf steps
(second-order hessian weighting), exact XGBoost gain formula with L2
regularization (lambda), minimum gain pruning (gamma), and minimum child
weight. Trees are depth-1 stumps (one split per round) and there is no
column (feature) subsampling — this is an XGBoost-style boosting scheme,
not a full XGBoost reimplementation. Supports classification and regression
across three feature tiers:
- GBM (1 feature) : gbm_fit / gbm_predict
classification or regression via is_classifier
- GBM3 (3 features) : gbm3_fit / gbm3_predict
classification only
- GBM4 (4 features) : gbm4_fit / gbm4_predict / gbm4_importance_pct
classification or regression with XGBoost-style
gain-based feature importance
All variants use Newton leaf steps, exact gain formula, L2 regularization,
Fisher-Yates shuffle subsampling, and gamma/min_child_weight pruning. Pass
an optional seed to any fit function for reproducible training runs.
gbm_fit(feat, target, n_rounds, lr, n_thresh, is_classifier, lambda, gamma, min_child_w, subsample, seed)
Fits a single-feature gradient-boosted stump ensemble using
XGBoost-style mechanics: Newton leaf steps (second-order hessian weighting),
exact gain formula with L2 regularization, gamma pruning, minimum child
weight, and Fisher-Yates row subsampling. Each round fits one depth-1 stump
(this is not a full multi-level tree, and there is no column subsampling).
Supports both binary classification (log-odds + sigmoid) and regression (MSE).
Parameters:
feat (array<float>): Array of feature values, one per training row
target (array<float>): Array of targets — 0.0/1.0 for classification, continuous for regression
n_rounds (int): Number of boosting rounds / stumps to fit
lr (float): Learning rate / shrinkage applied to each round's leaf contribution
n_thresh (int): Candidate split thresholds to scan per round
is_classifier (bool): True = binary classification, False = squared-error regression
lambda (float): L2 leaf regularization — Ridge-style shrinkage toward zero (XGBoost default: 1.0)
gamma (float): Minimum gain required to accept a split — prunes weak splits (XGBoost default: 0.0)
min_child_w (float): Minimum hessian sum per child node — prevents tiny noisy splits (XGBoost default: 1.0)
subsample (float): Fraction of rows randomly sampled per round via Fisher-Yates (default: 1.0 = all rows)
seed (int): Optional seed for the row-subsampling shuffle — pass a fixed value for reproducible fits across reloads (default: na = unseeded/random each time)
Returns: Fitted GBM object ready for gbm_predict()
gbm_predict(model, x)
Scores a single feature value against a fitted GBM ensemble.
Parameters:
model (GBM): A GBM object previously returned by gbm_fit()
x (float): Feature value to score (same feature definition used in training)
Returns: Predicted probability [0,1] if classifier, raw predicted value if regressor
gbm3_fit(feat1, feat2, feat3, target, n_rounds, lr, n_thresh, lambda, gamma, min_child_w, subsample, seed)
Fits a 3-feature gradient-boosted classifier using XGBoost-style
mechanics: Newton leaf steps, exact gain formula, L2 regularization, gamma
pruning, minimum child weight, and Fisher-Yates row subsampling. Selects the
best (feature, threshold) pair each round and boosts in log-odds space.
Each round fits a single depth-1 stump; there is no column subsampling.
Parameters:
feat1 (array<float>): Array of feature 1 values, one per training row
feat2 (array<float>): Array of feature 2 values, one per training row
feat3 (array<float>): Array of feature 3 values, one per training row
target (array<float>): Array of binary targets (0.0 or 1.0), one per training row
n_rounds (int): Number of boosting rounds
lr (float): Learning rate / shrinkage
n_thresh (int): Candidate thresholds scanned per feature per round
lambda (float): L2 leaf regularization (Ridge shrinkage, XGBoost default: 1.0)
gamma (float): Minimum gain to accept a split (XGBoost default: 0.0)
min_child_w (float): Minimum hessian sum per child node (XGBoost default: 1.0)
subsample (float): Row sampling fraction per round via Fisher-Yates (default: 1.0)
seed (int): Optional seed for the row-subsampling shuffle — pass a fixed value for reproducible fits across reloads (default: na = unseeded/random each time)
Returns: Fitted GBM3 object ready for gbm3_predict()
gbm3_predict(model, x1, x2, x3)
Scores 3 feature values against a fitted GBM3 classifier.
Parameters:
model (GBM3): GBM3 object from gbm3_fit()
x1 (float): Current value of feature 1
x2 (float): Current value of feature 2
x3 (float): Current value of feature 3
Returns: Predicted probability [0,1]
gbm4_fit(feat1, feat2, feat3, feat4, target, n_rounds, lr, n_thresh, is_classifier, lambda, gamma, min_child_w, subsample, seed)
Fits a 4-feature gradient-boosted ensemble with Newton steps, exact gain
formula, L2 regularization, gamma pruning, minimum child weight, Fisher-Yates
row subsampling, and gain-based feature importance tracking.
Supports both binary classification and regression. Each round fits a single
depth-1 stump; there is no column subsampling.
Parameters:
feat1 (array<float>): Array of feature 1 values, one per training row
feat2 (array<float>): Array of feature 2 values, one per training row
feat3 (array<float>): Array of feature 3 values, one per training row
feat4 (array<float>): Array of feature 4 values, one per training row
target (array<float>): Array of targets — 0.0/1.0 for classification, continuous for regression
n_rounds (int): Number of boosting rounds
lr (float): Learning rate / shrinkage
n_thresh (int): Candidate thresholds scanned per feature per round
is_classifier (bool): True = binary classification, False = regression
lambda (float): L2 leaf regularization (Ridge shrinkage, XGBoost default: 1.0)
gamma (float): Minimum gain to accept a split (XGBoost default: 0.0)
min_child_w (float): Minimum hessian sum per child node (XGBoost default: 1.0)
subsample (float): Row sampling fraction per round via Fisher-Yates (default: 1.0)
seed (int): Optional seed for the row-subsampling shuffle — pass a fixed value for reproducible fits across reloads (default: na = unseeded/random each time)
Returns: Fitted GBM4 object with importance scores, ready for gbm4_predict() / gbm4_importance_pct()
gbm4_predict(model, x1, x2, x3, x4)
Scores 4 feature values against a fitted GBM4 ensemble.
Parameters:
model (GBM4): GBM4 object from gbm4_fit()
x1 (float): Current value of feature 1
x2 (float): Current value of feature 2
x3 (float): Current value of feature 3
x4 (float): Current value of feature 4
Returns: Predicted probability [0,1] if classifier, raw predicted value if regressor
gbm4_importance_pct(model, feat_idx)
Returns normalized feature importance as % of total gain for one feature.
Importance = accumulated gain credited to this feature across all boosting rounds,
matching XGBoost's xgb.importance() Gain column definition.
Parameters:
model (GBM4): GBM4 object from gbm4_fit()
feat_idx (int): Feature index to query (0-3)
Returns: Percentage of total ensemble gain attributed to this feature (0.0–100.0)
GBM
Holds a fitted gradient-boosted stump ensemble (1 feature).
Fields:
thresh (array<float>): Split threshold for each round's stump
left_val (array<float>): Newton leaf value when feature < threshold
right_val (array<float>): Newton leaf value when feature >= threshold
base_score (series float): Log-odds of training mean (classifier) or mean (regressor)
lr (series float): Learning rate stored for inference
is_classifier (series bool): True = sigmoid probability output, False = raw regression output
GBM3
Holds a fitted 3-feature gradient-boosted stump ensemble (classification only).
Fields:
stump_feat (array<int>): Which feature index (0-2) each round's stump split on
thresh (array<float>): Split threshold for each round's stump
left_val (array<float>): Newton leaf value when feature < threshold
right_val (array<float>): Newton leaf value when feature >= threshold
base_score (series float): Log-odds of training mean
lr (series float): Learning rate stored for inference
GBM4
Holds a fitted 4-feature gradient-boosted ensemble with gain-based importance.
Fields:
stump_feat (array<int>): Which feature index (0-3) each round's stump split on
thresh (array<float>): Split threshold for each round's stump
left_val (array<float>): Newton leaf value when feature < threshold
right_val (array<float>): Newton leaf value when feature >= threshold
importance (array<float>): Accumulated gain per feature (indices 0-3), raw — normalize via gbm4_importance_pct()
base_score (series float): Log-odds (classifier) or mean (regressor)
lr (series float): Learning rate stored for inference
is_classifier (series bool): True = sigmoid probability output, False = raw regression output
Designed to support both classification and regression tasks, and building on our Random Forest approach to Pinescript, Arbor utilizes depth-1 stumps, meaning it performs one split per round without column subsampling.
Because TradingView automatically lists the exported types and function parameters, the following outlines the core mechanics and capabilities you unlock by importing Arbor.
Core Mechanics
Arbor brings advanced machine-learning concepts directly into your Pine Script workflows:Advanced Training: Utilizes Newton leaf steps (second-order hessian weighting) and the exact XGBoost gain formula.
Regularization & Pruning: Integrates L2 regularization (lambda), minimum gain pruning (gamma), and minimum child weight checks to manage model complexity and prevent overfitting.
Stochasticity: Implements Fisher-Yates row subsampling to provide genuine round-to-round stochasticity matching XGBoost's subsample behavior.
Reproducibility: You can pass an optional seed to any fit function to ensure reproducible training runs across reloads.
Model Tiers
The library supports models scaled across three specific feature tiers:
GBM (1 Feature): Built for rapid classification or regression implementations.
GBM3 (3 Features): Purpose-built specifically for classification tasks.
GBM4 (4 Features): Supports both classification and regression, and uniquely offers XGBoost-style, gain-based feature importance evaluation.
Library "Arbor_Gradient_Boosting_GainzAlgo"
Arbor — gradient boosting for Pine Script. From-scratch GBM v2
with XGBoost-style mechanics: Fisher-Yates row subsampling, Newton leaf steps
(second-order hessian weighting), exact XGBoost gain formula with L2
regularization (lambda), minimum gain pruning (gamma), and minimum child
weight. Trees are depth-1 stumps (one split per round) and there is no
column (feature) subsampling — this is an XGBoost-style boosting scheme,
not a full XGBoost reimplementation. Supports classification and regression
across three feature tiers:
- GBM (1 feature) : gbm_fit / gbm_predict
classification or regression via is_classifier
- GBM3 (3 features) : gbm3_fit / gbm3_predict
classification only
- GBM4 (4 features) : gbm4_fit / gbm4_predict / gbm4_importance_pct
classification or regression with XGBoost-style
gain-based feature importance
All variants use Newton leaf steps, exact gain formula, L2 regularization,
Fisher-Yates shuffle subsampling, and gamma/min_child_weight pruning. Pass
an optional seed to any fit function for reproducible training runs.
gbm_fit(feat, target, n_rounds, lr, n_thresh, is_classifier, lambda, gamma, min_child_w, subsample, seed)
Fits a single-feature gradient-boosted stump ensemble using
XGBoost-style mechanics: Newton leaf steps (second-order hessian weighting),
exact gain formula with L2 regularization, gamma pruning, minimum child
weight, and Fisher-Yates row subsampling. Each round fits one depth-1 stump
(this is not a full multi-level tree, and there is no column subsampling).
Supports both binary classification (log-odds + sigmoid) and regression (MSE).
Parameters:
feat (array<float>): Array of feature values, one per training row
target (array<float>): Array of targets — 0.0/1.0 for classification, continuous for regression
n_rounds (int): Number of boosting rounds / stumps to fit
lr (float): Learning rate / shrinkage applied to each round's leaf contribution
n_thresh (int): Candidate split thresholds to scan per round
is_classifier (bool): True = binary classification, False = squared-error regression
lambda (float): L2 leaf regularization — Ridge-style shrinkage toward zero (XGBoost default: 1.0)
gamma (float): Minimum gain required to accept a split — prunes weak splits (XGBoost default: 0.0)
min_child_w (float): Minimum hessian sum per child node — prevents tiny noisy splits (XGBoost default: 1.0)
subsample (float): Fraction of rows randomly sampled per round via Fisher-Yates (default: 1.0 = all rows)
seed (int): Optional seed for the row-subsampling shuffle — pass a fixed value for reproducible fits across reloads (default: na = unseeded/random each time)
Returns: Fitted GBM object ready for gbm_predict()
gbm_predict(model, x)
Scores a single feature value against a fitted GBM ensemble.
Parameters:
model (GBM): A GBM object previously returned by gbm_fit()
x (float): Feature value to score (same feature definition used in training)
Returns: Predicted probability [0,1] if classifier, raw predicted value if regressor
gbm3_fit(feat1, feat2, feat3, target, n_rounds, lr, n_thresh, lambda, gamma, min_child_w, subsample, seed)
Fits a 3-feature gradient-boosted classifier using XGBoost-style
mechanics: Newton leaf steps, exact gain formula, L2 regularization, gamma
pruning, minimum child weight, and Fisher-Yates row subsampling. Selects the
best (feature, threshold) pair each round and boosts in log-odds space.
Each round fits a single depth-1 stump; there is no column subsampling.
Parameters:
feat1 (array<float>): Array of feature 1 values, one per training row
feat2 (array<float>): Array of feature 2 values, one per training row
feat3 (array<float>): Array of feature 3 values, one per training row
target (array<float>): Array of binary targets (0.0 or 1.0), one per training row
n_rounds (int): Number of boosting rounds
lr (float): Learning rate / shrinkage
n_thresh (int): Candidate thresholds scanned per feature per round
lambda (float): L2 leaf regularization (Ridge shrinkage, XGBoost default: 1.0)
gamma (float): Minimum gain to accept a split (XGBoost default: 0.0)
min_child_w (float): Minimum hessian sum per child node (XGBoost default: 1.0)
subsample (float): Row sampling fraction per round via Fisher-Yates (default: 1.0)
seed (int): Optional seed for the row-subsampling shuffle — pass a fixed value for reproducible fits across reloads (default: na = unseeded/random each time)
Returns: Fitted GBM3 object ready for gbm3_predict()
gbm3_predict(model, x1, x2, x3)
Scores 3 feature values against a fitted GBM3 classifier.
Parameters:
model (GBM3): GBM3 object from gbm3_fit()
x1 (float): Current value of feature 1
x2 (float): Current value of feature 2
x3 (float): Current value of feature 3
Returns: Predicted probability [0,1]
gbm4_fit(feat1, feat2, feat3, feat4, target, n_rounds, lr, n_thresh, is_classifier, lambda, gamma, min_child_w, subsample, seed)
Fits a 4-feature gradient-boosted ensemble with Newton steps, exact gain
formula, L2 regularization, gamma pruning, minimum child weight, Fisher-Yates
row subsampling, and gain-based feature importance tracking.
Supports both binary classification and regression. Each round fits a single
depth-1 stump; there is no column subsampling.
Parameters:
feat1 (array<float>): Array of feature 1 values, one per training row
feat2 (array<float>): Array of feature 2 values, one per training row
feat3 (array<float>): Array of feature 3 values, one per training row
feat4 (array<float>): Array of feature 4 values, one per training row
target (array<float>): Array of targets — 0.0/1.0 for classification, continuous for regression
n_rounds (int): Number of boosting rounds
lr (float): Learning rate / shrinkage
n_thresh (int): Candidate thresholds scanned per feature per round
is_classifier (bool): True = binary classification, False = regression
lambda (float): L2 leaf regularization (Ridge shrinkage, XGBoost default: 1.0)
gamma (float): Minimum gain to accept a split (XGBoost default: 0.0)
min_child_w (float): Minimum hessian sum per child node (XGBoost default: 1.0)
subsample (float): Row sampling fraction per round via Fisher-Yates (default: 1.0)
seed (int): Optional seed for the row-subsampling shuffle — pass a fixed value for reproducible fits across reloads (default: na = unseeded/random each time)
Returns: Fitted GBM4 object with importance scores, ready for gbm4_predict() / gbm4_importance_pct()
gbm4_predict(model, x1, x2, x3, x4)
Scores 4 feature values against a fitted GBM4 ensemble.
Parameters:
model (GBM4): GBM4 object from gbm4_fit()
x1 (float): Current value of feature 1
x2 (float): Current value of feature 2
x3 (float): Current value of feature 3
x4 (float): Current value of feature 4
Returns: Predicted probability [0,1] if classifier, raw predicted value if regressor
gbm4_importance_pct(model, feat_idx)
Returns normalized feature importance as % of total gain for one feature.
Importance = accumulated gain credited to this feature across all boosting rounds,
matching XGBoost's xgb.importance() Gain column definition.
Parameters:
model (GBM4): GBM4 object from gbm4_fit()
feat_idx (int): Feature index to query (0-3)
Returns: Percentage of total ensemble gain attributed to this feature (0.0–100.0)
GBM
Holds a fitted gradient-boosted stump ensemble (1 feature).
Fields:
thresh (array<float>): Split threshold for each round's stump
left_val (array<float>): Newton leaf value when feature < threshold
right_val (array<float>): Newton leaf value when feature >= threshold
base_score (series float): Log-odds of training mean (classifier) or mean (regressor)
lr (series float): Learning rate stored for inference
is_classifier (series bool): True = sigmoid probability output, False = raw regression output
GBM3
Holds a fitted 3-feature gradient-boosted stump ensemble (classification only).
Fields:
stump_feat (array<int>): Which feature index (0-2) each round's stump split on
thresh (array<float>): Split threshold for each round's stump
left_val (array<float>): Newton leaf value when feature < threshold
right_val (array<float>): Newton leaf value when feature >= threshold
base_score (series float): Log-odds of training mean
lr (series float): Learning rate stored for inference
GBM4
Holds a fitted 4-feature gradient-boosted ensemble with gain-based importance.
Fields:
stump_feat (array<int>): Which feature index (0-3) each round's stump split on
thresh (array<float>): Split threshold for each round's stump
left_val (array<float>): Newton leaf value when feature < threshold
right_val (array<float>): Newton leaf value when feature >= threshold
importance (array<float>): Accumulated gain per feature (indices 0-3), raw — normalize via gbm4_importance_pct()
base_score (series float): Log-odds (classifier) or mean (regressor)
lr (series float): Learning rate stored for inference
is_classifier (series bool): True = sigmoid probability output, False = raw regression output
ملاحظات الأخبار
Improved the chart visuals for a better user experienceمكتبة باين
كمثال للقيم التي تتبناها TradingView، نشر المؤلف شيفرة باين كمكتبة مفتوحة المصدر بحيث يمكن لمبرمجي باين الآخرين من مجتمعنا استخدامه بحرية. تحياتنا للمؤلف! يمكنك استخدام هذه المكتبة بشكل خاص أو في منشورات أخرى مفتوحة المصدر، ولكن إعادة استخدام هذا الرمز في المنشورات تخضع لقواعد الموقع.
Get GainzAlgo only at gainzalgo.com
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
مكتبة باين
كمثال للقيم التي تتبناها TradingView، نشر المؤلف شيفرة باين كمكتبة مفتوحة المصدر بحيث يمكن لمبرمجي باين الآخرين من مجتمعنا استخدامه بحرية. تحياتنا للمؤلف! يمكنك استخدام هذه المكتبة بشكل خاص أو في منشورات أخرى مفتوحة المصدر، ولكن إعادة استخدام هذا الرمز في المنشورات تخضع لقواعد الموقع.
Get GainzAlgo only at gainzalgo.com
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.